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

Broken test runner generation for XCTestCase classes nested in other types #7411

Open
1 task done
dabrahams opened this issue Mar 19, 2024 · 0 comments
Open
1 task done
Labels
bug swift test Changes impacting `swift test` tool

Comments

@dabrahams
Copy link
Contributor

Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?

  • Confirmed reproduction steps with SwiftPM CLI.

Description

A test file containing the following will cause the test to fail to compile on Linux or Windows. These work on macOS, and my test scraper can successfully run them on Linux or Windows:

struct StructsAreNotTestCases {
  func testStructMethodsAreNotTests() {
    XCTFail("This shouldn't run")
  }

  class NestedStructClassesCanBeTestCases: XCTestCase {
    func testNestedClassMethodsCanBeTests() {}
  }
}

enum EnumsAreNotTestCases {
  func testEnumMethodsAreNotTests() {
    XCTFail("This shouldn't run")
  }

  class NestedEnumClassesCanBeTestCases: XCTestCase {
    func testNestedClassMethodsCanBeTests() {}
  }
}

Expected behavior

Both of the XXXCanBeTests functions run as part of testing and tests pass.

Actual behavior

[281/286] Emitting module SwiftCMakeXCTestingPackageDiscoveredTests
/home/runner/work/GenerateSwiftXCTestMain/GenerateSwiftXCTestMain/.build/x86_64-unknown-linux-gnu/debug/SwiftCMakeXCTestingPackageDiscoveredTests.derived/Tests.swift:4:23: error: cannot find type 'NestedEnumClassesCanBeTestCases' in scope
fileprivate extension NestedEnumClassesCanBeTestCases {
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/GenerateSwiftXCTestMain/GenerateSwiftXCTestMain/.build/x86_64-unknown-linux-gnu/debug/SwiftCMakeXCTestingPackageDiscoveredTests.derived/Tests.swift:11:23: error: cannot find type 'NestedStructClassesCanBeTestCases' in scope
fileprivate extension NestedStructClassesCanBeTestCases {
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[282/286] Compiling SwiftCMakeXCTestingPackageDiscoveredTests Tests.swift
/home/runner/work/GenerateSwiftXCTestMain/GenerateSwiftXCTestMain/.build/x86_64-unknown-linux-gnu/debug/SwiftCMakeXCTestingPackageDiscoveredTests.derived/Tests.swift:4:23: error: cannot find type 'NestedEnumClassesCanBeTestCases' in scope
fileprivate extension NestedEnumClassesCanBeTestCases {
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/GenerateSwiftXCTestMain/GenerateSwiftXCTestMain/.build/x86_64-unknown-linux-gnu/debug/SwiftCMakeXCTestingPackageDiscoveredTests.derived/Tests.swift:11:23: error: cannot find type 'NestedStructClassesCanBeTestCases' in scope
fileprivate extension NestedStructClassesCanBeTestCases {
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/GenerateSwiftXCTestMain/GenerateSwiftXCTestMain/.build/x86_64-unknown-linux-gnu/debug/SwiftCMakeXCTestingPackageDiscoveredTests.derived/Tests.swift:28:18: error: cannot find 'NestedEnumClassesCanBeTestCases' in scope
        testCase(NestedEnumClassesCanBeTestCases.__allTests__NestedEnumClassesCanBeTestCases),
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/GenerateSwiftXCTestMain/GenerateSwiftXCTestMain/.build/x86_64-unknown-linux-gnu/debug/SwiftCMakeXCTestingPackageDiscoveredTests.derived/Tests.swift:29:18: error: cannot find 'NestedStructClassesCanBeTestCases' in scope
        testCase(NestedStructClassesCanBeTestCases.__allTests__NestedStructClassesCanBeTestCases),
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/GenerateSwiftXCTestMain/GenerateSwiftXCTestMain/.build/x86_64-unknown-linux-gnu/debug/SwiftCMakeXCTestingPackageDiscoveredTests.derived/Tests.swift:7:46: error: cannot find 'testNestedClassMethodsCanBeTests' in scope
        ("testNestedClassMethodsCanBeTests", testNestedClassMethodsCanBeTests),
                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/GenerateSwiftXCTestMain/GenerateSwiftXCTestMain/.build/x86_64-unknown-linux-gnu/debug/SwiftCMakeXCTestingPackageDiscoveredTests.derived/Tests.swift:14:46: error: cannot find 'testNestedClassMethodsCanBeTests' in scope
        ("testNestedClassMethodsCanBeTests", testNestedClassMethodsCanBeTests),
                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: fatalError
error: fatalError
Error: Process completed with exit code 1.

Steps to reproduce

Put the snippet in a test and swift build --build-tests on Linux or Windows.

Swift Package Manager version/commit hash

5.9.0

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

swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: arm64-apple-macosx14.0
Darwin DaveA-MBP14-5.localdomain 23.4.0 Darwin Kernel Version 23.4.0: Wed Feb 21 21:44:43 PST 2024; root:xnu-10063.101.15~2/RELEASE_ARM64_T6000 arm64

@dabrahams dabrahams added the bug label Mar 19, 2024
dabrahams added a commit to hylo-lang/GenerateSwiftXCTestMain that referenced this issue Mar 19, 2024
dabrahams added a commit to hylo-lang/GenerateSwiftXCTestMain that referenced this issue Mar 19, 2024
dabrahams added a commit to hylo-lang/GenerateSwiftXCTestMain that referenced this issue Mar 19, 2024
@grynspan grynspan added the swift test Changes impacting `swift test` tool label May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug swift test Changes impacting `swift test` tool
Projects
None yet
Development

No branches or pull requests

2 participants