Skip to content

Commit eb62d70

Browse files
committed
[PackageLoading] Fix linux XCTest module name
This was colliding with main package module name if there is only one module. It got broken during the transition from `TestSuite` to `Tests` suffix.
1 parent be00cb4 commit eb62d70

File tree

3 files changed

+63
-6
lines changed

3 files changed

+63
-6
lines changed

Sources/PackageLoading/PackageBuilder.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,10 @@ public struct PackageBuilder {
482482
}
483483
#endif
484484
if !testModules.isEmpty {
485-
//TODO and then we should prefix all modules with their package probably
486-
//Suffix 'Tests' to test product so the module name of linux executable don't collide with
487-
//main package, if present.
488-
let product = Product(name: manifest.name + "Tests", type: .Test, modules: testModules)
485+
// TODO and then we should prefix all modules with their package probably.
486+
// Add suffix 'PackageTests' to test product so the module name of linux executable don't collide with
487+
// main package, if present.
488+
let product = Product(name: manifest.name + "PackageTests", type: .Test, modules: testModules)
489489
products.append(product)
490490
}
491491

Tests/FunctionalTests/SwiftPMXCTestHelperTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class SwiftPMXCTestHelperTests: XCTestCase {
2424
// Run swift-test on package.
2525
XCTAssertSwiftTest(prefix)
2626
// Expected output dictionary.
27-
let testCases = ["name": "All Tests", "tests": [["name" : "SwiftPMXCTestHelperTests.xctest",
27+
let testCases = ["name": "All Tests", "tests": [["name" : "SwiftPMXCTestHelperPackageTests.xctest",
2828
"tests": [
2929
[
3030
"name": "ObjCTests",
@@ -37,7 +37,7 @@ class SwiftPMXCTestHelperTests: XCTestCase {
3737
] as Array<Dictionary<String, Any>>]] as Array<Dictionary<String, Any>>
3838
] as Dictionary<String, Any> as NSDictionary
3939
// Run the XCTest helper tool and check result.
40-
XCTAssertXCTestHelper(prefix.appending(components: ".build", "debug", "SwiftPMXCTestHelperTests.xctest"), testCases: testCases)
40+
XCTAssertXCTestHelper(prefix.appending(components: ".build", "debug", "SwiftPMXCTestHelperPackageTests.xctest"), testCases: testCases)
4141
}
4242
#endif
4343
}

Tests/PackageLoadingTests/ConventionTests.swift

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,62 @@ class ConventionTests: XCTestCase {
603603
}
604604
}
605605

606+
func testTestsProduct() throws {
607+
// Make sure product name and test module name are different in single module package.
608+
var fs = InMemoryFileSystem()
609+
try fs.createEmptyFiles("/Sources/Foo.swift",
610+
"/Tests/FooTests/Bar.swift")
611+
612+
PackageBuilderTester("Foo", in: fs, products: products) { result in
613+
result.checkModule("Foo") { moduleResult in
614+
moduleResult.check(c99name: "Foo", type: .library, isTest: false)
615+
moduleResult.checkSources(root: "/Sources", paths: "Foo.swift")
616+
}
617+
618+
result.checkModule("FooTests") { moduleResult in
619+
moduleResult.check(c99name: "FooTests", type: .library, isTest: true)
620+
moduleResult.checkSources(root: "/Tests/FooTests", paths: "Bar.swift")
621+
}
622+
623+
result.checkProduct("FooPackageTests") { productResult in
624+
productResult.check(type: .Test, modules: ["FooTests"])
625+
}
626+
}
627+
628+
// Multi module tests package.
629+
fs = InMemoryFileSystem()
630+
try fs.createEmptyFiles("/Sources/Foo/Foo.swift",
631+
"/Sources/Bar/Bar.swift",
632+
"/Tests/FooTests/Foo.swift",
633+
"/Tests/BarTests/Bar.swift")
634+
635+
PackageBuilderTester("Foo", in: fs, products: products) { result in
636+
result.checkModule("Foo") { moduleResult in
637+
moduleResult.check(c99name: "Foo", type: .library, isTest: false)
638+
moduleResult.checkSources(root: "/Sources/Foo", paths: "Foo.swift")
639+
}
640+
641+
result.checkModule("Bar") { moduleResult in
642+
moduleResult.check(c99name: "Bar", type: .library, isTest: false)
643+
moduleResult.checkSources(root: "/Sources/Bar", paths: "Bar.swift")
644+
}
645+
646+
result.checkModule("FooTests") { moduleResult in
647+
moduleResult.check(c99name: "FooTests", type: .library, isTest: true)
648+
moduleResult.checkSources(root: "/Tests/FooTests", paths: "Foo.swift")
649+
}
650+
651+
result.checkModule("BarTests") { moduleResult in
652+
moduleResult.check(c99name: "BarTests", type: .library, isTest: true)
653+
moduleResult.checkSources(root: "/Tests/BarTests", paths: "Bar.swift")
654+
}
655+
656+
result.checkProduct("FooPackageTests") { productResult in
657+
productResult.check(type: .Test, modules: ["BarTests", "FooTests"])
658+
}
659+
}
660+
}
661+
606662
func testBadProducts() throws {
607663
var fs = InMemoryFileSystem()
608664
try fs.createEmptyFiles("/Foo.swift")
@@ -789,6 +845,7 @@ class ConventionTests: XCTestCase {
789845
("testManifestTargetDeclErrors", testManifestTargetDeclErrors),
790846
("testProducts", testProducts),
791847
("testBadProducts", testBadProducts),
848+
("testTestsProduct", testTestsProduct),
792849
]
793850
}
794851

0 commit comments

Comments
 (0)