|
| 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 | + @Test func testAutoProgressFallsBackToPlainWhenPiped() throws { |
| 22 | + let (_, _, error, status) = try run(arguments: [ |
| 23 | + "image", "pull", |
| 24 | + "--progress", "auto", |
| 25 | + alpine, |
| 26 | + ]) |
| 27 | + #expect(status == 0, "image pull should succeed, stderr: \(error)") |
| 28 | + let lines = error.components(separatedBy: .newlines) |
| 29 | + .filter { !$0.contains("Warning! Running debug build") && !$0.isEmpty } |
| 30 | + #expect(!lines.isEmpty, "expected plain progress output on stderr when piped") |
| 31 | + #expect(!error.contains("\u{1B}["), "expected no ANSI escapes in piped output") |
| 32 | + } |
| 33 | + |
| 34 | + @Test func testExplicitPlainProgress() throws { |
| 35 | + let (_, _, error, status) = try run(arguments: [ |
| 36 | + "image", "pull", |
| 37 | + "--progress", "plain", |
| 38 | + alpine, |
| 39 | + ]) |
| 40 | + #expect(status == 0, "image pull --progress plain should succeed, stderr: \(error)") |
| 41 | + let lines = error.components(separatedBy: .newlines) |
| 42 | + .filter { !$0.contains("Warning! Running debug build") && !$0.isEmpty } |
| 43 | + #expect(!lines.isEmpty, "expected plain progress output on stderr") |
| 44 | + #expect(!error.contains("\u{1B}["), "expected no ANSI escapes with --progress plain") |
| 45 | + } |
| 46 | + |
| 47 | + @Test func testExplicitAnsiProgress() throws { |
| 48 | + let (_, _, error, status) = try run(arguments: [ |
| 49 | + "image", "pull", |
| 50 | + "--progress", "ansi", |
| 51 | + alpine, |
| 52 | + ]) |
| 53 | + #expect(status == 0, "image pull --progress ansi should succeed, stderr: \(error)") |
| 54 | + let lines = error.components(separatedBy: .newlines) |
| 55 | + .filter { !$0.contains("Warning! Running debug build") && !$0.isEmpty } |
| 56 | + #expect(!lines.isEmpty, "expected ansi progress output on stderr") |
| 57 | + } |
| 58 | + |
| 59 | + @Test func testNoneProgressSuppressesOutput() throws { |
| 60 | + let (_, _, error, status) = try run(arguments: [ |
| 61 | + "image", "pull", |
| 62 | + "--progress", "none", |
| 63 | + alpine, |
| 64 | + ]) |
| 65 | + #expect(status == 0, "image pull --progress none should succeed, stderr: \(error)") |
| 66 | + let lines = error.components(separatedBy: .newlines) |
| 67 | + .filter { !$0.contains("Warning! Running debug build") && !$0.isEmpty } |
| 68 | + #expect(lines.isEmpty, "expected no progress output on stderr with --progress none") |
| 69 | + } |
| 70 | +} |
0 commit comments