Skip to content

Commit 06daaac

Browse files
committed
add integration test for progress auto fallback
1 parent 23d0519 commit 06daaac

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//===----------------------------------------------------------------------===//
2+
// Copyright © 2026 Apple Inc. and the container project authors.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// https://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//===----------------------------------------------------------------------===//
16+
17+
import Foundation
18+
import Testing
19+
20+
class TestCLIProgressAuto: CLITest {
21+
/// When stderr is not a TTY (piped), --progress auto should produce
22+
/// plain-text status lines on stderr instead of silence.
23+
@Test func testAutoProgressFallsBackToPlainWhenPiped() throws {
24+
do {
25+
// run() uses Pipe for stderr, so the subprocess sees a non-TTY
26+
let (_, _, error, status) = try run(arguments: [
27+
"image", "pull",
28+
"--progress", "auto",
29+
alpine,
30+
])
31+
#expect(status == 0, "image pull should succeed, stderr: \(error)")
32+
// stderr should contain progress text (not be empty, ignoring the debug warning)
33+
let lines = error.components(separatedBy: .newlines)
34+
.filter { !$0.contains("Warning! Running debug build") && !$0.isEmpty }
35+
#expect(!lines.isEmpty, "expected plain progress output on stderr when piped")
36+
// should NOT contain ANSI escape sequences
37+
#expect(!error.contains("\u{1B}["), "expected no ANSI escapes in piped output")
38+
} catch {
39+
Issue.record("failed to test auto progress: \(error)")
40+
return
41+
}
42+
}
43+
44+
/// Explicit --progress plain should also produce plain output on stderr.
45+
@Test func testExplicitPlainProgress() throws {
46+
do {
47+
let (_, _, error, status) = try run(arguments: [
48+
"image", "pull",
49+
"--progress", "plain",
50+
alpine,
51+
])
52+
#expect(status == 0, "image pull --progress plain should succeed, stderr: \(error)")
53+
let lines = error.components(separatedBy: .newlines)
54+
.filter { !$0.contains("Warning! Running debug build") && !$0.isEmpty }
55+
#expect(!lines.isEmpty, "expected plain progress output on stderr")
56+
#expect(!error.contains("\u{1B}["), "expected no ANSI escapes with --progress plain")
57+
} catch {
58+
Issue.record("failed to test plain progress: \(error)")
59+
return
60+
}
61+
}
62+
63+
/// --progress none should produce no progress output on stderr.
64+
@Test func testNoneProgressSuppressesOutput() throws {
65+
do {
66+
let (_, _, error, status) = try run(arguments: [
67+
"image", "pull",
68+
"--progress", "none",
69+
alpine,
70+
])
71+
#expect(status == 0, "image pull --progress none should succeed, stderr: \(error)")
72+
let lines = error.components(separatedBy: .newlines)
73+
.filter { !$0.contains("Warning! Running debug build") && !$0.isEmpty }
74+
#expect(lines.isEmpty, "expected no progress output on stderr with --progress none")
75+
} catch {
76+
Issue.record("failed to test none progress: \(error)")
77+
return
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)