aboutsummaryrefslogtreecommitdiff
path: root/bin/tests/main.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-11-03 09:18:35 +0000
committerAkshay <[email protected]>2021-11-08 05:03:13 +0000
commit4e063b2abc402ac4d6902647e821978269025c7d (patch)
treea8935a5432fe86d0e5facb9ff8acc71edcb7f782 /bin/tests/main.rs
parent78decf580d22fa792c19c40ace39762fb027067c (diff)
add snapshot test suitesnapshot-tests
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}