cargo/tests/testsuite/progress.rs
Ed Page 955faa1975 test(progress): Resolve flakiness
This is a follow up to #14181 which broke CI in #14221

```
---- progress::always_shows_progress stdout ----
running `/Users/runner/work/cargo/cargo/target/debug/cargo check`
thread 'progress::always_shows_progress' panicked at tests/testsuite/progress.rs:128:10:

---- expected: tests/testsuite/progress.rs:116:13
++++ actual:   stderr
   1    1 | [DOWNLOADING] 1 crate                                                                              
   2    2 | [DOWNLOADING] 2 crates                                                                             
   3    3 | [DOWNLOADING] 3 crates                                                                             
   4    4 | [DOWNLOADED] 3 crates ([..]KB) in [..]s
   5      - [BUILDING] [..] 0/4: [..]
   6    5 | [BUILDING] [..] 3/4: foo                                             
   7    6 | [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
   8    7 | ...∅

Update with SNAPSHOTS=overwrite
```
2024-07-09 15:38:44 -05:00

169 lines
3.8 KiB
Rust

//! Tests for progress bar.
use cargo_test_support::prelude::*;
use cargo_test_support::project;
use cargo_test_support::registry::Package;
use cargo_test_support::str;
#[cargo_test]
fn bad_progress_config_unknown_when() {
let p = project()
.file(
".cargo/config.toml",
r#"
[term]
progress = { when = 'unknown' }
"#,
)
.file("src/lib.rs", "")
.build();
p.cargo("check")
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] error in [ROOT]/foo/.cargo/config.toml: could not load config key `term.progress.when`
Caused by:
unknown variant `unknown`, expected one of `auto`, `never`, `always`
"#]])
.run();
}
#[cargo_test]
fn bad_progress_config_missing_width() {
let p = project()
.file(
".cargo/config.toml",
r#"
[term]
progress = { when = 'always' }
"#,
)
.file("src/lib.rs", "")
.build();
p.cargo("check")
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] "always" progress requires a `width` key
"#]])
.run();
}
#[cargo_test]
fn bad_progress_config_missing_when() {
let p = project()
.file(
".cargo/config.toml",
r#"
[term]
progress = { width = 1000 }
"#,
)
.file("src/lib.rs", "")
.build();
p.cargo("check")
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] error in [ROOT]/foo/.cargo/config.toml: could not load config key `term.progress`
Caused by:
missing field `when`
"#]])
.run();
}
#[cargo_test]
fn always_shows_progress() {
const N: usize = 3;
let mut deps = String::new();
for i in 1..=N {
Package::new(&format!("dep{}", i), "1.0.0").publish();
deps.push_str(&format!("dep{} = \"1.0\"\n", i));
}
let p = project()
.file(
".cargo/config.toml",
r#"
[term]
progress = { when = 'always', width = 100 }
"#,
)
.file(
"Cargo.toml",
&format!(
r#"
[package]
name = "foo"
version = "0.1.0"
[dependencies]
{}
"#,
deps
),
)
.file("src/lib.rs", "")
.build();
p.cargo("check")
.with_stderr_data(
str![[r#"
[DOWNLOADING] [..] crate
[DOWNLOADED] 3 crates ([..]KB) in [..]s
[BUILDING] [..] [..]/4: [..]
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
...
"#]]
.unordered(),
)
.run();
}
#[allow(deprecated)]
#[cargo_test]
fn never_progress() {
const N: usize = 3;
let mut deps = String::new();
for i in 1..=N {
Package::new(&format!("dep{}", i), "1.0.0").publish();
deps.push_str(&format!("dep{} = \"1.0\"\n", i));
}
let p = project()
.file(
".cargo/config.toml",
r#"
[term]
progress = { when = 'never' }
"#,
)
.file(
"Cargo.toml",
&format!(
r#"
[package]
name = "foo"
version = "0.1.0"
[dependencies]
{}
"#,
deps
),
)
.file("src/lib.rs", "")
.build();
p.cargo("check")
.with_stderr_does_not_contain("[DOWNLOADING] [..] crates [..]")
.with_stderr_does_not_contain("[..][DOWNLOADED] 3 crates ([..]) in [..]")
.with_stderr_does_not_contain("[BUILDING] [..] [..]/4: [..]")
.run();
}