-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen_integration_tests.rs
82 lines (67 loc) · 1.82 KB
/
gen_integration_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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! Test generating completions from KDL/JSON files
use std::{
env,
path::{Path, PathBuf},
process::{Command, Stdio},
};
use assert_cmd::prelude::{CommandCargoExt, OutputAssertExt};
use insta::Settings;
const BIN_NAME: &str = "gen-completions";
fn run_test(shell: &str, conf: &str, args: &[&str]) {
// The project's root directory
let root = env::var("CARGO_MANIFEST_DIR").unwrap();
let conf_file = PathBuf::from(root).join("tests/resources/gen").join(conf);
// The gen-completions binary to test
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
let cmd = cmd.arg("for").arg(shell).arg(&conf_file).args(args);
// So we can explicitly ask for logging
if let Ok(log_level) = env::var("RUST_LOG") {
cmd.env("RUST_LOG", log_level).stderr(Stdio::inherit());
}
let got = cmd.output().unwrap().stdout;
let got = std::str::from_utf8(&got).unwrap().trim();
cmd.assert().success();
let mut settings = Settings::clone_current();
settings.set_snapshot_path(Path::new("snapshots/gen/"));
settings.set_snapshot_suffix(format!("{}.{}", conf, shell));
settings.set_description(format!(
"Generated for shell {} using config file {}",
shell, conf
));
settings.set_input_file(conf_file);
settings.bind(|| {
insta::assert_snapshot!(got);
});
}
#[test]
fn test1_zsh() {
run_test("zsh", "test1.json", &[]);
}
#[test]
fn test1_bash() {
run_test("bash", "test1.json", &[]);
}
#[test]
fn test1_nu() {
run_test("nu", "test1.json", &[]);
}
#[test]
fn test1_kdl() {
run_test("kdl", "test1.json", &[]);
}
#[test]
fn test1_json() {
run_test("json", "test1.json", &[]);
}
// #[test]
// fn types_bash() {
// run_test("bash", "test-types.kdl", &[]);
// }
// #[test]
// fn types_zsh() {
// run_test("zsh", "test-types.kdl", &[]);
// }
#[test]
fn types_nu() {
run_test("nu", "test-types.kdl", &[]);
}