Skip to content

Commit

Permalink
Made reportingService optional and added guard since its never create…
Browse files Browse the repository at this point in the history
…d if we have set the tests not to be uploaded with flag in info.plist
  • Loading branch information
lemonandlime committed Oct 23, 2018
1 parent f947986 commit f9e4f96
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions Sources/RPListener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import XCTest

public class RPListener: NSObject, XCTestObservation {

private var reportingService: ReportingService!
private var reportingService: ReportingService?
private let queue = DispatchQueue(label: "com.report_portal.reporting", qos: .utility)

public override init() {
Expand Down Expand Up @@ -77,17 +77,20 @@ public class RPListener: NSObject, XCTestObservation {
print("Set 'YES' for 'PushTestDataToReportPortal' property in Info.plist if you want to put data to report portal")
return
}
reportingService = ReportingService(configuration: configuration)
let reportingService = ReportingService(configuration: configuration)
self.reportingService = reportingService
queue.async {
do {
try self.reportingService.startLaunch()
try reportingService.startLaunch()
} catch let error {
print(error)
}
}
}

public func testSuiteWillStart(_ testSuite: XCTestSuite) {
guard let reportingService = self.reportingService else { return }

guard
!testSuite.name.contains("All tests"),
!testSuite.name.contains("Selected tests") else
Expand All @@ -98,9 +101,9 @@ public class RPListener: NSObject, XCTestObservation {
queue.async {
do {
if testSuite.name.contains(".xctest") {
try self.reportingService.startRootSuite(testSuite)
try reportingService.startRootSuite(testSuite)
} else {
try self.reportingService.startTestSuite(testSuite)
try reportingService.startTestSuite(testSuite)
}
} catch let error {
print(error)
Expand All @@ -113,36 +116,46 @@ public class RPListener: NSObject, XCTestObservation {
}

public func testCaseWillStart(_ testCase: XCTestCase) {
guard let reportingService = self.reportingService else { return }

queue.async {
do {
try self.reportingService.startTest(testCase)
try reportingService.startTest(testCase)
} catch let error {
print(error)
}
}
}

public func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: Int) {
guard let reportingService = self.reportingService else { return }

queue.async {
do {
try self.reportingService.reportError(message: "Test '\(String(describing: testCase.name)))' failed on line \(lineNumber), \(description)")
try reportingService.reportError(message: "Test '\(String(describing: testCase.name)))' failed on line \(lineNumber), \(description)")
} catch let error {
print(error)
}
}
}

public func testCaseDidFinish(_ testCase: XCTestCase) {
guard let reportingService = self.reportingService else { return }


queue.async {
do {
try self.reportingService.finishTest(testCase)
try reportingService.finishTest(testCase)
} catch let error {
print(error)
}
}
}

public func testSuiteDidFinish(_ testSuite: XCTestSuite) {
guard let reportingService = self.reportingService else { return }


guard
!testSuite.name.contains("All tests"),
!testSuite.name.contains("Selected tests") else
Expand All @@ -153,9 +166,9 @@ public class RPListener: NSObject, XCTestObservation {
queue.async {
do {
if testSuite.name.contains(".xctest") {
try self.reportingService.finishRootSuite()
try reportingService.finishRootSuite()
} else {
try self.reportingService.finishTestSuite()
try reportingService.finishTestSuite()
}
} catch let error {
print(error)
Expand All @@ -164,9 +177,11 @@ public class RPListener: NSObject, XCTestObservation {
}

public func testBundleDidFinish(_ testBundle: Bundle) {
guard let reportingService = self.reportingService else { return }

queue.sync() {
do {
try self.reportingService.finishLaunch()
try reportingService.finishLaunch()
} catch let error {
print(error)
}
Expand Down

0 comments on commit f9e4f96

Please sign in to comment.