tangled
alpha
login
or
join now
oppi.li
/
statix
0
fork
atom
Lints and suggestions for the Nix programming language
0
fork
atom
overview
issues
pulls
pipelines
chore: extract helper fns for test_lint!
mightyiam.tngl.sh
5 months ago
ebec23e4
43681f0d
+35
-28
1 changed file
expand all
collapse all
unified
split
bin
tests
main.rs
+35
-28
bin/tests/main.rs
···
1
1
+
use std::path::Path;
2
2
+
1
3
use lib::session::{SessionInfo, Version};
2
4
3
5
macro_rules! session_info {
···
25
27
paste::paste! {
26
28
#[test]
27
29
fn [<$tname _lint>](){
28
28
-
use statix::{config::OutFormat, traits::WriteDiagnostic, lint};
29
29
-
use vfs::ReadOnlyVfs;
30
30
-
31
30
let file_path = concat!("data/", stringify!($tname), ".nix");
32
31
let contents = include_str!(concat!("data/", stringify!($tname), ".nix"));
33
33
-
34
34
-
let vfs = ReadOnlyVfs::singleton(file_path, contents.as_bytes());
35
35
-
36
36
-
let session = $sess;
37
37
-
38
38
-
let mut buffer = Vec::new();
39
39
-
vfs.iter().map(|entry| lint::lint(&entry, &session)).for_each(|r| {
40
40
-
buffer.write(&r, &vfs, OutFormat::StdErr).unwrap();
41
41
-
});
42
42
-
43
43
-
let stripped = strip_ansi_escapes::strip(&buffer).unwrap();
44
44
-
let out = std::str::from_utf8(&stripped).unwrap();
45
45
-
insta::assert_snapshot!(&out);
32
32
+
test_lint(&$sess, file_path, contents);
46
33
}
47
34
48
35
#[test]
49
36
fn [<$tname _fix>](){
50
37
let file_path = concat!("tests/data/", stringify!($tname), ".nix");
51
51
-
52
52
-
let output = std::process::Command::new("cargo")
53
53
-
.arg("run")
54
54
-
.arg("fix")
55
55
-
.arg("-d")
56
56
-
.arg(file_path)
57
57
-
.output()
58
58
-
.expect("command runs successfully");
59
59
-
60
60
-
let stdout = String::from_utf8(output.stdout).expect("output is valid utf8");
61
61
-
62
62
-
insta::assert_snapshot!(&stdout);
38
38
+
test_fix(file_path);
63
39
}
64
40
}
65
41
66
42
};
67
43
}
44
44
+
}
45
45
+
46
46
+
fn test_lint(session: &SessionInfo, file_path: impl AsRef<Path>, contents: &str) {
47
47
+
use statix::{config::OutFormat, lint, traits::WriteDiagnostic};
48
48
+
use vfs::ReadOnlyVfs;
49
49
+
50
50
+
let vfs = ReadOnlyVfs::singleton(file_path, contents.as_bytes());
51
51
+
52
52
+
let mut buffer = Vec::new();
53
53
+
vfs.iter()
54
54
+
.map(|entry| lint::lint(&entry, session))
55
55
+
.for_each(|r| {
56
56
+
buffer.write(&r, &vfs, OutFormat::StdErr).unwrap();
57
57
+
});
58
58
+
59
59
+
let stripped = strip_ansi_escapes::strip(&buffer).unwrap();
60
60
+
let out = std::str::from_utf8(&stripped).unwrap();
61
61
+
insta::assert_snapshot!(&out);
62
62
+
}
63
63
+
fn test_fix(file_path: &str) {
64
64
+
let output = std::process::Command::new("cargo")
65
65
+
.arg("run")
66
66
+
.arg("fix")
67
67
+
.arg("-d")
68
68
+
.arg(file_path)
69
69
+
.output()
70
70
+
.expect("command runs successfully");
71
71
+
72
72
+
let stdout = String::from_utf8(output.stdout).expect("output is valid utf8");
73
73
+
74
74
+
insta::assert_snapshot!(&stdout);
68
75
}
69
76
70
77
test_lint! {