11use super :: { flags:: Flags , ChangeIdWrapper , Config } ;
22use crate :: core:: config:: { LldMode , TomlConfig } ;
3+ use crate :: core:: build_steps:: check:: get_clippy_rules_in_order;
34
45use clap:: CommandFactory ;
56use serde:: Deserialize ;
@@ -11,12 +12,13 @@ use std::{
1112} ;
1213
1314fn parse ( config : & str ) -> Config {
14- let config = format ! ( "{config} \r \n build.rustc = \" /does-not-exists\" " ) ;
1515 Config :: parse_inner (
1616 & [
17- "check" . to_owned ( ) ,
18- "--config=/does/not/exist" . to_owned ( ) ,
19- "--skip-stage0-validation" . to_owned ( ) ,
17+ "check" . to_string ( ) ,
18+ "--set=build.rustc=/does/not/exist" . to_string ( ) ,
19+ "--set=build.cargo=/does/not/exist" . to_string ( ) ,
20+ "--config=/does/not/exist" . to_string ( ) ,
21+ "--skip-stage0-validation" . to_string ( ) ,
2022 ] ,
2123 |& _| toml:: from_str ( & config) . unwrap ( ) ,
2224 )
@@ -169,7 +171,10 @@ fn override_toml_duplicate() {
169171 Config :: parse_inner (
170172 & [
171173 "check" . to_owned ( ) ,
174+ "--set=build.rustc=/does/not/exist" . to_string ( ) ,
175+ "--set=build.cargo=/does/not/exist" . to_string ( ) ,
172176 "--config=/does/not/exist" . to_owned ( ) ,
177+ "--skip-stage0-validation" . to_owned ( ) ,
173178 "--set=change-id=1" . to_owned ( ) ,
174179 "--set=change-id=2" . to_owned ( ) ,
175180 ] ,
@@ -192,7 +197,15 @@ fn profile_user_dist() {
192197 . and_then ( |table : toml:: Value | TomlConfig :: deserialize ( table) )
193198 . unwrap ( )
194199 }
195- Config :: parse_inner ( & [ "check" . to_owned ( ) ] , get_toml) ;
200+ Config :: parse_inner (
201+ & [
202+ "check" . to_owned ( ) ,
203+ "--set=build.rustc=/does/not/exist" . to_string ( ) ,
204+ "--set=build.cargo=/does/not/exist" . to_string ( ) ,
205+ "--skip-stage0-validation" . to_string ( ) ,
206+ ] ,
207+ get_toml,
208+ ) ;
196209}
197210
198211#[ test]
@@ -254,3 +267,34 @@ fn parse_change_id_with_unknown_field() {
254267 let change_id_wrapper: ChangeIdWrapper = toml:: from_str ( config) . unwrap ( ) ;
255268 assert_eq ! ( change_id_wrapper. inner, Some ( 3461 ) ) ;
256269}
270+
271+ #[ test]
272+ fn order_of_clippy_rules ( ) {
273+ let args = vec ! [
274+ "clippy" . to_string( ) ,
275+ "--fix" . to_string( ) ,
276+ "--allow-dirty" . to_string( ) ,
277+ "--allow-staged" . to_string( ) ,
278+ "-Aclippy:all" . to_string( ) ,
279+ "-Wclippy::style" . to_string( ) ,
280+ "-Aclippy::foo1" . to_string( ) ,
281+ "-Aclippy::foo2" . to_string( ) ,
282+ ] ;
283+ let config = Config :: parse ( & args) ;
284+
285+ let actual = match & config. cmd {
286+ crate :: Subcommand :: Clippy { allow, deny, warn, forbid, .. } => {
287+ get_clippy_rules_in_order ( & args, & allow, & deny, & warn, & forbid)
288+ }
289+ _ => panic ! ( "invalid subcommand" ) ,
290+ } ;
291+
292+ let expected = vec ! [
293+ "-Aclippy:all" . to_string( ) ,
294+ "-Wclippy::style" . to_string( ) ,
295+ "-Aclippy::foo1" . to_string( ) ,
296+ "-Aclippy::foo2" . to_string( ) ,
297+ ] ;
298+
299+ assert_eq ! ( expected, actual) ;
300+ }
0 commit comments