Skip to content

Commit

Permalink
Merge pull request #38 from bow-swift/nef_testing
Browse files Browse the repository at this point in the history
`nef` boilerplate for testing
  • Loading branch information
miguelangel-dev authored Apr 23, 2019
2 parents b4db5e7 + 54bc304 commit 7e56905
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 1 deletion.
1 change: 0 additions & 1 deletion template/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ target '${POD_NAME}' do

pod "Bow", "~> 0.0.0"
pod "BowEffects", "~> 0.0.0"
pod "BowResult", "~> 0.0.0"
pod "BowRx", "~> 0.0.0"
pod "BowBrightFutures", "~> 0.0.0"
pod "BowOptics", "~> 0.0.0"
Expand Down
47 changes: 47 additions & 0 deletions template/ios/PROJECT.playground/Sources/NefTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import Foundation
import XCTest

public extension Nef {

static func run<T: XCTestCase>(testCase class: T.Type) {
startTestObserver()
T.defaultTestSuite.run()
}

static private func startTestObserver() {
_ = testObserverInstalled
}

static private var testObserverInstalled = { () -> NefTestFailObserver in
let testObserver = NefTestFailObserver()
XCTestObservationCenter.shared.addTestObserver(testObserver)
return testObserver
}()
}

// MARK: enrich the output for XCTest
fileprivate class NefTestFailObserver: NSObject, XCTestObservation {

private var numberOfFailedTests = 0

func testSuiteWillStart(_ testSuite: XCTestSuite) {
numberOfFailedTests = 0
}

func testSuiteDidFinish(_ testSuite: XCTestSuite) {
if numberOfFailedTests > 0 {
print("💢 Test Suite '\(testSuite.name)' finished with \(numberOfFailedTests) failed \(numberOfFailedTests > 1 ? "tests" : "test").")
} else {
print("🔅 Test Suite '\(testSuite.name)' finished successfully.")
}
}

func testCase(_ testCase: XCTestCase,
didFailWithDescription description: String,
inFile filePath: String?,
atLine lineNumber: Int) {

numberOfFailedTests += 1
print("❗️Test Fail '\(testCase.name)':\(UInt(lineNumber)): \(description.description)")
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions template/osx/PROJECT.playground/Sources/NefTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Foundation
import XCTest

public enum Nef {}

public extension Nef {

static func run<T: XCTestCase>(testCase class: T.Type) {
startTestObserver()
T.defaultTestSuite.run()
}

static private func startTestObserver() {
_ = testObserverInstalled
}

static private var testObserverInstalled = { () -> NefTestFailObserver in
let testObserver = NefTestFailObserver()
XCTestObservationCenter.shared.addTestObserver(testObserver)
return testObserver
}()
}

// MARK: enrich the output for XCTest
fileprivate class NefTestFailObserver: NSObject, XCTestObservation {

private var numberOfFailedTests = 0

func testSuiteWillStart(_ testSuite: XCTestSuite) {
numberOfFailedTests = 0
}

func testSuiteDidFinish(_ testSuite: XCTestSuite) {
if numberOfFailedTests > 0 {
print("💢 Test Suite '\(testSuite.name)' finished with \(numberOfFailedTests) failed \(numberOfFailedTests > 1 ? "tests" : "test").")
} else {
print("🔅 Test Suite '\(testSuite.name)' finished successfully.")
}
}

func testCase(_ testCase: XCTestCase,
didFailWithDescription description: String,
inFile filePath: String?,
atLine lineNumber: Int) {

numberOfFailedTests += 1
print("❗️Test Fail '\(testCase.name)':\(UInt(lineNumber)): \(description.description)")
}
}

0 comments on commit 7e56905

Please sign in to comment.