aboutsummaryrefslogtreecommitdiff
path: root/bin/tests/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'bin/tests/main.rs')
-rw-r--r--bin/tests/main.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/bin/tests/main.rs b/bin/tests/main.rs
new file mode 100644
index 0000000..6175c90
--- /dev/null
+++ b/bin/tests/main.rs
@@ -0,0 +1,47 @@
1mod util {
2 #[macro_export]
3 macro_rules! test_lint {
4 ($($tname:ident),*,) => {
5 test_lint!($($tname),*);
6 };
7 ($($tname:ident),*) => {
8 $(
9 #[test]
10 fn $tname() {
11 use statix::{config::OutFormat, traits::WriteDiagnostic, lint};
12 use vfs::ReadOnlyVfs;
13
14 let file_path = concat!("data/", stringify!($tname), ".nix");
15 let contents = include_str!(concat!("data/", stringify!($tname), ".nix"));
16
17 let vfs = ReadOnlyVfs::singleton(file_path, contents.as_bytes());
18
19 let mut buffer = Vec::new();
20 vfs.iter().map(lint::lint).for_each(|r| {
21 buffer.write(&r, &vfs, OutFormat::StdErr).unwrap();
22 });
23
24 let stripped = strip_ansi_escapes::strip(&buffer).unwrap();
25 let out = std::str::from_utf8(&stripped).unwrap();
26 insta::assert_snapshot!(&out);
27 }
28 )*
29 };
30 }
31}
32
33test_lint! {
34 bool_comparison,
35 empty_let_in,
36 manual_inherit,
37 manual_inherit_from,
38 legacy_let_syntax,
39 collapsible_let_in,
40 eta_reduction,
41 useless_parens,
42 unquoted_splices,
43 empty_pattern,
44 redundant_pattern_bind,
45 unquoted_uri,
46 deprecated_is_null,
47}