Skip to content

Commit 8ad47ad

Browse files
committed
2 parents ec10a7e + eb62d70 commit 8ad47ad

File tree

3 files changed

+65
-8
lines changed

3 files changed

+65
-8
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: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,63 @@ class ConventionTests: XCTestCase {
598598
}
599599

600600
result.checkProduct("libpm") { productResult in
601-
productResult.check(type: .Library(.Dynamic), modules: ["Foo", "Bar"])
601+
productResult.check(type: .Library(.Dynamic), modules: ["Bar", "Foo"])
602+
}
603+
}
604+
}
605+
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"])
602658
}
603659
}
604660
}
@@ -789,6 +845,7 @@ class ConventionTests: XCTestCase {
789845
("testManifestTargetDeclErrors", testManifestTargetDeclErrors),
790846
("testProducts", testProducts),
791847
("testBadProducts", testBadProducts),
848+
("testTestsProduct", testTestsProduct),
792849
]
793850
}
794851

@@ -939,7 +996,7 @@ final class PackageBuilderTester {
939996

940997
func check(type: PackageDescription.ProductType, modules: [String], file: StaticString = #file, line: UInt = #line) {
941998
XCTAssertEqual(product.type, type, file: file, line: line)
942-
XCTAssertEqual(product.modules.map{$0.name}, modules, file: file, line: line)
999+
XCTAssertEqual(product.modules.map{$0.name}.sorted(), modules, file: file, line: line)
9431000
}
9441001
}
9451002

0 commit comments

Comments
 (0)