Skip to content

Commit dc58d77

Browse files
franklinschharlanhaskins
authored andcommitted
Allow customization of message shown if tests pass (#3)
If all the tests of a lite instance pass, the string passed as the `successMessage` parameter of `runLite` will be displayed. A default message is displayed if no success message is specified.
1 parent 8516d76 commit dc58d77

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

Sources/LiteSupport/Run.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ public func runLite(substitutions: [(String, String)],
3535
pathExtensions: Set<String>,
3636
testDirPath: String?,
3737
testLinePrefix: String,
38-
parallelismLevel: ParallelismLevel = .none) throws -> Bool {
38+
parallelismLevel: ParallelismLevel = .none,
39+
successMessage: String = "All tests passed! 🎉") throws -> Bool {
3940
let testRunner = try TestRunner(testDirPath: testDirPath,
4041
substitutions: substitutions,
4142
pathExtensions: pathExtensions,
4243
testLinePrefix: testLinePrefix,
43-
parallelismLevel: parallelismLevel)
44+
parallelismLevel: parallelismLevel,
45+
successMessage: successMessage)
4446
return try testRunner.run()
4547
}

Sources/LiteSupport/TestRunner.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,16 @@ class TestRunner {
5353
/// How to parallelize work.
5454
let parallelismLevel: ParallelismLevel
5555

56+
/// The message to print if all the tests passed.
57+
let successMessage: String
58+
5659
/// Creates a test runner that will execute all tests in the provided
5760
/// directory.
5861
/// - throws: A LiteError if the test directory is invalid.
5962
init(testDirPath: String?, substitutions: [(String, String)],
6063
pathExtensions: Set<String>, testLinePrefix: String,
61-
parallelismLevel: ParallelismLevel) throws {
64+
parallelismLevel: ParallelismLevel,
65+
successMessage: String) throws {
6266
let fm = FileManager.default
6367
var isDir: ObjCBool = false
6468
let testDirPath =
@@ -74,6 +78,7 @@ class TestRunner {
7478
self.pathExtensions = pathExtensions
7579
self.testLinePrefix = testLinePrefix
7680
self.parallelismLevel = parallelismLevel
81+
self.successMessage = successMessage
7782
}
7883

7984
func discoverTests() throws -> [TestFile] {
@@ -167,7 +172,7 @@ class TestRunner {
167172
""")
168173

169174
if failures == 0 {
170-
print("All tests passed! 🎉".green.bold)
175+
print(successMessage.green.bold)
171176
return true
172177
}
173178
return false

0 commit comments

Comments
 (0)