Skip to content

Commit 1bb0b12

Browse files
committed
chore: Add tests to ensure lints and groups stay sorted
1 parent e8e50d0 commit 1bb0b12

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

src/cargo/util/lints.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use toml_edit::ImDocument;
1414

1515
const LINT_GROUPS: &[LintGroup] = &[TEST_DUMMY_UNSTABLE];
1616
pub const LINTS: &[Lint] = &[
17-
IM_A_TEAPOT,
1817
IMPLICIT_FEATURES,
18+
IM_A_TEAPOT,
1919
UNKNOWN_LINTS,
2020
UNUSED_OPTIONAL_DEPENDENCY,
2121
];
@@ -875,3 +875,42 @@ pub fn unused_dependencies(
875875
}
876876
Ok(())
877877
}
878+
879+
#[cfg(test)]
880+
mod tests {
881+
use snapbox::ToDebug;
882+
883+
#[test]
884+
fn ensure_sorted_lints() {
885+
// This will be printed out if the fields are not sorted.
886+
let location = std::panic::Location::caller();
887+
println!("\nTo fix this test, sort `LINTS` in {}\n", location.file(),);
888+
889+
let actual = super::LINTS
890+
.iter()
891+
.map(|l| l.name.to_uppercase())
892+
.collect::<Vec<_>>();
893+
894+
let mut expected = actual.clone();
895+
expected.sort();
896+
snapbox::assert_data_eq!(actual.to_debug(), expected.to_debug());
897+
}
898+
899+
#[test]
900+
fn ensure_sorted_lint_groups() {
901+
// This will be printed out if the fields are not sorted.
902+
let location = std::panic::Location::caller();
903+
println!(
904+
"\nTo fix this test, sort `LINT_GROUPS` in {}\n",
905+
location.file(),
906+
);
907+
let actual = super::LINT_GROUPS
908+
.iter()
909+
.map(|l| l.name.to_uppercase())
910+
.collect::<Vec<_>>();
911+
912+
let mut expected = actual.clone();
913+
expected.sort();
914+
snapbox::assert_data_eq!(actual.to_debug(), expected.to_debug());
915+
}
916+
}

0 commit comments

Comments
 (0)