Skip to content

Commit e702428

Browse files
committed
Merge `unique-test-runner-names'
2 parents 0d03048 + 065c6eb commit e702428

File tree

6 files changed

+40
-22
lines changed

6 files changed

+40
-22
lines changed

Sources/Build/misc.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ extension CModule {
3636

3737
extension Product {
3838
var Info: (_: Void, plist: String) {
39-
let bundleExecutable = "Package"
39+
precondition(isTest)
40+
41+
let bundleExecutable = name
4042
let bundleID = "org.swift.pm.\(name)"
4143
let bundleName = name
4244

Sources/PackageType/Product.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ public class Product {
3434
return "lib\(name).so"
3535
#endif
3636
case .Test:
37+
let base = "\(name).xctest"
3738
#if os(OSX)
38-
return "\(name).xctest/Contents/MacOS/\(name)"
39+
return "\(base)/Contents/MacOS/\(name)"
3940
#else
40-
return "test-\(name)"
41+
return base
4142
#endif
4243
}
4344
}

Sources/Transmute/Package+products.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ extension Package {
2828

2929
if !testModules.isEmpty {
3030
let modules: [SwiftModule] = testModules.map{$0} // or linux compiler crash (2016-02-03)
31-
//TODO name should be package name
3231
//TODO and then we should prefix all modules with their package probably
33-
let product = Product(name: "Package", type: .Test, modules: modules)
32+
let product = Product(name: self.name, type: .Test, modules: modules)
3433
products.append(product)
3534
}
3635

Sources/swift-test/Error.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extension Error: CustomStringConvertible {
1919
case .DebugYAMLNotFound:
2020
return "build the package using `swift build` before running tests"
2121
case .TestsExecutableNotFound:
22-
return "no tests found to execute, create a test-module in `Tests` directory"
22+
return "no tests found to execute, create a module in your `Tests' directory"
2323
}
2424
}
2525
}

Sources/swift-test/main.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,31 @@ do {
2121
usage()
2222
case .Run(let xctestArg):
2323
let dir = try directories()
24+
25+
func determineTestPath() -> String {
26+
27+
//FIXME better, ideally without parsing manifest since
28+
// that makes us depend on the whole Manifest system
29+
30+
let packageName = dir.root.basename //FIXME probably not true
31+
let maybePath = Path.join(dir.build, "\(packageName).xctest")
32+
33+
if maybePath.exists {
34+
return maybePath
35+
} else {
36+
return walk(dir.build).filter{
37+
$0.basename != "Package.xctest" && // this was our hardcoded name, may still exist if no clean
38+
$0.hasSuffix(".xctest")
39+
}.first!
40+
}
41+
}
42+
2443
let yamlPath = Path.join(dir.build, "debug.yaml")
2544
guard yamlPath.exists else { throw Error.DebugYAMLNotFound }
2645

2746
try build(YAMLPath: yamlPath, target: "test")
28-
let success = try test(dir.build, "debug", xctestArg: xctestArg)
47+
48+
let success = try test(path: determineTestPath(), xctestArg: xctestArg)
2949
exit(success ? 0 : 1)
3050
}
3151
} catch {

Sources/swift-test/test.swift

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,36 @@
1111
import PackageType
1212
import Utility
1313

14-
func test(path: String..., xctestArg: String? = nil) throws -> Bool {
15-
let path = Path.join(path)
16-
var args: [String] = []
17-
let testsPath: String
14+
func test(path path: String, xctestArg: String? = nil) throws -> Bool {
15+
16+
guard path.isValidTest else {
17+
throw Error.TestsExecutableNotFound
18+
}
1819

20+
var args: [String] = []
1921
#if os(OSX)
20-
testsPath = Path.join(path, "Package.xctest")
2122
args = ["xcrun", "xctest"]
2223
if let xctestArg = xctestArg {
2324
args += ["-XCTest", xctestArg]
2425
}
25-
args += [testsPath]
26+
args += [path]
2627
#else
27-
testsPath = Path.join(path, "test-Package")
28-
args += [testsPath]
28+
args += [path]
2929
if let xctestArg = xctestArg {
3030
args += [xctestArg]
3131
}
3232
#endif
3333

34-
guard testsPath.testExecutableExists else {
35-
throw Error.TestsExecutableNotFound
36-
}
37-
3834
let result: Void? = try? system(args)
3935
return result != nil
4036
}
4137

4238
private extension String {
43-
var testExecutableExists: Bool {
39+
var isValidTest: Bool {
4440
#if os(OSX)
45-
return self.isDirectory //Package.xctest is dir on OSX
41+
return isDirectory // ${foo}.xctest is dir on OSX
4642
#else
47-
return self.isFile //test-Package is executable on OSX
43+
return isFile // otherwise ${foo}.xctest is executable file
4844
#endif
4945
}
5046
}

0 commit comments

Comments
 (0)