ci-cargo

CI for Rust code.
git clone https://git.philomathiclife.com/repos/ci-cargo
Log | Files | Refs | README

tests.rs (27034B)


      1 use super::{
      2     ArgsErr, CheckClippyTargets, Cmd, Ignored, MetaCmd, NonZeroUsizePlus1, Opts, OsString, PathBuf,
      3     Target, Targets, TestTargets,
      4 };
      5 use core::iter;
      6 #[cfg(unix)]
      7 use std::os::unix::ffi::OsStringExt as _;
      8 #[expect(
      9     clippy::cognitive_complexity,
     10     clippy::too_many_lines,
     11     reason = "want to test for a lot of things"
     12 )]
     13 #[test]
     14 fn arg_parsing() {
     15     assert_eq!(MetaCmd::from_args(iter::empty()), Err(ArgsErr::NoArgs));
     16     assert_eq!(
     17         MetaCmd::from_args(iter::once(OsString::new())),
     18         Err(ArgsErr::NoCommand)
     19     );
     20     assert_eq!(
     21         MetaCmd::from_args([OsString::new(), OsString::new()].into_iter()),
     22         Err(ArgsErr::NoCommand)
     23     );
     24     // Invalid UTF-8 errors gracefully.
     25     #[cfg(unix)]
     26     assert_eq!(
     27         MetaCmd::from_args([OsString::new(), OsString::from_vec(vec![255])].into_iter()),
     28         Err(ArgsErr::UnknownArg(OsString::from_vec(vec![255])))
     29     );
     30     // Whitespace is not ignored.
     31     assert_eq!(
     32         MetaCmd::from_args([OsString::new(), " clippy".to_owned().into()].into_iter()),
     33         Err(ArgsErr::NoCommand)
     34     );
     35     // We parse in a case-sensitive way.
     36     assert_eq!(
     37         MetaCmd::from_args([OsString::new(), "Clippy".to_owned().into()].into_iter()),
     38         Err(ArgsErr::NoCommand)
     39     );
     40     // We require options to be after the command (if one was passed).
     41     assert_eq!(
     42         MetaCmd::from_args(
     43             [
     44                 OsString::new(),
     45                 "--summary".to_owned().into(),
     46                 "clippy".to_owned().into()
     47             ]
     48             .into_iter()
     49         ),
     50         Err(ArgsErr::NoCommand)
     51     );
     52     assert_eq!(
     53         MetaCmd::from_args(
     54             [
     55                 OsString::new(),
     56                 "help".to_owned().into(),
     57                 "--summary".to_owned().into()
     58             ]
     59             .into_iter()
     60         ),
     61         Err(ArgsErr::HelpWithArgs)
     62     );
     63     assert_eq!(
     64         MetaCmd::from_args(
     65             [
     66                 OsString::new(),
     67                 "version".to_owned().into(),
     68                 "foo".to_owned().into()
     69             ]
     70             .into_iter()
     71         ),
     72         Err(ArgsErr::VersionWithArgs)
     73     );
     74     assert_eq!(
     75         MetaCmd::from_args(
     76             [
     77                 OsString::new(),
     78                 "check".to_owned().into(),
     79                 "--cargo-path".to_owned().into()
     80             ]
     81             .into_iter()
     82         ),
     83         Err(ArgsErr::MissingCargoPath)
     84     );
     85     assert_eq!(
     86         MetaCmd::from_args(
     87             [
     88                 OsString::new(),
     89                 "check".to_owned().into(),
     90                 "--cargo-home".to_owned().into()
     91             ]
     92             .into_iter()
     93         ),
     94         Err(ArgsErr::MissingCargoHome)
     95     );
     96     assert_eq!(
     97         MetaCmd::from_args(
     98             [
     99                 OsString::new(),
    100                 "check".to_owned().into(),
    101                 "--rustup-home".to_owned().into()
    102             ]
    103             .into_iter()
    104         ),
    105         Err(ArgsErr::MissingRustupHome)
    106     );
    107     assert_eq!(
    108         MetaCmd::from_args(
    109             [
    110                 OsString::new(),
    111                 "test".to_owned().into(),
    112                 "--deny-warnings".to_owned().into()
    113             ]
    114             .into_iter()
    115         ),
    116         Err(ArgsErr::UnknownArg("--deny-warnings".to_owned().into()))
    117     );
    118     assert_eq!(
    119         MetaCmd::from_args(
    120             [
    121                 OsString::new(),
    122                 "check".to_owned().into(),
    123                 "--deny-warnings".to_owned().into()
    124             ]
    125             .into_iter()
    126         ),
    127         Err(ArgsErr::UnknownArg("--deny-warnings".to_owned().into()))
    128     );
    129     assert_eq!(
    130         MetaCmd::from_args(
    131             [
    132                 OsString::new(),
    133                 "clippy".to_owned().into(),
    134                 "--ignored".to_owned().into()
    135             ]
    136             .into_iter()
    137         ),
    138         Err(ArgsErr::UnknownArg("--ignored".to_owned().into()))
    139     );
    140     assert_eq!(
    141         MetaCmd::from_args(
    142             [
    143                 OsString::new(),
    144                 "check".to_owned().into(),
    145                 "--ignored".to_owned().into()
    146             ]
    147             .into_iter()
    148         ),
    149         Err(ArgsErr::UnknownArg("--ignored".to_owned().into()))
    150     );
    151     assert_eq!(
    152         MetaCmd::from_args(
    153             [
    154                 OsString::new(),
    155                 "clippy".to_owned().into(),
    156                 "--include-ignored".to_owned().into()
    157             ]
    158             .into_iter()
    159         ),
    160         Err(ArgsErr::UnknownArg("--include-ignored".to_owned().into()))
    161     );
    162     assert_eq!(
    163         MetaCmd::from_args(
    164             [
    165                 OsString::new(),
    166                 "check".to_owned().into(),
    167                 "--include-ignored".to_owned().into()
    168             ]
    169             .into_iter()
    170         ),
    171         Err(ArgsErr::UnknownArg("--include-ignored".to_owned().into()))
    172     );
    173     assert_eq!(
    174         MetaCmd::from_args(
    175             [
    176                 OsString::new(),
    177                 "test".to_owned().into(),
    178                 "--ignored".to_owned().into(),
    179                 "--include-ignored".to_owned().into()
    180             ]
    181             .into_iter()
    182         ),
    183         Err(ArgsErr::IgnoredIncludeIgnored)
    184     );
    185     assert_eq!(
    186         MetaCmd::from_args(
    187             [
    188                 OsString::new(),
    189                 "test".to_owned().into(),
    190                 "--ignore-features".to_owned().into(),
    191             ]
    192             .into_iter()
    193         ),
    194         Err(ArgsErr::MissingIgnoredFeatures)
    195     );
    196     assert_eq!(
    197         MetaCmd::from_args(
    198             [
    199                 OsString::new(),
    200                 "clippy".to_owned().into(),
    201                 "--ignore-features".to_owned().into(),
    202                 ",".to_owned().into(),
    203             ]
    204             .into_iter()
    205         ),
    206         Err(ArgsErr::DuplicateIgnoredFeatures(",".to_owned().into()))
    207     );
    208     assert_eq!(
    209         MetaCmd::from_args(
    210             [
    211                 OsString::new(),
    212                 "check".to_owned().into(),
    213                 "--ignore-features".to_owned().into(),
    214                 "a,,a".to_owned().into(),
    215             ]
    216             .into_iter()
    217         ),
    218         Err(ArgsErr::DuplicateIgnoredFeatures("a,,a".to_owned().into()))
    219     );
    220     assert_eq!(
    221         MetaCmd::from_args(
    222             [
    223                 OsString::new(),
    224                 "check".to_owned().into(),
    225                 "--ignore-features".to_owned().into(),
    226                 ",a,b,".to_owned().into(),
    227             ]
    228             .into_iter()
    229         ),
    230         Err(ArgsErr::DuplicateIgnoredFeatures(",a,b,".to_owned().into()))
    231     );
    232     assert_eq!(
    233         MetaCmd::from_args(
    234             [
    235                 OsString::new(),
    236                 "clippy".to_owned().into(),
    237                 "--ignore-features".to_owned().into(),
    238                 ",a,,b".to_owned().into(),
    239             ]
    240             .into_iter()
    241         ),
    242         Err(ArgsErr::DuplicateIgnoredFeatures(",a,,b".to_owned().into()))
    243     );
    244     assert_eq!(
    245         MetaCmd::from_args(
    246             [
    247                 OsString::new(),
    248                 "clippy".to_owned().into(),
    249                 "--ignore-features".to_owned().into(),
    250                 "a,b,,".to_owned().into(),
    251             ]
    252             .into_iter()
    253         ),
    254         Err(ArgsErr::DuplicateIgnoredFeatures("a,b,,".to_owned().into()))
    255     );
    256     // `--all-targets` can't be combined with other targets.
    257     assert_eq!(
    258         MetaCmd::from_args(
    259             [
    260                 OsString::new(),
    261                 "clippy".to_owned().into(),
    262                 "--lib".to_owned().into(),
    263                 "--all-targets".to_owned().into(),
    264             ]
    265             .into_iter()
    266         ),
    267         Err(ArgsErr::AllTargets)
    268     );
    269     assert_eq!(
    270         MetaCmd::from_args(
    271             [
    272                 OsString::new(),
    273                 "check".to_owned().into(),
    274                 "--lib".to_owned().into(),
    275                 "--all-targets".to_owned().into(),
    276             ]
    277             .into_iter()
    278         ),
    279         Err(ArgsErr::AllTargets)
    280     );
    281     assert_eq!(
    282         MetaCmd::from_args(
    283             [
    284                 OsString::new(),
    285                 "check".to_owned().into(),
    286                 "--all-targets".to_owned().into(),
    287                 "test".to_owned().into(),
    288                 "--doc".to_owned().into(),
    289                 "--all-targets".to_owned().into(),
    290             ]
    291             .into_iter()
    292         ),
    293         Err(ArgsErr::AllTargets)
    294     );
    295     // `--doc` can't be combined with other targets.
    296     assert_eq!(
    297         MetaCmd::from_args(
    298             [
    299                 OsString::new(),
    300                 "test".to_owned().into(),
    301                 "--all-targets".to_owned().into(),
    302                 "--doc".to_owned().into(),
    303             ]
    304             .into_iter()
    305         ),
    306         Err(ArgsErr::Doc)
    307     );
    308     assert_eq!(
    309         MetaCmd::from_args(
    310             [
    311                 OsString::new(),
    312                 "test".to_owned().into(),
    313                 "--doc".to_owned().into(),
    314                 "--lib".to_owned().into(),
    315             ]
    316             .into_iter()
    317         ),
    318         Err(ArgsErr::Doc)
    319     );
    320     assert_eq!(
    321         MetaCmd::from_args(
    322             [
    323                 OsString::new(),
    324                 "clippy".to_owned().into(),
    325                 "--doc".to_owned().into(),
    326             ]
    327             .into_iter()
    328         ),
    329         Err(ArgsErr::UnknownArg("--doc".to_owned().into()))
    330     );
    331     assert_eq!(
    332         MetaCmd::from_args(
    333             [
    334                 OsString::new(),
    335                 "check".to_owned().into(),
    336                 "--color".to_owned().into(),
    337                 "clippy".to_owned().into(),
    338                 "--color".to_owned().into(),
    339             ]
    340             .into_iter()
    341         ),
    342         Err(ArgsErr::DuplicateOption("--color".to_owned().into()))
    343     );
    344     assert_eq!(
    345         MetaCmd::from_args(
    346             [
    347                 OsString::new(),
    348                 "test".to_owned().into(),
    349                 "--ignored".to_owned().into(),
    350                 "--ignored".to_owned().into(),
    351             ]
    352             .into_iter()
    353         ),
    354         Err(ArgsErr::DuplicateOption("--ignored".to_owned().into()))
    355     );
    356     assert_eq!(
    357         MetaCmd::from_args(
    358             [
    359                 OsString::new(),
    360                 "clippy".to_owned().into(),
    361                 "--all-targets".to_owned().into(),
    362                 "--allow-implied-features".to_owned().into(),
    363                 "--cargo-home".to_owned().into(),
    364                 "--ignored".to_owned().into(),
    365                 "--cargo-path".to_owned().into(),
    366                 "cargo".to_owned().into(),
    367                 "--color".to_owned().into(),
    368                 "--default-toolchain".to_owned().into(),
    369                 "--deny-warnings".to_owned().into(),
    370                 "--dir".to_owned().into(),
    371                 OsString::new(),
    372                 "--ignore-compile-errors".to_owned().into(),
    373                 "--ignore-features".to_owned().into(),
    374                 ",a".to_owned().into(),
    375                 "--ignore-msrv".to_owned().into(),
    376                 "--rustup-home".to_owned().into(),
    377                 "a".to_owned().into(),
    378                 "--progress".to_owned().into(),
    379                 "--skip-msrv".to_owned().into(),
    380                 "--summary".to_owned().into(),
    381             ]
    382             .into_iter()
    383         ),
    384         Ok(MetaCmd::Cargo(
    385             Cmd::Clippy(CheckClippyTargets::All, true,),
    386             Opts {
    387                 exec_dir: Some(PathBuf::new()),
    388                 rustup_home: Some("a".to_owned().into()),
    389                 cargo_home: Some("--ignored".to_owned().into()),
    390                 cargo_path: "cargo/cargo".to_owned().into(),
    391                 color: true,
    392                 default_toolchain: true,
    393                 allow_implied_features: true,
    394                 ignore_compile_errors: true,
    395                 ignore_msrv: true,
    396                 progress: true,
    397                 skip_msrv: true,
    398                 summary: true,
    399                 ignore_features: vec![String::new(), "a".to_owned()],
    400             }
    401         ))
    402     );
    403     assert_eq!(
    404         MetaCmd::from_args(
    405             [
    406                 OsString::new(),
    407                 "clippy".to_owned().into(),
    408                 "--all-targets".to_owned().into(),
    409                 "--deny-warnings".to_owned().into(),
    410             ]
    411             .into_iter()
    412         ),
    413         Ok(MetaCmd::Cargo(
    414             Cmd::Clippy(CheckClippyTargets::All, true,),
    415             Opts {
    416                 exec_dir: None,
    417                 rustup_home: None,
    418                 cargo_home: None,
    419                 cargo_path: "cargo".to_owned().into(),
    420                 color: false,
    421                 default_toolchain: false,
    422                 allow_implied_features: false,
    423                 ignore_compile_errors: false,
    424                 ignore_msrv: false,
    425                 progress: false,
    426                 skip_msrv: false,
    427                 summary: false,
    428                 ignore_features: Vec::new(),
    429             }
    430         ))
    431     );
    432     assert_eq!(
    433         MetaCmd::from_args(
    434             [
    435                 OsString::new(),
    436                 "test".to_owned().into(),
    437                 "--allow-implied-features".to_owned().into(),
    438                 "--cargo-home".to_owned().into(),
    439                 "--ignored".to_owned().into(),
    440                 "--cargo-path".to_owned().into(),
    441                 "cargo".to_owned().into(),
    442                 "--color".to_owned().into(),
    443                 "--default-toolchain".to_owned().into(),
    444                 "--dir".to_owned().into(),
    445                 OsString::new(),
    446                 "--ignore-compile-errors".to_owned().into(),
    447                 "--ignore-features".to_owned().into(),
    448                 OsString::new(),
    449                 "--ignore-msrv".to_owned().into(),
    450                 "--ignored".to_owned().into(),
    451                 "--rustup-home".to_owned().into(),
    452                 OsString::new(),
    453                 "--progress".to_owned().into(),
    454                 "--skip-msrv".to_owned().into(),
    455                 "--summary".to_owned().into(),
    456             ]
    457             .into_iter()
    458         ),
    459         Ok(MetaCmd::Cargo(
    460             Cmd::Test(TestTargets::Default, Ignored::Only),
    461             Opts {
    462                 exec_dir: Some(PathBuf::new()),
    463                 rustup_home: Some(PathBuf::new()),
    464                 cargo_home: Some("--ignored".to_owned().into()),
    465                 cargo_path: "cargo/cargo".to_owned().into(),
    466                 color: true,
    467                 default_toolchain: true,
    468                 allow_implied_features: true,
    469                 ignore_compile_errors: true,
    470                 ignore_msrv: true,
    471                 progress: true,
    472                 skip_msrv: true,
    473                 summary: true,
    474                 ignore_features: vec![String::new()],
    475             }
    476         ))
    477     );
    478     assert_eq!(
    479         MetaCmd::from_args([OsString::new(), "test".to_owned().into(),].into_iter()),
    480         Ok(MetaCmd::Cargo(
    481             Cmd::Test(TestTargets::Default, Ignored::None),
    482             Opts {
    483                 exec_dir: None,
    484                 rustup_home: None,
    485                 cargo_home: None,
    486                 cargo_path: "cargo".to_owned().into(),
    487                 color: false,
    488                 default_toolchain: false,
    489                 allow_implied_features: false,
    490                 ignore_compile_errors: false,
    491                 ignore_msrv: false,
    492                 progress: false,
    493                 skip_msrv: false,
    494                 summary: false,
    495                 ignore_features: Vec::new(),
    496             }
    497         ))
    498     );
    499     assert_eq!(
    500         MetaCmd::from_args(
    501             [
    502                 OsString::new(),
    503                 "test".to_owned().into(),
    504                 "--include-ignored".to_owned().into()
    505             ]
    506             .into_iter()
    507         ),
    508         Ok(MetaCmd::Cargo(
    509             Cmd::Test(TestTargets::Default, Ignored::Include),
    510             Opts {
    511                 exec_dir: None,
    512                 rustup_home: None,
    513                 cargo_home: None,
    514                 cargo_path: "cargo".to_owned().into(),
    515                 color: false,
    516                 default_toolchain: false,
    517                 allow_implied_features: false,
    518                 ignore_compile_errors: false,
    519                 ignore_msrv: false,
    520                 progress: false,
    521                 skip_msrv: false,
    522                 summary: false,
    523                 ignore_features: Vec::new(),
    524             }
    525         ))
    526     );
    527     assert_eq!(
    528         MetaCmd::from_args(
    529             [
    530                 OsString::new(),
    531                 "check".to_owned().into(),
    532                 "--all-targets".to_owned().into(),
    533                 "--allow-implied-features".to_owned().into(),
    534                 "--cargo-home".to_owned().into(),
    535                 "--ignored".to_owned().into(),
    536                 "--cargo-path".to_owned().into(),
    537                 "cargo".to_owned().into(),
    538                 "--color".to_owned().into(),
    539                 "--default-toolchain".to_owned().into(),
    540                 "--dir".to_owned().into(),
    541                 OsString::new(),
    542                 "--ignore-compile-errors".to_owned().into(),
    543                 "--ignore-features".to_owned().into(),
    544                 "a,".to_owned().into(),
    545                 "--ignore-msrv".to_owned().into(),
    546                 "--rustup-home".to_owned().into(),
    547                 OsString::new(),
    548                 "--progress".to_owned().into(),
    549                 "--skip-msrv".to_owned().into(),
    550                 "--summary".to_owned().into(),
    551             ]
    552             .into_iter()
    553         ),
    554         Ok(MetaCmd::Cargo(
    555             Cmd::Check(CheckClippyTargets::All),
    556             Opts {
    557                 exec_dir: Some(PathBuf::new()),
    558                 rustup_home: Some(PathBuf::new()),
    559                 cargo_home: Some("--ignored".to_owned().into()),
    560                 cargo_path: "cargo/cargo".to_owned().into(),
    561                 color: true,
    562                 default_toolchain: true,
    563                 allow_implied_features: true,
    564                 ignore_compile_errors: true,
    565                 ignore_msrv: true,
    566                 progress: true,
    567                 skip_msrv: true,
    568                 summary: true,
    569                 ignore_features: vec!["a".to_owned(), String::new()],
    570             }
    571         ))
    572     );
    573     assert_eq!(
    574         MetaCmd::from_args([OsString::new(), "check".to_owned().into(),].into_iter()),
    575         Ok(MetaCmd::Cargo(
    576             Cmd::Check(CheckClippyTargets::Default),
    577             Opts {
    578                 exec_dir: None,
    579                 rustup_home: None,
    580                 cargo_home: None,
    581                 cargo_path: "cargo".to_owned().into(),
    582                 color: false,
    583                 default_toolchain: false,
    584                 allow_implied_features: false,
    585                 ignore_compile_errors: false,
    586                 ignore_msrv: false,
    587                 progress: false,
    588                 skip_msrv: false,
    589                 summary: false,
    590                 ignore_features: Vec::new(),
    591             }
    592         ))
    593     );
    594     assert_eq!(
    595         MetaCmd::from_args(
    596             [
    597                 OsString::new(),
    598                 "check".to_owned().into(),
    599                 "--ignore-features".to_owned().into(),
    600                 "a,,b".to_owned().into(),
    601             ]
    602             .into_iter()
    603         ),
    604         Ok(MetaCmd::Cargo(
    605             Cmd::Check(CheckClippyTargets::Default),
    606             Opts {
    607                 exec_dir: None,
    608                 rustup_home: None,
    609                 cargo_home: None,
    610                 cargo_path: "cargo".to_owned().into(),
    611                 color: false,
    612                 default_toolchain: false,
    613                 allow_implied_features: false,
    614                 ignore_compile_errors: false,
    615                 ignore_msrv: false,
    616                 progress: false,
    617                 skip_msrv: false,
    618                 summary: false,
    619                 ignore_features: vec!["a".to_owned(), String::new(), "b".to_owned()],
    620             }
    621         ))
    622     );
    623     assert_eq!(
    624         MetaCmd::from_args(
    625             [
    626                 OsString::new(),
    627                 "check".to_owned().into(),
    628                 "--ignore-features".to_owned().into(),
    629                 "a,b,".to_owned().into(),
    630             ]
    631             .into_iter()
    632         ),
    633         Ok(MetaCmd::Cargo(
    634             Cmd::Check(CheckClippyTargets::Default),
    635             Opts {
    636                 exec_dir: None,
    637                 rustup_home: None,
    638                 cargo_home: None,
    639                 cargo_path: "cargo".to_owned().into(),
    640                 color: false,
    641                 default_toolchain: false,
    642                 allow_implied_features: false,
    643                 ignore_compile_errors: false,
    644                 ignore_msrv: false,
    645                 progress: false,
    646                 skip_msrv: false,
    647                 summary: false,
    648                 ignore_features: vec!["a".to_owned(), "b".to_owned(), String::new()],
    649             }
    650         ))
    651     );
    652     assert_eq!(
    653         MetaCmd::from_args(
    654             [
    655                 OsString::new(),
    656                 "check".to_owned().into(),
    657                 "--ignore-features".to_owned().into(),
    658                 "a,b".to_owned().into(),
    659             ]
    660             .into_iter()
    661         ),
    662         Ok(MetaCmd::Cargo(
    663             Cmd::Check(CheckClippyTargets::Default),
    664             Opts {
    665                 exec_dir: None,
    666                 rustup_home: None,
    667                 cargo_home: None,
    668                 cargo_path: "cargo".to_owned().into(),
    669                 color: false,
    670                 default_toolchain: false,
    671                 allow_implied_features: false,
    672                 ignore_compile_errors: false,
    673                 ignore_msrv: false,
    674                 progress: false,
    675                 skip_msrv: false,
    676                 summary: false,
    677                 ignore_features: vec!["a".to_owned(), "b".to_owned()],
    678             }
    679         ))
    680     );
    681     // No whitespace cleanup is done on the features.
    682     assert_eq!(
    683         MetaCmd::from_args(
    684             [
    685                 OsString::new(),
    686                 "check".to_owned().into(),
    687                 "--ignore-features".to_owned().into(),
    688                 "a , , b,  ".to_owned().into(),
    689             ]
    690             .into_iter()
    691         ),
    692         Ok(MetaCmd::Cargo(
    693             Cmd::Check(CheckClippyTargets::Default),
    694             Opts {
    695                 exec_dir: None,
    696                 rustup_home: None,
    697                 cargo_home: None,
    698                 cargo_path: "cargo".to_owned().into(),
    699                 color: false,
    700                 default_toolchain: false,
    701                 allow_implied_features: false,
    702                 ignore_compile_errors: false,
    703                 ignore_msrv: false,
    704                 progress: false,
    705                 skip_msrv: false,
    706                 summary: false,
    707                 ignore_features: vec![
    708                     "a ".to_owned(),
    709                     " ".to_owned(),
    710                     " b".to_owned(),
    711                     "  ".to_owned()
    712                 ],
    713             }
    714         ))
    715     );
    716     assert_eq!(
    717         MetaCmd::from_args([OsString::new(), "help".to_owned().into(),].into_iter()),
    718         Ok(MetaCmd::Help)
    719     );
    720     assert_eq!(
    721         MetaCmd::from_args([OsString::new(), "version".to_owned().into(),].into_iter()),
    722         Ok(MetaCmd::Version)
    723     );
    724     let mut check_targets = Targets::new(Target::Examples);
    725     assert!(check_targets.add(Target::Tests));
    726     assert!(!check_targets.add(Target::Examples));
    727     let mut test_targets = Targets::new(Target::Benches);
    728     assert!(test_targets.add(Target::Bins));
    729     assert!(!test_targets.add(Target::Bins));
    730     assert!(test_targets.add(Target::Examples));
    731     assert!(test_targets.add(Target::Lib));
    732     assert!(test_targets.add(Target::Tests));
    733     assert_eq!(
    734         MetaCmd::from_args(
    735             [
    736                 OsString::new(),
    737                 "clippy".to_owned().into(),
    738                 "--all-targets".to_owned().into(),
    739                 "--allow-implied-features".to_owned().into(),
    740                 "--cargo-home".to_owned().into(),
    741                 "--ignored".to_owned().into(),
    742                 "--cargo-path".to_owned().into(),
    743                 "cargo".to_owned().into(),
    744                 "--color".to_owned().into(),
    745                 "--default-toolchain".to_owned().into(),
    746                 "--deny-warnings".to_owned().into(),
    747                 "--dir".to_owned().into(),
    748                 OsString::new(),
    749                 "--ignore-compile-errors".to_owned().into(),
    750                 "--ignore-features".to_owned().into(),
    751                 ",a".to_owned().into(),
    752                 "--ignore-msrv".to_owned().into(),
    753                 "--rustup-home".to_owned().into(),
    754                 "a".to_owned().into(),
    755                 "test".to_owned().into(),
    756                 "--benches".to_owned().into(),
    757                 "--bins".to_owned().into(),
    758                 "--examples".to_owned().into(),
    759                 "--include-ignored".to_owned().into(),
    760                 "--lib".to_owned().into(),
    761                 "--tests".to_owned().into(),
    762                 "--progress".to_owned().into(),
    763                 "--skip-msrv".to_owned().into(),
    764                 "check".to_owned().into(),
    765                 "--tests".to_owned().into(),
    766                 "--examples".to_owned().into(),
    767                 "--summary".to_owned().into(),
    768             ]
    769             .into_iter()
    770         ),
    771         Ok(MetaCmd::Cargo(
    772             Cmd::CheckClippyTest(
    773                 CheckClippyTargets::Targets(check_targets),
    774                 CheckClippyTargets::All,
    775                 true,
    776                 TestTargets::Targets(test_targets),
    777                 Ignored::Include,
    778             ),
    779             Opts {
    780                 exec_dir: Some(PathBuf::new()),
    781                 rustup_home: Some("a".to_owned().into()),
    782                 cargo_home: Some("--ignored".to_owned().into()),
    783                 cargo_path: "cargo/cargo".to_owned().into(),
    784                 color: true,
    785                 default_toolchain: true,
    786                 allow_implied_features: true,
    787                 ignore_compile_errors: true,
    788                 ignore_msrv: true,
    789                 progress: true,
    790                 skip_msrv: true,
    791                 summary: true,
    792                 ignore_features: vec![String::new(), "a".to_owned()],
    793             }
    794         ))
    795     );
    796 }
    797 #[test]
    798 fn non_zero_usize_plus_1() {
    799     #[cfg(target_pointer_width = "64")]
    800     assert_eq!(NonZeroUsizePlus1(0).to_string(), "18446744073709551616");
    801     #[cfg(target_pointer_width = "64")]
    802     assert_eq!(
    803         NonZeroUsizePlus1(usize::MAX).to_string(),
    804         "18446744073709551615"
    805     );
    806     #[cfg(target_pointer_width = "32")]
    807     assert_eq!(NonZeroUsizePlus1(0).to_string(), "4294967296");
    808     #[cfg(target_pointer_width = "32")]
    809     assert_eq!(NonZeroUsizePlus1(usize::MAX).to_string(), "4294967295");
    810     #[cfg(target_pointer_width = "16")]
    811     assert_eq!(NonZeroUsizePlus1(0).to_string(), "65536");
    812     #[cfg(target_pointer_width = "16")]
    813     assert_eq!(NonZeroUsizePlus1(usize::MAX).to_string(), "65535");
    814     assert_eq!(NonZeroUsizePlus1(1).to_string(), "1");
    815     assert_eq!(NonZeroUsizePlus1(2).to_string(), "2");
    816     assert_eq!(NonZeroUsizePlus1(10).to_string(), "10");
    817 }