Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot mark suite as @available #608

Open
CamJN opened this issue Aug 11, 2024 · 3 comments
Open

Cannot mark suite as @available #608

CamJN opened this issue Aug 11, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@CamJN
Copy link

CamJN commented Aug 11, 2024

Description

It would make sense to be able to mark a whole suite as @available(macOS 11, *) or w/e instead of making us mark each test. Also the error when you try to do this makes no sense.

Expected behavior

Successful compilation when marking whole suite as available on specific platforms.

Actual behavior

/Users/camdennarzt/Developer/getargv.swift/Tests/SwiftGetargvTests/Test.swift:6:1: error: Attribute 'Suite' cannot be applied to this structure because it has been marked '@available(macOS 11.0, *)'
 4 | @testable import SwiftGetargv
 5 | 
 6 | @available(macOS 11.0, *)
   | `- error: Attribute 'Suite' cannot be applied to this structure because it has been marked '@available(macOS 11.0, *)'
 7 | @Suite()
 8 | struct SwiftGetargvTests {

/Users/camdennarzt/Developer/getargv.swift/Tests/SwiftGetargvTests/Test.swift:10:5: error: Attribute 'Test' cannot be applied to this function because it has been marked '@available(macOS 11.0, *)'
 8 | struct SwiftGetargvTests {
 9 | 
10 |     @Test("test getArgvOfPid NUL replacement", arguments: zip([true, false], [" ", "\0"]))
   |     `- error: Attribute 'Test' cannot be applied to this function because it has been marked '@available(macOS 11.0, *)'
11 |         func GetArgvOfPidNuls(nuls: Bool, separator: String) throws {
12 |             let expectedOutput = CommandLine.arguments.joined(separator: separator).utf8CString

/Users/camdennarzt/Developer/getargv.swift/Tests/SwiftGetargvTests/Test.swift:19:5: error: Attribute 'Test' cannot be applied to this function because it has been marked '@available(macOS 11.0, *)'
17 |         }
18 | 
19 |     @Test("test getArgvAndArgcOfPid")
   |     `- error: Attribute 'Test' cannot be applied to this function because it has been marked '@available(macOS 11.0, *)'
20 |         func testGetArgvAndArgcOfPid() throws {
21 |             let expectedOutput = CommandLine.arguments

error: fatalError

This is especially bad because the error: error: Attribute 'Test' cannot be applied to this function because it has been marked '@available(macOS 11.0, *)' is not true, if you apply the @Test attribute to a function which has been marked with @available(macOS 11.0, *) that works, it's just that inheriting the available attr from the suite breaks things.

Steps to reproduce

import Foundation
import Testing

@testable import SwiftGetargv

@available(macOS 11.0, *)
@Suite()
struct SwiftGetargvTests {

    @Test("test getArgvOfPid NUL replacement", arguments: zip([true, false], [" ", "\0"]))
        func GetArgvOfPidNuls(nuls: Bool, separator: String) throws {
            let expectedOutput = CommandLine.arguments.joined(separator: separator).utf8CString
            let actualOutput = try #require(try getArgvOfPid(pid: getpid(), nuls: nuls).get())
            #expect(actualOutput.array == Array(expectedOutput))
        }

    @Test("test getArgvAndArgcOfPid")
        func testGetArgvAndArgcOfPid() throws {
            let expectedOutput = CommandLine.arguments
            let actualOutput = try #require(try getArgvAndArgcOfPid(pid: getpid(), encoding: String.Encoding.nonLossyASCII).get())
            #expect(actualOutput == expectedOutput)
        }
}

swift-testing version/commit hash

0.11.0

Swift & OS version (output of swift --version ; uname -a)

<unknown>:0: warning: using (deprecated) legacy driver, Swift installation does not contain swift-driver at: '/Library/Developer/CommandLineTools/usr/bin/swift-driver-new'
Apple Swift version 6.0 (swiftlang-6.0.0.7.6 clang-1600.0.24.1)
Target: x86_64-apple-darwin24.0.0
Darwin Camdens-Mac 24.0.0 Darwin Kernel Version 24.0.0: Thu Jun 20 20:36:19 PDT 2024; root:xnu-11215.0.115.501.3~1/RELEASE_X86_64 x86_64
@CamJN CamJN added the bug Something isn't working label Aug 11, 2024
@grynspan grynspan added enhancement New feature or request swift-6.1 and removed bug Something isn't working labels Aug 11, 2024
@grynspan
Copy link
Contributor

This constraint exists because, in order to correctly compute availability on a suite, we need to be able to see the availability of all its containing types (or if a test is declared in an extension, of the original type declaration.)

As of swift-syntax-600, it's possible for us to see the containing type declarations of everything that isn't an extension, so we may be able to resolve this in the common case. Extensions continue to pose a problem because tests declared in them could be subject to availability constraints that are not bound to the visible AST, but that's an existing problem.

@grynspan
Copy link
Contributor

Ah, right, now I remember. It's not just about syntax, because we need some way to determine the fully-qualified name of the suite type and that information isn't available if the suite type is unavailable.

@grynspan
Copy link
Contributor

Tracked internally as rdar://111430835.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants