Skip to content

Commit cc15171

Browse files
committed
Merge pull request #160 from aciidb0mb3r/patch-12
Throw error if no test module
2 parents 30ea0a9 + 494ec4b commit cc15171

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

Sources/swift-test/Error.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ See http://swift.org/CONTRIBUTORS.txt for Swift project authors
1010

1111
enum Error: ErrorType {
1212
case DebugYAMLNotFound
13+
case TestsExecutableNotFound
1314
}
1415

1516
extension Error: CustomStringConvertible {
1617
var description: String {
1718
switch self {
1819
case .DebugYAMLNotFound:
1920
return "build the package using `swift build` before running tests"
21+
case .TestsExecutableNotFound:
22+
return "no tests found to execute, create a test-module in `Tests` directory"
2023
}
2124
}
2225
}

Sources/swift-test/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ do {
2727
guard yamlPath.exists else { throw Error.DebugYAMLNotFound }
2828

2929
try build(YAMLPath: yamlPath, target: "test")
30-
let success = test(dir.build, "debug")
30+
let success = try test(dir.build, "debug")
3131
exit(success ? 0 : 1)
3232

3333
} catch {

Sources/swift-test/test.swift

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,35 @@
1111
import PackageType
1212
import Utility
1313

14-
func test(path: String..., args: String? = nil) -> Bool {
14+
func test(path: String..., args: String? = nil) throws -> Bool {
1515
let path = Path.join(path)
16-
let result: Void?
16+
var args: [String] = []
17+
let testsPath: String
18+
1719
#if os(OSX)
18-
var args = ["xcrun", "xctest"]
20+
testsPath = Path.join(path, "Package.xctest")
21+
args = ["xcrun", "xctest"]
1922
args += Process.arguments.dropFirst()
20-
args += [Path.join(path, "Package.xctest")]
21-
result = try? system(args)
2223
#else
23-
result = try? system(Path.join(path, "test-Package"))
24+
testsPath = Path.join(path, "test-Package")
2425
#endif
25-
26+
27+
guard testsPath.testExecutableExists else {
28+
throw Error.TestsExecutableNotFound
29+
}
30+
31+
args += [testsPath]
32+
33+
let result: Void? = try? system(args)
2634
return result != nil
2735
}
36+
37+
private extension String {
38+
var testExecutableExists: Bool {
39+
#if os(OSX)
40+
return self.isDirectory //Package.xctest is dir on OSX
41+
#else
42+
return self.isFile //test-Package is executable on OSX
43+
#endif
44+
}
45+
}

0 commit comments

Comments
 (0)