Skip to content

Commit 70a12d5

Browse files
committed
Move mixed format input test to integration
The test was specified using snapshot tests, which aren't really a good fit for multiple input files. While it worked locally, it didn't work on the CI, where it couldn't find the input files, despite efforts to properly set the current working directory in the test process. In the end, it was simpler to move it to a manual intergration test, which is a bit more cumbersome but more flexible.
1 parent 94f7955 commit 70a12d5

File tree

6 files changed

+59
-0
lines changed

6 files changed

+59
-0
lines changed

cli/tests/integration/main.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::{
2+
ffi::OsString,
23
io::Write,
4+
path::PathBuf,
35
process::{Command, Stdio},
46
};
57

@@ -73,3 +75,60 @@ fn automatic_color_on_non_tty() {
7375
);
7476
}
7577
}
78+
79+
#[test]
80+
// This test didn't fit the snapshot test specification very well. While it can be encoded as
81+
// snapshot test, it didn't work on the CI (where the working directory doesn't seem to be properly
82+
// set for some reason), so we are using a manual test for now.
83+
fn merge_mixed_formats() {
84+
// Provide a current directory-independent path to the input files of integration tests.
85+
fn input_path(name: &str) -> OsString {
86+
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
87+
path.push("tests/integration/inputs");
88+
path.push(name);
89+
path.into_os_string()
90+
}
91+
92+
let nickel_bin = env!("CARGO_BIN_EXE_nickel");
93+
94+
let nickel = Command::new(nickel_bin)
95+
.arg("export")
96+
.args([
97+
input_path("mixed.ncl"),
98+
input_path("mixed.json"),
99+
input_path("mixed.toml"),
100+
])
101+
.arg("--apply-contract")
102+
.arg(input_path("mixed_contract.ncl"))
103+
.stdin(Stdio::piped())
104+
.stdout(Stdio::piped())
105+
.stderr(Stdio::piped())
106+
.spawn()
107+
.expect("Nickel should be runnable");
108+
109+
let output = nickel
110+
.wait_with_output()
111+
.expect("couldn't retrieve stdout handle to Nickel");
112+
113+
let stderr_output =
114+
String::from_utf8(output.stderr).expect("The result of Nickel should be valid utf8");
115+
let stdout_output =
116+
String::from_utf8(output.stdout).expect("The result of Nickel should be valid utf8");
117+
118+
assert_eq!(stderr_output, "");
119+
assert_eq!(
120+
stdout_output,
121+
"\
122+
{
123+
\"bar\": 123,
124+
\"extra\": {
125+
\"json\": true,
126+
\"nickel\": true,
127+
\"subfield\": \"here\",
128+
\"toml\": true
129+
},
130+
\"foo\": \"hello\"
131+
}
132+
"
133+
);
134+
}

0 commit comments

Comments
 (0)