diff options
Diffstat (limited to 'bin/tests/main.rs')
-rw-r--r-- | bin/tests/main.rs | 66 |
1 files changed, 42 insertions, 24 deletions
diff --git a/bin/tests/main.rs b/bin/tests/main.rs index de5266f..991c876 100644 --- a/bin/tests/main.rs +++ b/bin/tests/main.rs | |||
@@ -1,31 +1,48 @@ | |||
1 | use lib::session::{SessionInfo, Version}; | ||
2 | |||
3 | macro_rules! session_info { | ||
4 | ($version:expr) => {{ | ||
5 | let v: Version = $version.parse().unwrap(); | ||
6 | SessionInfo::from_version(v) | ||
7 | }}; | ||
8 | } | ||
9 | |||
1 | mod util { | 10 | mod util { |
2 | #[macro_export] | 11 | #[macro_export] |
3 | macro_rules! test_lint { | 12 | macro_rules! test_lint { |
4 | ($($tname:ident),*,) => { | 13 | ($tname:ident => $sess:expr, $($tail:tt)*) => { |
5 | test_lint!($($tname),*); | 14 | test_lint!($tname => $sess); |
15 | test_lint!($($tail)*); | ||
16 | }; | ||
17 | ($tname:ident, $($tail:tt)*) => { | ||
18 | test_lint!($tname); | ||
19 | test_lint!($($tail)*); | ||
20 | }; | ||
21 | ($tname:ident) => { | ||
22 | test_lint!($tname => session_info!("nix (Nix) 2.5")); | ||
6 | }; | 23 | }; |
7 | ($($tname:ident),*) => { | 24 | ($tname:ident => $sess:expr) => { |
8 | $( | 25 | #[test] |
9 | #[test] | 26 | fn $tname() { |
10 | fn $tname() { | 27 | use statix::{config::OutFormat, traits::WriteDiagnostic, lint}; |
11 | use statix::{config::OutFormat, traits::WriteDiagnostic, lint}; | 28 | use vfs::ReadOnlyVfs; |
12 | use vfs::ReadOnlyVfs; | 29 | |
13 | 30 | let file_path = concat!("data/", stringify!($tname), ".nix"); | |
14 | let file_path = concat!("data/", stringify!($tname), ".nix"); | 31 | let contents = include_str!(concat!("data/", stringify!($tname), ".nix")); |
15 | let contents = include_str!(concat!("data/", stringify!($tname), ".nix")); | 32 | |
16 | 33 | let vfs = ReadOnlyVfs::singleton(file_path, contents.as_bytes()); | |
17 | let vfs = ReadOnlyVfs::singleton(file_path, contents.as_bytes()); | 34 | |
18 | 35 | let session = $sess; | |
19 | let mut buffer = Vec::new(); | 36 | |
20 | vfs.iter().map(lint::lint).for_each(|r| { | 37 | let mut buffer = Vec::new(); |
21 | buffer.write(&r, &vfs, OutFormat::StdErr).unwrap(); | 38 | vfs.iter().map(|entry| lint::lint(entry, &session)).for_each(|r| { |
22 | }); | 39 | buffer.write(&r, &vfs, OutFormat::StdErr).unwrap(); |
23 | 40 | }); | |
24 | let stripped = strip_ansi_escapes::strip(&buffer).unwrap(); | 41 | |
25 | let out = std::str::from_utf8(&stripped).unwrap(); | 42 | let stripped = strip_ansi_escapes::strip(&buffer).unwrap(); |
26 | insta::assert_snapshot!(&out); | 43 | let out = std::str::from_utf8(&stripped).unwrap(); |
27 | } | 44 | insta::assert_snapshot!(&out); |
28 | )* | 45 | } |
29 | }; | 46 | }; |
30 | } | 47 | } |
31 | } | 48 | } |
@@ -44,4 +61,5 @@ test_lint! { | |||
44 | unquoted_uri, | 61 | unquoted_uri, |
45 | deprecated_is_null, | 62 | deprecated_is_null, |
46 | empty_inherit, | 63 | empty_inherit, |
64 | faster_groupby => session_info!("nix (Nix) 2.5") | ||
47 | } | 65 | } |