Skip to content

Commit 848e474

Browse files
committed
add unit test: order_of_clippy_rules
Signed-off-by: onur-ozkan <[email protected]>
1 parent 57135bf commit 848e474

File tree

1 file changed

+52
-6
lines changed

1 file changed

+52
-6
lines changed

src/bootstrap/src/core/config/tests.rs

+52-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use super::{flags::Flags, Config};
2-
use crate::core::config::{LldMode, TomlConfig};
2+
use crate::core::{
3+
build_steps::check::get_clippy_rules_in_order,
4+
config::{LldMode, TomlConfig},
5+
};
36

47
use clap::CommandFactory;
58
use serde::Deserialize;
@@ -11,12 +14,13 @@ use std::{
1114
};
1215

1316
fn parse(config: &str) -> Config {
14-
let config = format!("{config} \r\n build.rustc = \"/does-not-exists\" ");
1517
Config::parse_inner(
1618
&[
17-
"check".to_owned(),
18-
"--config=/does/not/exist".to_owned(),
19-
"--skip-stage0-validation".to_owned(),
19+
"check".to_string(),
20+
"--set=build.rustc=/does/not/exist".to_string(),
21+
"--set=build.cargo=/does/not/exist".to_string(),
22+
"--config=/does/not/exist".to_string(),
23+
"--skip-stage0-validation".to_string(),
2024
],
2125
|&_| toml::from_str(&config).unwrap(),
2226
)
@@ -169,7 +173,10 @@ fn override_toml_duplicate() {
169173
Config::parse_inner(
170174
&[
171175
"check".to_owned(),
176+
"--set=build.rustc=/does/not/exist".to_string(),
177+
"--set=build.cargo=/does/not/exist".to_string(),
172178
"--config=/does/not/exist".to_owned(),
179+
"--skip-stage0-validation".to_owned(),
173180
"--set=change-id=1".to_owned(),
174181
"--set=change-id=2".to_owned(),
175182
],
@@ -192,7 +199,15 @@ fn profile_user_dist() {
192199
.and_then(|table: toml::Value| TomlConfig::deserialize(table))
193200
.unwrap()
194201
}
195-
Config::parse_inner(&["check".to_owned()], get_toml);
202+
Config::parse_inner(
203+
&[
204+
"check".to_owned(),
205+
"--set=build.rustc=/does/not/exist".to_string(),
206+
"--set=build.cargo=/does/not/exist".to_string(),
207+
"--skip-stage0-validation".to_string(),
208+
],
209+
get_toml,
210+
);
196211
}
197212

198213
#[test]
@@ -237,3 +252,34 @@ fn rust_lld() {
237252
assert!(matches!(parse("rust.use-lld = true").lld_mode, LldMode::External));
238253
assert!(matches!(parse("rust.use-lld = false").lld_mode, LldMode::Unused));
239254
}
255+
256+
#[test]
257+
fn order_of_clippy_rules() {
258+
let args = vec![
259+
"clippy".to_string(),
260+
"--fix".to_string(),
261+
"--allow-dirty".to_string(),
262+
"--allow-staged".to_string(),
263+
"-Aclippy:all".to_string(),
264+
"-Wclippy::style".to_string(),
265+
"-Aclippy::foo1".to_string(),
266+
"-Aclippy::foo2".to_string(),
267+
];
268+
let config = Config::parse(&args);
269+
270+
let actual = match &config.cmd {
271+
crate::Subcommand::Clippy { allow, deny, warn, forbid, .. } => {
272+
get_clippy_rules_in_order(&args, &allow, &deny, &warn, &forbid)
273+
}
274+
_ => panic!("invalid subcommand"),
275+
};
276+
277+
let expected = vec![
278+
"-Aclippy:all".to_string(),
279+
"-Wclippy::style".to_string(),
280+
"-Aclippy::foo1".to_string(),
281+
"-Aclippy::foo2".to_string(),
282+
];
283+
284+
assert_eq!(expected, actual);
285+
}

0 commit comments

Comments
 (0)