Skip to content

Commit

Permalink
Auto merge of #12224 - Muscraft:test-z-flags-sorted, r=weihanglo
Browse files Browse the repository at this point in the history
test(z-flags): Verify `-Z` flags list is sorted

#12182 made it so that `unstable_cli_options!` was sorted, but had no way to make sure it would stay sorted in the future.

In [this thread](https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/Sorting.20features!.20and.20ensuring.20it.20stays.20sorted), I proposed that a test should be added that would fail if the list is not sorted, this PR adds that test.

If the list is not sorted the test output looks like this:
![Screenshot from 2023-06-02 10-17-08](https://github.com/rust-lang/cargo/assets/23045215/f22cf5f3-4411-44ec-ac5a-991165d5e0a1)
  • Loading branch information
bors committed Jun 11, 2023
2 parents 928b956 + 8d143cc commit 18a28a1
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,26 @@ macro_rules! unstable_cli_options {
fields
}
}

#[cfg(test)]
mod test {
#[test]
fn ensure_sorted() {
// This will be printed out if the fields are not sorted.
let location = std::panic::Location::caller();
println!(
"\nTo fix this test, sort the features inside the macro at {}:{}\n",
location.file(),
location.line()
);
let mut expected = vec![$(stringify!($element)),*];
expected[2..].sort();
snapbox::assert_eq(
format!("{:#?}", expected),
format!("{:#?}", vec![$(stringify!($element)),*])
);
}
}
}
}

Expand Down

0 comments on commit 18a28a1

Please sign in to comment.