Skip to content

Commit 18a28a1

Browse files
committed
Auto merge of #12224 - Muscraft:test-z-flags-sorted, r=weihanglo
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)
2 parents 928b956 + 8d143cc commit 18a28a1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Diff for: src/cargo/core/features.rs

+20
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,26 @@ macro_rules! unstable_cli_options {
687687
fields
688688
}
689689
}
690+
691+
#[cfg(test)]
692+
mod test {
693+
#[test]
694+
fn ensure_sorted() {
695+
// This will be printed out if the fields are not sorted.
696+
let location = std::panic::Location::caller();
697+
println!(
698+
"\nTo fix this test, sort the features inside the macro at {}:{}\n",
699+
location.file(),
700+
location.line()
701+
);
702+
let mut expected = vec![$(stringify!($element)),*];
703+
expected[2..].sort();
704+
snapbox::assert_eq(
705+
format!("{:#?}", expected),
706+
format!("{:#?}", vec![$(stringify!($element)),*])
707+
);
708+
}
709+
}
690710
}
691711
}
692712

0 commit comments

Comments
 (0)