From 6ef4386b85a2d0a5103adc0c0739552421e0dd1f Mon Sep 17 00:00:00 2001 From: Franklin Schrans Date: Wed, 18 Apr 2018 23:50:36 +0100 Subject: [PATCH] Allow customization of message shown if tests pass 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. --- Sources/LiteSupport/Run.swift | 6 ++++-- Sources/LiteSupport/TestRunner.swift | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Sources/LiteSupport/Run.swift b/Sources/LiteSupport/Run.swift index e54aa9a..aaa2acd 100644 --- a/Sources/LiteSupport/Run.swift +++ b/Sources/LiteSupport/Run.swift @@ -35,11 +35,13 @@ public func runLite(substitutions: [(String, String)], pathExtensions: Set, testDirPath: String?, testLinePrefix: String, - parallelismLevel: ParallelismLevel = .none) throws -> Bool { + parallelismLevel: ParallelismLevel = .none, + successMessage: String = "All tests passed! 🎉") throws -> Bool { let testRunner = try TestRunner(testDirPath: testDirPath, substitutions: substitutions, pathExtensions: pathExtensions, testLinePrefix: testLinePrefix, - parallelismLevel: parallelismLevel) + parallelismLevel: parallelismLevel, + successMessage: successMessage) return try testRunner.run() } diff --git a/Sources/LiteSupport/TestRunner.swift b/Sources/LiteSupport/TestRunner.swift index 4265726..f0da4c4 100644 --- a/Sources/LiteSupport/TestRunner.swift +++ b/Sources/LiteSupport/TestRunner.swift @@ -53,12 +53,16 @@ class TestRunner { /// How to parallelize work. let parallelismLevel: ParallelismLevel + /// The message to print if all the tests passed. + let successMessage: String + /// Creates a test runner that will execute all tests in the provided /// directory. /// - throws: A LiteError if the test directory is invalid. init(testDirPath: String?, substitutions: [(String, String)], pathExtensions: Set, testLinePrefix: String, - parallelismLevel: ParallelismLevel) throws { + parallelismLevel: ParallelismLevel, + successMessage: String) throws { let fm = FileManager.default var isDir: ObjCBool = false let testDirPath = @@ -74,6 +78,7 @@ class TestRunner { self.pathExtensions = pathExtensions self.testLinePrefix = testLinePrefix self.parallelismLevel = parallelismLevel + self.successMessage = successMessage } func discoverTests() throws -> [TestFile] { @@ -167,7 +172,7 @@ class TestRunner { """) if failures == 0 { - print("All tests passed! 🎉".green.bold) + print(successMessage.green.bold) return true } return false