-
-
Notifications
You must be signed in to change notification settings - Fork 92
/
tests.rs
36 lines (33 loc) · 1016 Bytes
/
tests.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use std::env;
use std::fs;
use std::path::Path;
use std::process::Command;
use insta::{assert_snapshot, Settings};
use walkdir::WalkDir;
fn main() {
// run tests and accept snapshots
Command::new(env!("CARGO_BIN_EXE_cargo-insta"))
.arg("test")
.arg("--accept")
.arg("--no-ignore")
.status()
.unwrap();
// use insta itself to assert snapshots
for entry in WalkDir::new("test-input") {
let entry = entry.unwrap();
let filename = entry
.path()
.strip_prefix("test-input/")
.unwrap()
.to_str()
.unwrap();
if let Some(snapshot) = filename.strip_suffix(".rs") {
let gen_file = Path::new("tests").join(filename);
let mut settings = Settings::clone_current();
settings.set_input_file(&gen_file);
settings.bind(|| {
assert_snapshot!(snapshot, &fs::read_to_string(gen_file).unwrap());
});
}
}
}