Skip to content

Commit

Permalink
Merge pull request #1 from kattouf/workflows
Browse files Browse the repository at this point in the history
Add tests GitHub workflow
  • Loading branch information
kattouf authored Jul 17, 2024
2 parents 4a78fbe + 065c195 commit b88f03d
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 146 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Tests
on: [push]
jobs:
build:
name: Integration tests
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: swift-actions/setup-swift@v2
with:
swift-version: "5.10"
- name: Run tests
run: make test
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
## ProgressLine

[![Latest Release](https://img.shields.io/badge/Platform-macOS-6464aa)](https://img.shields.io/badge/Platform-macOS-6464aa)
[![Latest Release](https://img.shields.io/badge/Platform-Linux-6464aa)](https://img.shields.io/badge/Platform-Linux-6464aa)
![](https://img.shields.io/badge/Platform-macOS-6464aa)
![](https://img.shields.io/badge/Platform-Linux-6464aa)
[![Latest Release](https://img.shields.io/github/release/kattouf/ProgressLine.svg)](https://github.com/kattouf/ProgressLine/releases/latest)
![](https://github.com/kattouf/ProgressLine/actions/workflows/tests.yml/badge.svg?branch=main)

Track commands progress in a compact one-line format.

Expand Down
8 changes: 0 additions & 8 deletions Sources/ActivityIndicator+CommandArgument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,4 @@ extension ActivityIndicator {
.snake
}
}

#if DEBUG
static func test() -> ActivityIndicator {
.init(
configuration: .init(refreshRate: 1_000_000_000, states: ["<activity>"])
)
}
#endif
}
10 changes: 10 additions & 0 deletions Sources/ActivityIndicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,13 @@ extension ActivityIndicator {
return ActivityIndicator(configuration: configuration)
}()
}

#if DEBUG
extension ActivityIndicator {
static func disabled() -> ActivityIndicator {
.init(
configuration: .init(refreshRate: 1_000_000_000, states: [])
)
}
}
#endif
6 changes: 4 additions & 2 deletions Sources/ProgressLine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ struct ProgressLine: AsyncParsableCommand {
let logger = AboveProgressLineLogger(printers: printers)

#if DEBUG
let activityIndicator: ActivityIndicator = testMode ? .test() : .make(style: activityIndicatorStyle)
let activityIndicator: ActivityIndicator = testMode ? .disabled() : .make(style: activityIndicatorStyle)
#else
let testMode = false
let activityIndicator: ActivityIndicator = .make(style: activityIndicatorStyle)
#endif
let progressLineController = await ProgressLineController.buildAndStart(
printers: printers,
logger: logger,
activityIndicator: activityIndicator
activityIndicator: activityIndicator,
mockActivityAndDuration: testMode
)
let originalLogController = if let originalLogPath {
await OriginalLogController(logger: logger, path: originalLogPath)
Expand Down
6 changes: 4 additions & 2 deletions Sources/ProgressLineController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ final actor ProgressLineController {
static func buildAndStart(
printers: PrintersHolder,
logger: AboveProgressLineLogger,
activityIndicator: ActivityIndicator
activityIndicator: ActivityIndicator,
mockActivityAndDuration: Bool = false
) async -> Self {
let progressTracker = ProgressTracker.start()
let windowSizeObserver = WindowSizeObserver.startObserving()
let progressLineFormatter = ProgressLineFormatter(
activityIndicator: activityIndicator,
windowSizeObserver: windowSizeObserver
windowSizeObserver: windowSizeObserver,
mockActivityAndDuration: mockActivityAndDuration
)

let controller = Self(
Expand Down
11 changes: 7 additions & 4 deletions Sources/ProgressLineFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ final class ProgressLineFormatter: Sendable {

private let activityIndicator: ActivityIndicator
private let windowSizeObserver: WindowSizeObserver?
private let mockActivityAndDuration: Bool

init(
activityIndicator: ActivityIndicator,
windowSizeObserver: WindowSizeObserver?
windowSizeObserver: WindowSizeObserver?,
mockActivityAndDuration: Bool
) {
self.activityIndicator = activityIndicator
self.windowSizeObserver = windowSizeObserver
self.mockActivityAndDuration = mockActivityAndDuration
}

func inProgress(progress: Progress) -> String {
let activityIndicator = activityIndicator.state(forDuration: progress.duration)
let formattedDuration = formatDuration(from: progress.duration)
let activityIndicator = mockActivityAndDuration ? "<activity>" : activityIndicator.state(forDuration: progress.duration)
let formattedDuration = mockActivityAndDuration ? "<duration>" : formatDuration(from: progress.duration)

let styledActivityIndicator = ANSI.blue + activityIndicator + ANSI.reset
let styledDuration = ANSI.bold + formattedDuration + ANSI.reset
Expand All @@ -46,7 +49,7 @@ final class ProgressLineFormatter: Sendable {
}

func finished(progress: Progress?) -> String {
let formattedDuration = progress.map { formatDuration(from: $0.duration) }
let formattedDuration = mockActivityAndDuration ? "<duration>" : progress.map { formatDuration(from: $0.duration) }

let styledActivityIndicator = ANSI.green + Symbol.checkmark + ANSI.reset
let styledDuration = formattedDuration.map { ANSI.bold + $0 + ANSI.reset }
Expand Down
64 changes: 32 additions & 32 deletions snapshots/default.snapshot
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
<activity> 0s
<activity> 0s ❯ Chunk number: 1, Chunk Line: 3
<activity> 0s ❯ Chunk number: 2, Chunk Line: 3
<activity> 0s ❯ Chunk number: 3, Chunk Line: 3
<activity> 0s ❯ Chunk number: 4, Chunk Line: 3
<activity> 0s ❯ Chunk number: 5, Chunk Line: 3
<activity> 0s ❯ Chunk number: 6, Chunk Line: 3
<activity> 0s ❯ Chunk number: 7, Chunk Line: 3
<activity> 0s ❯ Chunk number: 8, Chunk Line: 3
<activity> 0s ❯ Chunk number: 9, Chunk Line: 3
<activity> 0s ❯ Chunk number: 10, Chunk Line: 3
<activity> 0s ❯ Chunk number: 11, Chunk Line: 3
<activity> 0s ❯ Chunk number: 12, Chunk Line: 3
<activity> 0s ❯ Chunk number: 13, Chunk Line: 3
<activity> 0s ❯ Chunk number: 14, Chunk Line: 3
<activity> 0s ❯ Chunk number: 15, Chunk Line: 3
<activity> 0s ❯ Chunk number: 16, Chunk Line: 3
<activity> 0s ❯ Chunk number: 17, Chunk Line: 3
<activity> 0s ❯ Chunk number: 18, Chunk Line: 3
<activity> 0s ❯ Chunk number: 19, Chunk Line: 3
<activity> 0s ❯ Chunk number: 20, Chunk Line: 3
<activity> 0s ❯ Chunk number: 21, Chunk Line: 3
<activity> 0s ❯ Chunk number: 22, Chunk Line: 3
<activity> 0s ❯ Chunk number: 23, Chunk Line: 3
<activity> 0s ❯ Chunk number: 24, Chunk Line: 3
<activity> 0s ❯ Chunk number: 25, Chunk Line: 3
<activity> 0s ❯ Chunk number: 26, Chunk Line: 3
<activity> 0s ❯ Chunk number: 27, Chunk Line: 3
<activity> 0s ❯ Chunk number: 28, Chunk Line: 3
<activity> 0s ❯ Chunk number: 29, Chunk Line: 3
<activity> 0s ❯ Chunk number: 30, Chunk Line: 3
✓ 0s ❯ Chunk number: 30, Chunk Line: 3
<activity> <duration>
<activity> <duration> ❯ Chunk number: 1, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 2, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 3, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 4, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 5, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 6, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 7, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 8, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 9, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 10, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 11, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 12, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 13, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 14, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 15, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 16, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 17, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 18, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 19, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 20, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 21, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 22, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 23, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 24, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 25, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 26, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 27, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 28, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 29, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 30, Chunk Line: 3
✓ <duration> ❯ Chunk number: 30, Chunk Line: 3
64 changes: 32 additions & 32 deletions snapshots/default_with_original_log.snapshot
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
<activity> 0s
<activity> 0s ❯ Chunk number: 1, Chunk Line: 3
<activity> 0s ❯ Chunk number: 2, Chunk Line: 3
<activity> 0s ❯ Chunk number: 3, Chunk Line: 3
<activity> 0s ❯ Chunk number: 4, Chunk Line: 3
<activity> 0s ❯ Chunk number: 5, Chunk Line: 3
<activity> 0s ❯ Chunk number: 6, Chunk Line: 3
<activity> 0s ❯ Chunk number: 7, Chunk Line: 3
<activity> 0s ❯ Chunk number: 8, Chunk Line: 3
<activity> 0s ❯ Chunk number: 9, Chunk Line: 3
<activity> 0s ❯ Chunk number: 10, Chunk Line: 3
<activity> 0s ❯ Chunk number: 11, Chunk Line: 3
<activity> 0s ❯ Chunk number: 12, Chunk Line: 3
<activity> 0s ❯ Chunk number: 13, Chunk Line: 3
<activity> 0s ❯ Chunk number: 14, Chunk Line: 3
<activity> 0s ❯ Chunk number: 15, Chunk Line: 3
<activity> 0s ❯ Chunk number: 16, Chunk Line: 3
<activity> 0s ❯ Chunk number: 17, Chunk Line: 3
<activity> 0s ❯ Chunk number: 18, Chunk Line: 3
<activity> 0s ❯ Chunk number: 19, Chunk Line: 3
<activity> 0s ❯ Chunk number: 20, Chunk Line: 3
<activity> 0s ❯ Chunk number: 21, Chunk Line: 3
<activity> 0s ❯ Chunk number: 22, Chunk Line: 3
<activity> 0s ❯ Chunk number: 23, Chunk Line: 3
<activity> 0s ❯ Chunk number: 24, Chunk Line: 3
<activity> 0s ❯ Chunk number: 25, Chunk Line: 3
<activity> 0s ❯ Chunk number: 26, Chunk Line: 3
<activity> 0s ❯ Chunk number: 27, Chunk Line: 3
<activity> 0s ❯ Chunk number: 28, Chunk Line: 3
<activity> 0s ❯ Chunk number: 29, Chunk Line: 3
<activity> 0s ❯ Chunk number: 30, Chunk Line: 3
✓ 0s ❯ Chunk number: 30, Chunk Line: 3
<activity> <duration>
<activity> <duration> ❯ Chunk number: 1, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 2, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 3, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 4, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 5, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 6, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 7, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 8, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 9, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 10, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 11, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 12, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 13, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 14, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 15, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 16, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 17, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 18, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 19, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 20, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 21, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 22, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 23, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 24, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 25, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 26, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 27, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 28, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 29, Chunk Line: 3
<activity> <duration> ❯ Chunk number: 30, Chunk Line: 3
✓ <duration> ❯ Chunk number: 30, Chunk Line: 3
Loading

0 comments on commit b88f03d

Please sign in to comment.