From fb6d9137a531a08aa34e4a08b5242863d235a4ea Mon Sep 17 00:00:00 2001 From: Aleksey Berezka Date: Fri, 15 Dec 2023 16:25:35 +0500 Subject: [PATCH] Run on cloud runners (#14) * Run on cloud runners * Using new macos and xcode * Fixed locale in tests --- .github/workflows/unittest.yml | 2 +- .xcode-version | 2 +- Sources/DBXCResultParser/Formatter.swift | 5 +++++ Tests/DBXCResultParserTests/FormatterTests.swift | 14 ++++++++++++-- Tests/DBXCResultParserTests/IntegrationTests.swift | 12 +++++++----- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 42b965c..1dd678d 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -19,7 +19,7 @@ env: jobs: tests: - runs-on: 'ios' + runs-on: 'macos-13' timeout-minutes: 10 steps: diff --git a/.xcode-version b/.xcode-version index c519231..3f10ffe 100644 --- a/.xcode-version +++ b/.xcode-version @@ -1 +1 @@ -14.3 \ No newline at end of file +15 \ No newline at end of file diff --git a/Sources/DBXCResultParser/Formatter.swift b/Sources/DBXCResultParser/Formatter.swift index 92027bc..705e209 100644 --- a/Sources/DBXCResultParser/Formatter.swift +++ b/Sources/DBXCResultParser/Formatter.swift @@ -8,6 +8,8 @@ import Foundation class Formatter { + static var locale: Locale? + static func format(_ report: ReportModel, filters: [Parser.Filter] = [], format: Parser.Format) -> String { @@ -171,6 +173,7 @@ extension String { extension MeasurementFormatter { static var singleTestDurationFormatter: MeasurementFormatter { let formatter = MeasurementFormatter() + formatter.locale = Formatter.locale formatter.unitOptions = [.providedUnit] formatter.numberFormatter.maximumFractionDigits = 0 return formatter @@ -178,6 +181,7 @@ extension MeasurementFormatter { static var totalTestsDurationFormatter: MeasurementFormatter { let formatter = MeasurementFormatter() + formatter.locale = Formatter.locale formatter.unitOptions = [.naturalScale] formatter.numberFormatter.maximumFractionDigits = 0 return formatter @@ -187,6 +191,7 @@ extension MeasurementFormatter { extension NumberFormatter { static var testsCountFormatter: NumberFormatter { let formatter = NumberFormatter() + formatter.locale = Formatter.locale formatter.maximumFractionDigits = 0 return formatter } diff --git a/Tests/DBXCResultParserTests/FormatterTests.swift b/Tests/DBXCResultParserTests/FormatterTests.swift index e488703..79a5993 100644 --- a/Tests/DBXCResultParserTests/FormatterTests.swift +++ b/Tests/DBXCResultParserTests/FormatterTests.swift @@ -2,6 +2,16 @@ import XCTest @testable import DBXCResultParser final class FormatterTests: XCTestCase { + override func setUpWithError() throws { + try super.setUpWithError() + Formatter.locale = Locale(identifier: "en-US") + } + + override func tearDownWithError() throws { + Formatter.locale = nil + try super.tearDownWithError() + } + func test_filter_any_list() { let result = Formatter.format(generalReport, format: .list) @@ -38,12 +48,12 @@ NetworkSpec func test_filter_any_count() { let result = Formatter.format(generalReport, format: .count) - XCTAssertEqual(result, "7 (0 secs)") + XCTAssertEqual(result, "7 (0 sec)") } func test_filter_failure_count() { let result = Formatter.format(generalReport, filters: [.failed], format: .count) - XCTAssertEqual(result, "3 (0 secs)") + XCTAssertEqual(result, "3 (0 sec)") } func test_filter_slow_list_milliseconds() { diff --git a/Tests/DBXCResultParserTests/IntegrationTests.swift b/Tests/DBXCResultParserTests/IntegrationTests.swift index 38dc2c7..85272e6 100644 --- a/Tests/DBXCResultParserTests/IntegrationTests.swift +++ b/Tests/DBXCResultParserTests/IntegrationTests.swift @@ -4,9 +4,11 @@ import XCTest final class IntegrationTests: XCTestCase { override func setUpWithError() throws { try super.setUpWithError() + Formatter.locale = Locale(identifier: "en-US") } override func tearDownWithError() throws { + Formatter.locale = nil try super.tearDownWithError() } @@ -25,25 +27,25 @@ final class IntegrationTests: XCTestCase { let result = try Parser(xcresultPath: Constants.unitTestsReportPath).parse(filters: [.slow(duration: .init(value: 3, unit: .seconds))], format: .list) let expectedResult = """ ContactsViewControllerSpec - ✅🕢 (3 secs) ContactsViewController__load_view__when_feedback_block_are_visible__when_chat_enabled__should_snapshot() - ✅🕢 (3 secs) ContactsViewController__load_view__when_location_button_is_visible__should_snapshot() + ✅🕢 (3 sec) ContactsViewController__load_view__when_feedback_block_are_visible__when_chat_enabled__should_snapshot() + ✅🕢 (3 sec) ContactsViewController__load_view__when_location_button_is_visible__should_snapshot() """ XCTAssertEqual(String(result.prefix(expectedResult.count)), expectedResult) } func test_parse_slow_3s_count() throws { let result = try Parser(xcresultPath: Constants.unitTestsReportPath).parse(filters: [.slow(duration: .init(value: 3, unit: .seconds))], format: .count) - XCTAssertEqual(result, "2 (7 secs)") + XCTAssertEqual(result, "2 (7 sec)") } func test_parse_failed_count() throws { let result = try Parser(xcresultPath: Constants.unitTestsReportPath).parse(filters: [.failed], format: .count) - XCTAssertEqual(result, "77 (9 secs)") + XCTAssertEqual(result, "77 (9 sec)") } func test_parse_failed_slow_3s_count() throws { let result = try Parser(xcresultPath: Constants.unitTestsReportPath).parse(filters: [.failed, .slow(duration: .init(value: 3, unit: .seconds))], format: .count) - XCTAssertEqual(result, "79 (16 secs)") + XCTAssertEqual(result, "79 (16 sec)") } func test_parse_any_count() throws {