diff --git a/Tests/TerminalProgressTests/ProgressBarTests.swift b/Tests/TerminalProgressTests/ProgressBarTests.swift index 3be26d74..9a65ca48 100644 --- a/Tests/TerminalProgressTests/ProgressBarTests.swift +++ b/Tests/TerminalProgressTests/ProgressBarTests.swift @@ -14,41 +14,42 @@ // limitations under the License. //===----------------------------------------------------------------------===// -import XCTest +import Foundation +import Testing @testable import TerminalProgress -final class ProgressBarTests: XCTestCase { - func testSpinner() async throws { +struct ProgressBarTests { + @Test func spinner() throws { let config = try ProgressConfig( description: "Task" ) let progress = ProgressBar(config: config) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task [0s]") + #expect(output == "⠋ Task [0s]") } - func testSpinnerFinished() async throws { + @Test func spinnerFinished() throws { let config = try ProgressConfig( description: "Task" ) let progress = ProgressBar(config: config) progress.finish() let output = progress.draw() - XCTAssertEqual(output, "✔ Task [0s]") + #expect(output == "✔ Task [0s]") } - func testNoSpinner() async throws { + @Test func noSpinner() throws { let config = try ProgressConfig( description: "Task", showSpinner: false ) let progress = ProgressBar(config: config) let output = progress.draw() - XCTAssertEqual(output, "Task [0s]") + #expect(output == "Task [0s]") } - func testNoSpinnerFinished() async throws { + @Test func noSpinnerFinished() throws { let config = try ProgressConfig( description: "Task", showSpinner: false @@ -56,30 +57,30 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.finish() let output = progress.draw() - XCTAssertEqual(output, "Task [0s]") + #expect(output == "Task [0s]") } - func testNoTasks() async throws { + @Test func noTasks() throws { let config = try ProgressConfig( description: "Task", showTasks: false ) let progress = ProgressBar(config: config) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task [0s]") + #expect(output == "⠋ Task [0s]") } - func testTasks() async throws { + @Test func tasks() throws { let config = try ProgressConfig( description: "Task", showTasks: true ) let progress = ProgressBar(config: config) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task [0s]") + #expect(output == "⠋ Task [0s]") } - func testTasksAdd() async throws { + @Test func tasksAdd() throws { let config = try ProgressConfig( description: "Task", showTasks: true @@ -87,10 +88,10 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.add(tasks: 1) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task [0s]") + #expect(output == "⠋ Task [0s]") } - func testTasksSet() async throws { + @Test func tasksSet() throws { let config = try ProgressConfig( description: "Task", showTasks: true @@ -98,10 +99,10 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.set(tasks: 2) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task [0s]") + #expect(output == "⠋ Task [0s]") } - func testTotalTasks() async throws { + @Test func totalTasks() throws { let config = try ProgressConfig( description: "Task", showTasks: true, @@ -109,10 +110,10 @@ final class ProgressBarTests: XCTestCase { ) let progress = ProgressBar(config: config) let output = progress.draw() - XCTAssertEqual(output, "⠋ [0/2] Task [0s]") + #expect(output == "⠋ [0/2] Task [0s]") } - func testTotalTasksFinished() async throws { + @Test func totalTasksFinished() throws { let config = try ProgressConfig( description: "Task", showTasks: true, @@ -121,10 +122,10 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.finish() let output = progress.draw() - XCTAssertEqual(output, "✔ [0/2] Task [0s]") + #expect(output == "✔ [0/2] Task [0s]") } - func testTotalTasksAdd() async throws { + @Test func totalTasksAdd() throws { let config = try ProgressConfig( description: "Task", showTasks: true, @@ -133,10 +134,10 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.add(totalTasks: 1) let output = progress.draw() - XCTAssertEqual(output, "⠋ [0/2] Task [0s]") + #expect(output == "⠋ [0/2] Task [0s]") } - func testTotalTasksSet() async throws { + @Test func totalTasksSet() throws { let config = try ProgressConfig( description: "Task", showTasks: true, @@ -145,35 +146,32 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.set(totalTasks: 2) let output = progress.draw() - XCTAssertEqual(output, "⠋ [0/2] Task [0s]") + #expect(output == "⠋ [0/2] Task [0s]") } - func testTotalTasksInvalid() throws { - do { - let _ = try ProgressConfig(description: "test", totalTasks: 0) - } catch ProgressConfig.Error.invalid(_) { - return + @Test func totalTasksInvalid() { + #expect(throws: ProgressConfig.Error.self) { + try ProgressConfig(description: "test", totalTasks: 0) } - XCTFail("expected ProgressConfig.Error.invalid") } - func testDescription() async throws { + @Test func description() throws { let config = try ProgressConfig( description: "Task" ) let progress = ProgressBar(config: config) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task [0s]") + #expect(output == "⠋ Task [0s]") } - func testNoDescription() async throws { + @Test func noDescription() throws { let config = try ProgressConfig() let progress = ProgressBar(config: config) let output = progress.draw() - XCTAssertEqual(output, "⠋ [0s]") + #expect(output == "⠋ [0s]") } - func testNoPercent() async throws { + @Test func noPercent() throws { let config = try ProgressConfig( description: "Task", showPercent: false, @@ -182,20 +180,20 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.set(items: 1) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task [0s]") + #expect(output == "⠋ Task [0s]") } - func testPercentHidden() async throws { + @Test func percentHidden() throws { let config = try ProgressConfig( description: "Task", showPercent: true ) let progress = ProgressBar(config: config) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task [0s]") + #expect(output == "⠋ Task [0s]") } - func testPercentItems() async throws { + @Test func percentItems() throws { let config = try ProgressConfig( description: "Task", showPercent: true, @@ -204,10 +202,10 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.set(items: 1) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task 50% [0s]") + #expect(output == "⠋ Task 50% [0s]") } - func testPercentItemsFinished() async throws { + @Test func percentItemsFinished() throws { let config = try ProgressConfig( description: "Task", showPercent: true, @@ -217,10 +215,10 @@ final class ProgressBarTests: XCTestCase { progress.set(items: 1) progress.finish() let output = progress.draw() - XCTAssertEqual(output, "✔ Task 100% [0s]") + #expect(output == "✔ Task 100% [0s]") } - func testPercentSize() async throws { + @Test func percentSize() throws { let config = try ProgressConfig( description: "Task", showPercent: true, @@ -231,10 +229,10 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.set(size: 1) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task 50% [0s]") + #expect(output == "⠋ Task 50% [0s]") } - func testPercentSizeFinished() async throws { + @Test func percentSizeFinished() throws { let config = try ProgressConfig( description: "Task", showPercent: true, @@ -246,10 +244,10 @@ final class ProgressBarTests: XCTestCase { progress.set(size: 1) progress.finish() let output = progress.draw() - XCTAssertEqual(output, "✔ Task 100% [0s]") + #expect(output == "✔ Task 100% [0s]") } - func testNoProgressBar() async throws { + @Test func noProgressBar() throws { let config = try ProgressConfig( description: "Task", showProgressBar: false, @@ -259,10 +257,10 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.set(items: 1) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task 50% [0s]") + #expect(output == "⠋ Task 50% [0s]") } - func testProgressBar() async throws { + @Test func progressBar() throws { let config = try ProgressConfig( description: "Task", showProgressBar: true, @@ -272,10 +270,10 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.set(items: 1) let output = progress.draw() - XCTAssertEqual(output, "Task 50% |██ | [0s]") + #expect(output == "Task 50% |██ | [0s]") } - func testProgressBarFinished() async throws { + @Test func progressBarFinished() throws { let config = try ProgressConfig( description: "Task", showProgressBar: true, @@ -286,10 +284,10 @@ final class ProgressBarTests: XCTestCase { progress.set(items: 1) progress.finish() let output = progress.draw() - XCTAssertEqual(output, "Task 100% |███| [0s]") + #expect(output == "Task 100% |███| [0s]") } - func testProgressBarMinWidth() async throws { + @Test func progressBarMinWidth() throws { let config = try ProgressConfig( description: "Task", showProgressBar: true, @@ -299,10 +297,10 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.set(items: 1) let output = progress.draw() - XCTAssertEqual(output, "Task 50% | | [0s]") + #expect(output == "Task 50% | | [0s]") } - func testProgressBarMinWidthFinished() async throws { + @Test func progressBarMinWidthFinished() throws { let config = try ProgressConfig( description: "Task", showProgressBar: true, @@ -313,30 +311,30 @@ final class ProgressBarTests: XCTestCase { progress.set(items: 1) progress.finish() let output = progress.draw() - XCTAssertEqual(output, "Task 100% |█| [0s]") + #expect(output == "Task 100% |█| [0s]") } - func testNoItems() async throws { + @Test func noItems() throws { let config = try ProgressConfig( description: "Task", showItems: false ) let progress = ProgressBar(config: config) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task [0s]") + #expect(output == "⠋ Task [0s]") } - func testItemsZero() async throws { + @Test func itemsZero() throws { let config = try ProgressConfig( description: "Task", showItems: true ) let progress = ProgressBar(config: config) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task [0s]") + #expect(output == "⠋ Task [0s]") } - func testItemsAdd() async throws { + @Test func itemsAdd() throws { let config = try ProgressConfig( description: "Task", showItems: true @@ -344,10 +342,10 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.add(items: 1) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task (1 it) [0s]") + #expect(output == "⠋ Task (1 it) [0s]") } - func testItemsAddFinish() async throws { + @Test func itemsAddFinish() throws { let config = try ProgressConfig( description: "Task", showItems: true @@ -356,10 +354,10 @@ final class ProgressBarTests: XCTestCase { progress.add(items: 1) progress.finish() let output = progress.draw() - XCTAssertEqual(output, "✔ Task [0s]") + #expect(output == "✔ Task [0s]") } - func testItemsSet() async throws { + @Test func itemsSet() throws { let config = try ProgressConfig( description: "Task", showItems: true @@ -367,10 +365,10 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.set(items: 2) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task (2 it) [0s]") + #expect(output == "⠋ Task (2 it) [0s]") } - func testTotalItemsZeroItems() async throws { + @Test func totalItemsZeroItems() throws { let config = try ProgressConfig( description: "Task", showItems: true, @@ -378,10 +376,10 @@ final class ProgressBarTests: XCTestCase { ) let progress = ProgressBar(config: config) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task 0% [0s]") + #expect(output == "⠋ Task 0% [0s]") } - func testTotalItems() async throws { + @Test func totalItems() throws { let config = try ProgressConfig( description: "Task", showItems: true, @@ -390,10 +388,10 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.set(items: 1) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task 50% (1 of 2 it) [0s]") + #expect(output == "⠋ Task 50% (1 of 2 it) [0s]") } - func testTotalItemsFinish() async throws { + @Test func totalItemsFinish() throws { let config = try ProgressConfig( description: "Task", showItems: true, @@ -403,10 +401,10 @@ final class ProgressBarTests: XCTestCase { progress.set(items: 1) progress.finish() let output = progress.draw() - XCTAssertEqual(output, "✔ Task 100% (2 it) [0s]") + #expect(output == "✔ Task 100% (2 it) [0s]") } - func testTotalItemsAdd() async throws { + @Test func totalItemsAdd() throws { let config = try ProgressConfig( description: "Task", showItems: true, @@ -416,10 +414,10 @@ final class ProgressBarTests: XCTestCase { progress.set(items: 1) progress.add(totalItems: 1) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task 50% (1 of 2 it) [0s]") + #expect(output == "⠋ Task 50% (1 of 2 it) [0s]") } - func testTotalItemsSet() async throws { + @Test func totalItemsSet() throws { let config = try ProgressConfig( description: "Task", showItems: true, @@ -429,39 +427,36 @@ final class ProgressBarTests: XCTestCase { progress.set(items: 1) progress.set(totalItems: 2) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task 50% (1 of 2 it) [0s]") + #expect(output == "⠋ Task 50% (1 of 2 it) [0s]") } - func testTotalItemsInvalid() throws { - do { - let _ = try ProgressConfig(description: "test", totalItems: 0) - } catch ProgressConfig.Error.invalid(_) { - return + @Test func totalItemsInvalid() { + #expect(throws: ProgressConfig.Error.self) { + try ProgressConfig(description: "test", totalItems: 0) } - XCTFail("expected ProgressConfig.Error.invalid") } - func testNoSize() async throws { + @Test func noSize() throws { let config = try ProgressConfig( description: "Task", showSize: false ) let progress = ProgressBar(config: config) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task [0s]") + #expect(output == "⠋ Task [0s]") } - func testSizeZero() async throws { + @Test func sizeZero() throws { let config = try ProgressConfig( description: "Task", showSize: true ) let progress = ProgressBar(config: config) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task [0s]") + #expect(output == "⠋ Task [0s]") } - func testSizeAdd() async throws { + @Test func sizeAdd() throws { let config = try ProgressConfig( description: "Task", showSize: true, @@ -470,10 +465,10 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.add(size: 1) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task (1 byte) [0s]") + #expect(output == "⠋ Task (1 byte) [0s]") } - func testSizeAddFinish() async throws { + @Test func sizeAddFinish() throws { let config = try ProgressConfig( description: "Task", showSize: true, @@ -483,10 +478,10 @@ final class ProgressBarTests: XCTestCase { progress.add(size: 1) progress.finish() let output = progress.draw() - XCTAssertEqual(output, "✔ Task [0s]") + #expect(output == "✔ Task [0s]") } - func testSizeSet() async throws { + @Test func sizeSet() throws { let config = try ProgressConfig( description: "Task", showSize: true, @@ -495,10 +490,10 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.set(size: 2) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task (2 bytes) [0s]") + #expect(output == "⠋ Task (2 bytes) [0s]") } - func testTotalSizeZeroSize() async throws { + @Test func totalSizeZeroSize() throws { let config = try ProgressConfig( description: "Task", showSize: true, @@ -506,10 +501,10 @@ final class ProgressBarTests: XCTestCase { ) let progress = ProgressBar(config: config) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task 0% [0s]") + #expect(output == "⠋ Task 0% [0s]") } - func testTotalSizeDifferentUnits() async throws { + @Test func totalSizeDifferentUnits() throws { let config = try ProgressConfig( description: "Task", showSize: true, @@ -519,10 +514,10 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.set(size: 1) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task 50% (1 byte/2 bytes) [0s]") + #expect(output == "⠋ Task 50% (1 byte/2 bytes) [0s]") } - func testTotalSizeDifferentUnitsFinish() async throws { + @Test func totalSizeDifferentUnitsFinish() throws { let config = try ProgressConfig( description: "Task", showSize: true, @@ -533,10 +528,10 @@ final class ProgressBarTests: XCTestCase { progress.set(size: 1) progress.finish() let output = progress.draw() - XCTAssertEqual(output, "✔ Task 100% (2 bytes) [0s]") + #expect(output == "✔ Task 100% (2 bytes) [0s]") } - func testTotalSizeSameUnits() async throws { + @Test func totalSizeSameUnits() throws { let config = try ProgressConfig( description: "Task", showSize: true, @@ -546,10 +541,10 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.set(size: 2) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task 50% (2/4 bytes) [0s]") + #expect(output == "⠋ Task 50% (2/4 bytes) [0s]") } - func testTotalSizeSameUnitsFinish() async throws { + @Test func totalSizeSameUnitsFinish() throws { let config = try ProgressConfig( description: "Task", showSize: true, @@ -560,10 +555,10 @@ final class ProgressBarTests: XCTestCase { progress.set(size: 2) progress.finish() let output = progress.draw() - XCTAssertEqual(output, "✔ Task 100% (4 bytes) [0s]") + #expect(output == "✔ Task 100% (4 bytes) [0s]") } - func testTotalSizeAdd() async throws { + @Test func totalSizeAdd() throws { let config = try ProgressConfig( description: "Task", showSize: true, @@ -574,10 +569,10 @@ final class ProgressBarTests: XCTestCase { progress.set(size: 2) progress.add(totalSize: 1) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task 50% (2/4 bytes) [0s]") + #expect(output == "⠋ Task 50% (2/4 bytes) [0s]") } - func testTotalSizeSet() async throws { + @Test func totalSizeSet() throws { let config = try ProgressConfig( description: "Task", showSize: true, @@ -588,19 +583,16 @@ final class ProgressBarTests: XCTestCase { progress.set(size: 2) progress.set(totalSize: 4) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task 50% (2/4 bytes) [0s]") + #expect(output == "⠋ Task 50% (2/4 bytes) [0s]") } - func testTotalSizeInvalid() throws { - do { - let _ = try ProgressConfig(description: "test", totalSize: 0) - } catch ProgressConfig.Error.invalid(_) { - return + @Test func totalSizeInvalid() { + #expect(throws: ProgressConfig.Error.self) { + try ProgressConfig(description: "test", totalSize: 0) } - XCTFail("expected ProgressConfig.Error.invalid") } - func testItemsAndSize() async throws { + @Test func itemsAndSize() throws { let config = try ProgressConfig( description: "Task", showItems: true, @@ -613,10 +605,10 @@ final class ProgressBarTests: XCTestCase { progress.set(items: 1) progress.set(size: 2) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task 50% (1 of 2 it, 2/4 bytes) [0s]") + #expect(output == "⠋ Task 50% (1 of 2 it, 2/4 bytes) [0s]") } - func testItemsAndSizeFinish() async throws { + @Test func itemsAndSizeFinish() throws { let config = try ProgressConfig( description: "Task", showItems: true, @@ -630,10 +622,10 @@ final class ProgressBarTests: XCTestCase { progress.set(size: 2) progress.finish() let output = progress.draw() - XCTAssertEqual(output, "✔ Task 100% (2 it, 4 bytes) [0s]") + #expect(output == "✔ Task 100% (2 it, 4 bytes) [0s]") } - func testNoSpeed() async throws { + @Test func noSpeed() throws { let config = try ProgressConfig( description: "Task", showSpeed: false, @@ -642,10 +634,10 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.set(size: 2) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task 50% (2/4 bytes) [0s]") + #expect(output == "⠋ Task 50% (2/4 bytes) [0s]") } - func testSpeed() async throws { + @Test func speed() throws { let config = try ProgressConfig( description: "Task", showSpeed: true, @@ -654,10 +646,10 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.set(size: 2) let output = progress.draw() - XCTAssertTrue(output.contains("/s")) + #expect(output.contains("/s")) } - func testSpeedFinish() async throws { + @Test func speedFinish() throws { let config = try ProgressConfig( description: "Task", showSpeed: true, @@ -667,10 +659,10 @@ final class ProgressBarTests: XCTestCase { progress.set(size: 2) progress.finish() let output = progress.draw() - XCTAssertFalse(output.contains("/s")) + #expect(!output.contains("/s")) } - func testItemsSizeAndSpeed() async throws { + @Test func itemsSizeAndSpeed() throws { let config = try ProgressConfig( description: "Task", showItems: true, @@ -683,11 +675,11 @@ final class ProgressBarTests: XCTestCase { progress.set(items: 1) progress.set(size: 2) let output = progress.draw() - XCTAssertTrue(output.contains("1 of 2 it, 2/4 bytes")) - XCTAssertTrue(output.contains("/s")) + #expect(output.contains("1 of 2 it, 2/4 bytes")) + #expect(output.contains("/s")) } - func testItemsSizeAndSpeedFinish() async throws { + @Test func itemsSizeAndSpeedFinish() throws { let config = try ProgressConfig( description: "Task", showItems: true, @@ -701,21 +693,21 @@ final class ProgressBarTests: XCTestCase { progress.set(size: 2) progress.finish() let output = progress.draw() - XCTAssertTrue(output.contains("2 it, 4 bytes")) - XCTAssertFalse(output.contains("/s")) + #expect(output.contains("2 it, 4 bytes")) + #expect(!output.contains("/s")) } - func testNoTime() async throws { + @Test func noTime() throws { let config = try ProgressConfig( description: "Task", showTime: false ) let progress = ProgressBar(config: config) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task") + #expect(output == "⠋ Task") } - func testTime() async throws { + @Test func time() throws { let config = try ProgressConfig( description: "Task", showTime: true @@ -723,10 +715,10 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) sleep(1) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task [1s]") + #expect(output == "⠋ Task [1s]") } - func testIgnoreSmallSize() async throws { + @Test func ignoreSmallSize() throws { let config = try ProgressConfig( description: "Task", ignoreSmallSize: true, @@ -735,10 +727,10 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.set(size: 2) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task [0s]") + #expect(output == "⠋ Task [0s]") } - func testProgressBarSizeExceedsTotal() async throws { + @Test func progressBarSizeExceedsTotal() throws { let config = try ProgressConfig( description: "Task", showProgressBar: true, @@ -749,7 +741,7 @@ final class ProgressBarTests: XCTestCase { let _ = progress.draw() } - func testProgressBarNegativeValue() async throws { + @Test func progressBarNegativeValue() throws { // Regression test: a negative progress value (e.g. from a race in progress events) // must not cause String(repeating:count:) to be called with a negative count. let config = try ProgressConfig( @@ -765,7 +757,7 @@ final class ProgressBarTests: XCTestCase { let _ = progress.draw(state: state, detail: .full) } - func testItemsName() async throws { + @Test func itemsName() throws { let config = try ProgressConfig( description: "Task", itemsName: "files", @@ -775,19 +767,19 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.set(items: 1) let output = progress.draw() - XCTAssertEqual(output, "⠋ Task 50% (1 of 2 files) [0s]") + #expect(output == "⠋ Task 50% (1 of 2 files) [0s]") } - func testPlainModeConfig() async throws { + @Test func plainModeConfig() throws { let config = try ProgressConfig( description: "Task", showSpinner: false, outputMode: .plain ) - XCTAssertEqual(config.outputMode, .plain) + #expect(config.outputMode == .plain) } - func testPlainModeDraw() async throws { + @Test func plainModeDraw() throws { let config = try ProgressConfig( description: "Task", showSpinner: false, @@ -795,10 +787,10 @@ final class ProgressBarTests: XCTestCase { ) let progress = ProgressBar(config: config) let output = progress.draw() - XCTAssertEqual(output, "Task [0s]") + #expect(output == "Task [0s]") } - func testPlainModeDrawWithTasks() async throws { + @Test func plainModeDrawWithTasks() throws { let config = try ProgressConfig( description: "Task", showSpinner: false, @@ -808,10 +800,10 @@ final class ProgressBarTests: XCTestCase { ) let progress = ProgressBar(config: config) let output = progress.draw() - XCTAssertEqual(output, "[0/2] Task [0s]") + #expect(output == "[0/2] Task [0s]") } - func testPlainModeDrawWithPercent() async throws { + @Test func plainModeDrawWithPercent() throws { let config = try ProgressConfig( description: "Task", showSpinner: false, @@ -822,10 +814,10 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.set(items: 1) let output = progress.draw() - XCTAssertEqual(output, "Task 50% (1 of 2 it) [0s]") + #expect(output == "Task 50% (1 of 2 it) [0s]") } - func testPlainModeFinished() async throws { + @Test func plainModeFinished() throws { let config = try ProgressConfig( description: "Task", showSpinner: false, @@ -838,10 +830,10 @@ final class ProgressBarTests: XCTestCase { progress.set(tasks: 2) progress.finish() let output = progress.draw() - XCTAssertEqual(output, "[2/2] Task [0s]") + #expect(output == "[2/2] Task [0s]") } - func testPlainModeWithSize() async throws { + @Test func plainModeWithSize() throws { let config = try ProgressConfig( description: "Task", showSpinner: false, @@ -853,10 +845,10 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.set(size: 2) let output = progress.draw() - XCTAssertEqual(output, "Task 50% (2/4 bytes) [0s]") + #expect(output == "Task 50% (2/4 bytes) [0s]") } - func testPlainModeNoProgressBar() async throws { + @Test func plainModeNoProgressBar() throws { let config = try ProgressConfig( description: "Task", showSpinner: false, @@ -867,10 +859,10 @@ final class ProgressBarTests: XCTestCase { let progress = ProgressBar(config: config) progress.set(items: 1) let output = progress.draw() - XCTAssertEqual(output, "Task 50% [0s]") + #expect(output == "Task 50% [0s]") } - func testPlainModeNoAnsiEscapes() async throws { + @Test func plainModeNoAnsiEscapes() throws { let config = try ProgressConfig( description: "Task", showSpinner: false, @@ -878,10 +870,10 @@ final class ProgressBarTests: XCTestCase { ) let progress = ProgressBar(config: config) let output = progress.draw() - XCTAssertFalse(output.contains("\u{001B}")) + #expect(!output.contains("\u{001B}")) } - func testPlainModeTerminalOutput() async throws { + @Test func plainModeTerminalOutput() throws { let pipe = Pipe() let config = try ProgressConfig( terminal: pipe.fileHandleForWriting, @@ -899,12 +891,12 @@ final class ProgressBarTests: XCTestCase { let output = String(decoding: data, as: UTF8.self) let lines = output.components(separatedBy: "\n").filter { !$0.isEmpty } // Expect exactly 2 lines: one from render, one from finish - XCTAssertEqual(lines.count, 2) - XCTAssertTrue(lines[0].contains("Task")) - XCTAssertTrue(lines[1].contains("Task")) + #expect(lines.count == 2) + #expect(lines[0].contains("Task")) + #expect(lines[1].contains("Task")) } - func testPlainModeTerminalOutputNoAnsiEscapes() async throws { + @Test func plainModeTerminalOutputNoAnsiEscapes() throws { let pipe = Pipe() let config = try ProgressConfig( terminal: pipe.fileHandleForWriting, @@ -920,10 +912,10 @@ final class ProgressBarTests: XCTestCase { let data = pipe.fileHandleForReading.readDataToEndOfFile() let output = String(decoding: data, as: UTF8.self) - XCTAssertFalse(output.contains("\u{001B}")) + #expect(!output.contains("\u{001B}")) } - func testPlainModeTerminalOutputUsesNewlines() async throws { + @Test func plainModeTerminalOutputUsesNewlines() throws { let pipe = Pipe() let config = try ProgressConfig( terminal: pipe.fileHandleForWriting, @@ -940,11 +932,11 @@ final class ProgressBarTests: XCTestCase { let data = pipe.fileHandleForReading.readDataToEndOfFile() let output = String(decoding: data, as: UTF8.self) // Plain mode should use newlines, not carriage returns - XCTAssertFalse(output.contains("\r")) - XCTAssertTrue(output.contains("\n")) + #expect(!output.contains("\r")) + #expect(output.contains("\n")) } - func testPlainModeDefaultClearOnFinishOmitsFinalLine() async throws { + @Test func plainModeDefaultClearOnFinishOmitsFinalLine() throws { let pipe = Pipe() let config = try ProgressConfig( terminal: pipe.fileHandleForWriting, @@ -960,40 +952,40 @@ final class ProgressBarTests: XCTestCase { let data = pipe.fileHandleForReading.readDataToEndOfFile() let output = String(decoding: data, as: UTF8.self) let lines = output.components(separatedBy: "\n").filter { !$0.isEmpty } - XCTAssertEqual(lines.count, 1) - XCTAssertEqual(lines.first, "Task [0s]") + #expect(lines.count == 1) + #expect(lines.first == "Task [0s]") } - func testOutputModeDefaultIsAnsi() async throws { + @Test func outputModeDefaultIsAnsi() throws { let config = try ProgressConfig(description: "Task") - XCTAssertEqual(config.outputMode, .ansi) + #expect(config.outputMode == .ansi) } // MARK: - Color mode tests - func testColorModeConfig() async throws { + @Test func colorModeConfig() throws { let config = try ProgressConfig( description: "Task", outputMode: .color ) - XCTAssertEqual(config.outputMode, .color) + #expect(config.outputMode == .color) } - func testVisibleLengthPlainText() async throws { + @Test func visibleLengthPlainText() { let text = "hello" - XCTAssertEqual(text.visibleLength, 5) + #expect(text.visibleLength == 5) } - func testVisibleLengthWithAnsiCodes() async throws { + @Test func visibleLengthWithAnsiCodes() { let text = "\u{001B}[36mhello\u{001B}[0m" - XCTAssertEqual(text.visibleLength, 5) + #expect(text.visibleLength == 5) } - func testVisibleLengthEmptyString() async throws { - XCTAssertEqual("".visibleLength, 0) + @Test func visibleLengthEmptyString() { + #expect("".visibleLength == 0) } - func testColorModeDraw() async throws { + @Test func colorModeDraw() throws { let config = try ProgressConfig( description: "Task", outputMode: .color @@ -1003,24 +995,24 @@ final class ProgressBarTests: XCTestCase { let stripped = output.replacingOccurrences( of: "\u{001B}\\[[0-9;]*[a-zA-Z]", with: "", options: .regularExpression ) - XCTAssertEqual(stripped, "⠋ Task [0s]") + #expect(stripped == "⠋ Task [0s]") } - func testColorModeDrawContainsAnsiCodes() async throws { + @Test func colorModeDrawContainsAnsiCodes() throws { let config = try ProgressConfig( description: "Task", outputMode: .color ) let progress = ProgressBar(config: config) let output = progress.draw() - XCTAssertTrue(output.contains("\u{001B}[")) - XCTAssertTrue(output.contains(EscapeSequence.cyan)) // spinner - XCTAssertTrue(output.contains(EscapeSequence.bold)) // description - XCTAssertTrue(output.contains(EscapeSequence.dim)) // time - XCTAssertTrue(output.contains(EscapeSequence.reset)) // reset + #expect(output.contains("\u{001B}[")) + #expect(output.contains(EscapeSequence.cyan)) // spinner + #expect(output.contains(EscapeSequence.bold)) // description + #expect(output.contains(EscapeSequence.dim)) // time + #expect(output.contains(EscapeSequence.reset)) // reset } - func testColorModeDrawFinished() async throws { + @Test func colorModeDrawFinished() throws { let config = try ProgressConfig( description: "Task", outputMode: .color @@ -1031,11 +1023,11 @@ final class ProgressBarTests: XCTestCase { let stripped = output.replacingOccurrences( of: "\u{001B}\\[[0-9;]*[a-zA-Z]", with: "", options: .regularExpression ) - XCTAssertEqual(stripped, "✔ Task [0s]") - XCTAssertTrue(output.contains(EscapeSequence.green)) // done icon + #expect(stripped == "✔ Task [0s]") + #expect(output.contains(EscapeSequence.green)) // done icon } - func testColorModeDrawWithTasks() async throws { + @Test func colorModeDrawWithTasks() throws { let config = try ProgressConfig( description: "Task", showTasks: true, @@ -1047,11 +1039,11 @@ final class ProgressBarTests: XCTestCase { let stripped = output.replacingOccurrences( of: "\u{001B}\\[[0-9;]*[a-zA-Z]", with: "", options: .regularExpression ) - XCTAssertEqual(stripped, "⠋ [0/2] Task [0s]") - XCTAssertTrue(output.contains(EscapeSequence.cyan)) // tasks + #expect(stripped == "⠋ [0/2] Task [0s]") + #expect(output.contains(EscapeSequence.cyan)) // tasks } - func testColorModeDrawWithPercent() async throws { + @Test func colorModeDrawWithPercent() throws { let config = try ProgressConfig( description: "Task", showItems: true, @@ -1064,11 +1056,11 @@ final class ProgressBarTests: XCTestCase { let stripped = output.replacingOccurrences( of: "\u{001B}\\[[0-9;]*[a-zA-Z]", with: "", options: .regularExpression ) - XCTAssertEqual(stripped, "⠋ Task 50% (1 of 2 it) [0s]") - XCTAssertTrue(output.contains(EscapeSequence.yellow)) // in-progress percent + #expect(stripped == "⠋ Task 50% (1 of 2 it) [0s]") + #expect(output.contains(EscapeSequence.yellow)) // in-progress percent } - func testColorModeDrawWithPercentFinished() async throws { + @Test func colorModeDrawWithPercentFinished() throws { let config = try ProgressConfig( description: "Task", showItems: true, @@ -1082,11 +1074,11 @@ final class ProgressBarTests: XCTestCase { let stripped = output.replacingOccurrences( of: "\u{001B}\\[[0-9;]*[a-zA-Z]", with: "", options: .regularExpression ) - XCTAssertEqual(stripped, "✔ Task 100% (2 it) [0s]") - XCTAssertTrue(output.contains(EscapeSequence.green)) // finished percent + #expect(stripped == "✔ Task 100% (2 it) [0s]") + #expect(output.contains(EscapeSequence.green)) // finished percent } - func testColorModeDrawWithSize() async throws { + @Test func colorModeDrawWithSize() throws { let config = try ProgressConfig( description: "Task", showSize: true, @@ -1100,11 +1092,11 @@ final class ProgressBarTests: XCTestCase { let stripped = output.replacingOccurrences( of: "\u{001B}\\[[0-9;]*[a-zA-Z]", with: "", options: .regularExpression ) - XCTAssertEqual(stripped, "⠋ Task 50% (2/4 bytes) [0s]") - XCTAssertTrue(output.contains(EscapeSequence.dim)) // parens content + #expect(stripped == "⠋ Task 50% (2/4 bytes) [0s]") + #expect(output.contains(EscapeSequence.dim)) // parens content } - func testColorModeDrawVisibleLengthMatchesContent() async throws { + @Test func colorModeDrawVisibleLengthMatchesContent() throws { let config = try ProgressConfig( description: "Task", showTasks: true, @@ -1128,10 +1120,10 @@ final class ProgressBarTests: XCTestCase { plainProgress.set(items: 2) let plainOutput = plainProgress.draw() - XCTAssertEqual(colorOutput.visibleLength, plainOutput.count) + #expect(colorOutput.visibleLength == plainOutput.count) } - func testColorModeNoAnsiCodesInContent() async throws { + @Test func colorModeNoAnsiCodesInContent() throws { let config = try ProgressConfig( description: "Task", outputMode: .color @@ -1141,10 +1133,10 @@ final class ProgressBarTests: XCTestCase { let stripped = output.replacingOccurrences( of: "\u{001B}\\[[0-9;]*[a-zA-Z]", with: "", options: .regularExpression ) - XCTAssertFalse(stripped.contains("\u{001B}")) + #expect(!stripped.contains("\u{001B}")) } - func testColorModeDrawWithProgressBar() async throws { + @Test func colorModeDrawWithProgressBar() throws { let config = try ProgressConfig( description: "Task", showProgressBar: true, @@ -1158,11 +1150,11 @@ final class ProgressBarTests: XCTestCase { let stripped = output.replacingOccurrences( of: "\u{001B}\\[[0-9;]*[a-zA-Z]", with: "", options: .regularExpression ) - XCTAssertEqual(stripped, "Task 50% |██ | [0s]") - XCTAssertTrue(output.contains(EscapeSequence.green)) + #expect(stripped == "Task 50% |██ | [0s]") + #expect(output.contains(EscapeSequence.green)) } - func testColorModeRequiresTTY() async throws { + @Test func colorModeRequiresTTY() throws { let pipe = Pipe() let config = try ProgressConfig( terminal: pipe.fileHandleForWriting, @@ -1176,10 +1168,10 @@ final class ProgressBarTests: XCTestCase { try pipe.fileHandleForWriting.close() let data = pipe.fileHandleForReading.readDataToEndOfFile() - XCTAssertTrue(data.isEmpty) + #expect(data.isEmpty) } - func testColorModeDrawOutputContainsColorCodes() async throws { + @Test func colorModeDrawOutputContainsColorCodes() throws { // Verify draw() includes ANSI codes even without a TTY // (draw is separate from terminal rendering) let config = try ProgressConfig( @@ -1188,13 +1180,13 @@ final class ProgressBarTests: XCTestCase { ) let progress = ProgressBar(config: config) let output = progress.draw() - XCTAssertTrue(output.contains(EscapeSequence.cyan)) - XCTAssertTrue(output.contains(EscapeSequence.bold)) - XCTAssertTrue(output.contains(EscapeSequence.dim)) - XCTAssertTrue(output.contains(EscapeSequence.reset)) + #expect(output.contains(EscapeSequence.cyan)) + #expect(output.contains(EscapeSequence.bold)) + #expect(output.contains(EscapeSequence.dim)) + #expect(output.contains(EscapeSequence.reset)) } - func testColorModeRenderTerminatorIsCarriageReturn() async throws { + @Test func colorModeRenderTerminatorIsCarriageReturn() throws { // Color mode is TTY-only so we cannot capture its raw terminal output via a pipe. // Instead, verify that plain mode emits \n (newlines) while color mode shares the // ansi code path which emits \r (carriage returns). We confirm this by checking @@ -1215,20 +1207,20 @@ final class ProgressBarTests: XCTestCase { let plainData = plainPipe.fileHandleForReading.readDataToEndOfFile() let plainOutput = String(decoding: plainData, as: UTF8.self) // Plain mode uses \n terminators - XCTAssertTrue(plainOutput.contains("\n")) - XCTAssertFalse(plainOutput.contains("\r")) + #expect(plainOutput.contains("\n")) + #expect(!plainOutput.contains("\r")) // Color mode follows the ansi path (not plain), so it uses \r let colorConfig = try ProgressConfig( description: "Task", outputMode: .color ) - XCTAssertNotEqual(colorConfig.outputMode, .plain) + #expect(colorConfig.outputMode != .plain) } - func testOutputModeDefaultIsNotColor() async throws { + @Test func outputModeDefaultIsNotColor() throws { let config = try ProgressConfig(description: "Task") - XCTAssertNotEqual(config.outputMode, .color) - XCTAssertEqual(config.outputMode, .ansi) + #expect(config.outputMode != .color) + #expect(config.outputMode == .ansi) } }