sagiegurari / cargo-make
1
use super::*;
2
use crate::test;
3
use crate::types::Task;
4
use std::io::ErrorKind;
5

6
#[test]
7
#[should_panic]
8 8
fn validate_exit_code_unable_to_fetch() {
9 8
    validate_exit_code(-1);
10 0
}
11

12
#[test]
13
#[should_panic]
14 8
fn validate_exit_code_not_zero() {
15 8
    validate_exit_code(1);
16 0
}
17

18
#[test]
19 8
fn validate_exit_code_zero() {
20 8
    validate_exit_code(0);
21 8
}
22

23
#[test]
24
#[should_panic]
25 8
fn get_exit_code_error() {
26 8
    test::on_test_startup();
27

28 8
    get_exit_code(Err(Error::new(ErrorKind::Other, "test")), false);
29 0
}
30

31
#[test]
32 8
fn is_silent_for_level_error() {
33 8
    let silent = is_silent_for_level("error".to_string());
34 8
    assert!(silent);
35 8
}
36

37
#[test]
38 8
fn is_silent_for_level_info() {
39 8
    let silent = is_silent_for_level("info".to_string());
40 8
    assert!(!silent);
41 8
}
42

43
#[test]
44 8
fn is_silent_for_level_verbose() {
45 8
    let silent = is_silent_for_level("verbose".to_string());
46 8
    assert!(!silent);
47 8
}
48

49
#[test]
50 8
fn is_silent_for_level_other() {
51 8
    let silent = is_silent_for_level("test".to_string());
52 8
    assert!(!silent);
53 8
}
54

55
#[test]
56 8
fn should_print_commands_for_level_error() {
57 8
    let print_commands = should_print_commands_for_level("error".to_string());
58 8
    assert!(!print_commands)
59 8
}
60

61
#[test]
62 8
fn should_print_commands_for_level_info() {
63 8
    let print_commands = should_print_commands_for_level("info".to_string());
64 8
    assert!(!print_commands)
65 8
}
66

67
#[test]
68 8
fn should_print_commands_for_level_verbose() {
69 8
    let print_commands = should_print_commands_for_level("verbose".to_string());
70 8
    assert!(print_commands);
71 8
}
72

73
#[test]
74 8
fn should_print_commands_for_level_other() {
75 8
    let print_commands = should_print_commands_for_level("test".to_string());
76 8
    assert!(!print_commands)
77 8
}
78

79
#[test]
80 8
fn run_no_command() {
81 8
    let task = Task::new();
82

83 8
    let step = Step {
84 8
        name: "test".to_string(),
85 8
        config: task,
86
    };
87

88 8
    run(&step);
89 8
}
90

91
#[test]
92 8
fn run_command() {
93 8
    let mut task = Task::new();
94 8
    task.command = Some("echo".to_string());
95 8
    task.args = Some(vec!["test".to_string()]);
96

97 8
    let step = Step {
98 8
        name: "test_command_output_env".to_string(),
99 8
        config: task,
100
    };
101

102 8
    run(&step);
103 8
}
104

105
#[test]
106 8
fn run_command_for_toolchain() {
107 8
    if test::is_not_rust_stable() {
108 4
        let toolchain = test::get_toolchain();
109

110 4
        let mut task = Task::new();
111 4
        task.command = Some("echo".to_string());
112 4
        task.args = Some(vec!["test".to_string()]);
113 4
        task.toolchain = Some(toolchain.to_string());
114

115 4
        let step = Step {
116 4
            name: "test".to_string(),
117 4
            config: task,
118
        };
119

120 4
        run(&step);
121 4
    }
122 8
}
123

124
#[test]
125
#[should_panic]
126 8
fn run_command_error() {
127 8
    test::on_test_startup();
128

129 8
    let mut task = Task::new();
130 8
    task.command = Some("badbadbad".to_string());
131

132 8
    let step = Step {
133 8
        name: "test".to_string(),
134 8
        config: task,
135
    };
136

137 8
    run(&step);
138 0
}
139

140
#[test]
141 8
fn run_command_error_ignore_errors() {
142 8
    let mut task = Task::new();
143 8
    task.ignore_errors = Some(true);
144 8
    task.command = Some("badbadbad".to_string());
145

146 8
    let step = Step {
147 8
        name: "test".to_string(),
148 8
        config: task,
149
    };
150

151 8
    run(&step);
152 8
}
153

154
#[test]
155 8
fn run_script_get_exit_code_valid() {
156 8
    run_script_get_exit_code(&vec!["echo 1".to_string()], None, &vec![], true);
157 8
}
158

159
#[test]
160
#[should_panic]
161 8
fn run_script_get_exit_code_error() {
162 8
    run_script_get_exit_code(&vec!["exit 1".to_string()], None, &vec![], true);
163 0
}
164

165
#[test]
166 8
fn run_script_get_exit_code_error_force() {
167 8
    run_script_get_exit_code(&vec!["exit 1".to_string()], None, &vec![], false);
168 8
}
169

170
#[test]
171
#[cfg(target_os = "linux")]
172 8
fn run_script_get_exit_code_custom_runner() {
173 8
    run_script_get_exit_code(
174 8
        &vec!["echo test".to_string()],
175 8
        Some("bash".to_string()),
176 8
        &vec![],
177
        true,
178 6
    );
179 8
}
180

181
#[test]
182
#[cfg(target_os = "linux")]
183 8
fn run_script_get_exit_code_cli_args_valid() {
184 8
    run_script_get_exit_code(
185 8
        &vec!["exit $1".to_string()],
186 8
        None,
187 8
        &vec!["0".to_string()],
188
        true,
189 2
    );
190 8
}
191

192
#[test]
193
#[should_panic]
194
#[cfg(target_os = "linux")]
195 8
fn run_script_get_exit_code_cli_args_error() {
196 8
    run_script_get_exit_code(
197 8
        &vec!["exit $1".to_string()],
198 8
        None,
199 8
        &vec!["1".to_string()],
200
        true,
201 8
    );
202 0
}

Read our documentation on viewing source code .

Loading