Skip to content

Commit 065c6eb

Browse files
committed
Name test runners consistently
The xctest extension means we won’t conflict with anything else (based on how our existing rules for names are enforced).
1 parent a58b560 commit 065c6eb

File tree

4 files changed

+35
-21
lines changed

4 files changed

+35
-21
lines changed

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/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: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,30 @@ do {
2222
case .Run(let xctestArg):
2323
let dir = try directories()
2424

25-
//FIXME find a reliable name to detect the name of the root test Package
26-
let testPackageName = dir.root.basename
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+
2743
let yamlPath = Path.join(dir.build, "debug.yaml")
2844
guard yamlPath.exists else { throw Error.DebugYAMLNotFound }
2945

3046
try build(YAMLPath: yamlPath, target: "test")
31-
let success = try test(dir.build, "debug", testPackageName: testPackageName, xctestArg: xctestArg)
47+
48+
let success = try test(path: determineTestPath(), xctestArg: xctestArg)
3249
exit(success ? 0 : 1)
3350
}
3451
} 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..., testPackageName: 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, "\(testPackageName).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-\(testPackageName)")
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)