File: progress.rs

package info (click to toggle)
rust-cargo 0.91.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 16,860 kB
  • sloc: javascript: 426; sh: 315; python: 88; xml: 21; makefile: 6
file content (158 lines) | stat: -rw-r--r-- 3,567 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//! Tests for progress bar.

use crate::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 default_progress_is_auto() {
    let p = project()
        .file(
            ".cargo/config.toml",
            r#"
            [term]
            progress = { width = 1000 }
            "#,
        )
        .file("src/lib.rs", "")
        .build();

    p.cargo("check").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 ([..]) in [..]s
[BUILDING] [..] [..]/4: [..]
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
...
"#]]
            .unordered(),
        )
        .run();
}

#[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();
}