@@ -576,6 +576,132 @@ fileprivate struct BuildOperationTests: CoreBasedTests {
576576 }
577577 }
578578
579+ @Test ( . requireSDKs( . host) , . skipHostOS( . macOS) , . skipHostOS( . windows, " cannot find testing library " ) )
580+ func unitTestWithGeneratedEntryPoint_testabilityDisabled( ) async throws {
581+ try await withTemporaryDirectory ( removeTreeOnDeinit: false ) { ( tmpDir: Path ) in
582+ let testProject = try await TestProject (
583+ " TestProject " ,
584+ sourceRoot: tmpDir,
585+ groupTree: TestGroup (
586+ " SomeFiles " ,
587+ children: [
588+ TestFile ( " library.swift " ) ,
589+ TestFile ( " test.swift " ) ,
590+ ] ) ,
591+ buildConfigurations: [
592+ TestBuildConfiguration ( " Debug " , buildSettings: [
593+ " ARCHS " : " $(ARCHS_STANDARD) " ,
594+ " CODE_SIGNING_ALLOWED " : " NO " ,
595+ " PRODUCT_NAME " : " $(TARGET_NAME) " ,
596+ " SDKROOT " : " $(HOST_PLATFORM) " ,
597+ " SUPPORTED_PLATFORMS " : " $(HOST_PLATFORM) " ,
598+ " SWIFT_VERSION " : swiftVersion,
599+ " INDEX_DATA_STORE_DIR " : " \( tmpDir. join ( " index " ) . str) " ,
600+ " LINKER_DRIVER " : " swiftc " ,
601+ " ENABLE_TESTABILITY " : " NO " ,
602+ ] )
603+ ] ,
604+ targets: [
605+ TestStandardTarget (
606+ " UnitTestRunner " ,
607+ type: . swiftpmTestRunner,
608+ buildConfigurations: [
609+ TestBuildConfiguration ( " Debug " , buildSettings: [
610+ " LD_RUNPATH_SEARCH_PATHS " : " $(RPATH_ORIGIN) " ,
611+ ] ) ,
612+ ] ,
613+ buildPhases: [
614+ TestSourcesBuildPhase ( ) ,
615+ TestFrameworksBuildPhase ( [
616+ " MyTests.so "
617+ ] )
618+ ] ,
619+ dependencies: [ " MyTests " ]
620+ ) ,
621+ TestStandardTarget (
622+ " MyTests " ,
623+ type: . unitTest,
624+ buildConfigurations: [
625+ TestBuildConfiguration ( " Debug " , buildSettings: [
626+ " LD_RUNPATH_SEARCH_PATHS " : " $(RPATH_ORIGIN) " ,
627+ " LD_DYLIB_INSTALL_NAME " : " MyTests.so "
628+ ] )
629+ ] ,
630+ buildPhases: [
631+ TestSourcesBuildPhase ( [ " test.swift " ] ) ,
632+ TestFrameworksBuildPhase ( [
633+ TestBuildFile ( . target( " library " ) ) ,
634+ ] )
635+ ] , dependencies: [
636+ " library "
637+ ] ,
638+ productReferenceName: " MyTests.so "
639+ ) ,
640+ TestStandardTarget (
641+ " library " ,
642+ type: . dynamicLibrary,
643+ buildConfigurations: [
644+ TestBuildConfiguration ( " Debug " , buildSettings: [
645+ " LD_RUNPATH_SEARCH_PATHS " : " $(RPATH_ORIGIN) " ,
646+ " LD_DYLIB_INSTALL_NAME " : " liblibrary.so " ,
647+
648+ // FIXME: Find a way to make these default
649+ " EXECUTABLE_PREFIX " : " lib " ,
650+ " EXECUTABLE_PREFIX[sdk=windows*] " : " " ,
651+ ] )
652+ ] ,
653+ buildPhases: [
654+ TestSourcesBuildPhase ( [ " library.swift " ] ) ,
655+ ] ,
656+ )
657+ ] )
658+ let core = try await getCore ( )
659+ let tester = try await BuildOperationTester ( core, testProject, simulated: false )
660+ try localFS. createDirectory ( tmpDir. join ( " index " ) )
661+ let projectDir = tester. workspace. projects [ 0 ] . sourceRoot
662+
663+ try await tester. fs. writeFileContents ( projectDir. join ( " library.swift " ) ) { stream in
664+ stream <<< " public func foo() -> Int { 42 } \n "
665+ }
666+
667+ try await tester. fs. writeFileContents ( projectDir. join ( " test.swift " ) ) { stream in
668+ stream <<< """
669+ import Testing
670+ import XCTest
671+ import library
672+ @Suite struct MySuite {
673+ @Test func myTest() {
674+ #expect(foo() == 42)
675+ }
676+ }
677+
678+ final class MYXCTests: XCTestCase {
679+ func testFoo() {
680+ XCTAssertTrue(true)
681+ }
682+ }
683+ """
684+ }
685+
686+ let destination : RunDestinationInfo = . host
687+ try await tester. checkBuild ( runDestination: destination, persistent: true ) { results in
688+ results. checkWarning ( " Skipping XCTest discovery for 'MyTests' because it was not built for testing " )
689+ results. checkNoErrors ( )
690+
691+ let environment = destination. hostRuntimeEnvironment ( core)
692+
693+ do {
694+ let executionResult = try await Process . getOutput ( url: URL ( fileURLWithPath: projectDir. join ( " build " ) . join ( " Debug \( destination. builtProductsDirSuffix) " ) . join ( core. hostOperatingSystem. imageFormat. executableName ( basename: " UnitTestRunner " ) ) . str) , arguments: [ ] , environment: environment)
695+ #expect( String ( decoding: executionResult. stdout, as: UTF8 . self) . contains ( " Executed 0 tests " ) )
696+ }
697+ do {
698+ let executionResult = try await Process . getOutput ( url: URL ( fileURLWithPath: projectDir. join ( " build " ) . join ( " Debug \( destination. builtProductsDirSuffix) " ) . join ( core. hostOperatingSystem. imageFormat. executableName ( basename: " UnitTestRunner " ) ) . str) , arguments: [ " --testing-library " , " swift-testing " ] , environment: environment)
699+ #expect( String ( decoding: executionResult. stderr, as: UTF8 . self) . contains ( " Test run with 1 test " ) )
700+ }
701+ }
702+ }
703+ }
704+
579705 /// Check that environment variables are propagated from the user environment correctly.
580706 @Test ( . requireSDKs( . host) , . skipHostOS( . windows) , . requireSystemPackages( apt: " yacc " , yum: " byacc " ) )
581707 func userEnvironment( ) async throws {
0 commit comments