@@ -576,6 +576,133 @@ 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+ " SWIFT_ENABLE_TESTABILITY " : " NO " ,
603+ ] )
604+ ] ,
605+ targets: [
606+ TestStandardTarget (
607+ " UnitTestRunner " ,
608+ type: . swiftpmTestRunner,
609+ buildConfigurations: [
610+ TestBuildConfiguration ( " Debug " , buildSettings: [
611+ " LD_RUNPATH_SEARCH_PATHS " : " $(RPATH_ORIGIN) " ,
612+ ] ) ,
613+ ] ,
614+ buildPhases: [
615+ TestSourcesBuildPhase ( ) ,
616+ TestFrameworksBuildPhase ( [
617+ " MyTests.so "
618+ ] )
619+ ] ,
620+ dependencies: [ " MyTests " ]
621+ ) ,
622+ TestStandardTarget (
623+ " MyTests " ,
624+ type: . unitTest,
625+ buildConfigurations: [
626+ TestBuildConfiguration ( " Debug " , buildSettings: [
627+ " LD_RUNPATH_SEARCH_PATHS " : " $(RPATH_ORIGIN) " ,
628+ " LD_DYLIB_INSTALL_NAME " : " MyTests.so "
629+ ] )
630+ ] ,
631+ buildPhases: [
632+ TestSourcesBuildPhase ( [ " test.swift " ] ) ,
633+ TestFrameworksBuildPhase ( [
634+ TestBuildFile ( . target( " library " ) ) ,
635+ ] )
636+ ] , dependencies: [
637+ " library "
638+ ] ,
639+ productReferenceName: " MyTests.so "
640+ ) ,
641+ TestStandardTarget (
642+ " library " ,
643+ type: . dynamicLibrary,
644+ buildConfigurations: [
645+ TestBuildConfiguration ( " Debug " , buildSettings: [
646+ " LD_RUNPATH_SEARCH_PATHS " : " $(RPATH_ORIGIN) " ,
647+ " LD_DYLIB_INSTALL_NAME " : " liblibrary.so " ,
648+
649+ // FIXME: Find a way to make these default
650+ " EXECUTABLE_PREFIX " : " lib " ,
651+ " EXECUTABLE_PREFIX[sdk=windows*] " : " " ,
652+ ] )
653+ ] ,
654+ buildPhases: [
655+ TestSourcesBuildPhase ( [ " library.swift " ] ) ,
656+ ] ,
657+ )
658+ ] )
659+ let core = try await getCore ( )
660+ let tester = try await BuildOperationTester ( core, testProject, simulated: false )
661+ try localFS. createDirectory ( tmpDir. join ( " index " ) )
662+ let projectDir = tester. workspace. projects [ 0 ] . sourceRoot
663+
664+ try await tester. fs. writeFileContents ( projectDir. join ( " library.swift " ) ) { stream in
665+ stream <<< " public func foo() -> Int { 42 } \n "
666+ }
667+
668+ try await tester. fs. writeFileContents ( projectDir. join ( " test.swift " ) ) { stream in
669+ stream <<< """
670+ import Testing
671+ import XCTest
672+ import library
673+ @Suite struct MySuite {
674+ @Test func myTest() {
675+ #expect(foo() == 42)
676+ }
677+ }
678+
679+ final class MYXCTests: XCTestCase {
680+ func testFoo() {
681+ XCTAssertTrue(true)
682+ }
683+ }
684+ """
685+ }
686+
687+ let destination : RunDestinationInfo = . host
688+ try await tester. checkBuild ( runDestination: destination, persistent: true ) { results in
689+ results. checkWarning ( . prefix( " Skipping XCTest discovery for 'MyTests' because it was not built for testing " ) )
690+ results. checkNoErrors ( )
691+
692+ let environment = destination. hostRuntimeEnvironment ( core)
693+
694+ do {
695+ 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)
696+ #expect( String ( decoding: executionResult. stdout, as: UTF8 . self) . contains ( " Executed 0 tests " ) )
697+ }
698+ do {
699+ 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)
700+ #expect( String ( decoding: executionResult. stderr, as: UTF8 . self) . contains ( " Test run with 1 test " ) )
701+ }
702+ }
703+ }
704+ }
705+
579706 /// Check that environment variables are propagated from the user environment correctly.
580707 @Test ( . requireSDKs( . host) , . skipHostOS( . windows) , . requireSystemPackages( apt: " yacc " , yum: " byacc " ) )
581708 func userEnvironment( ) async throws {
0 commit comments