|
1 | 1 | use std::{
|
| 2 | + ffi::OsString, |
2 | 3 | io::Write,
|
| 4 | + path::PathBuf, |
3 | 5 | process::{Command, Stdio},
|
4 | 6 | };
|
5 | 7 |
|
@@ -73,3 +75,60 @@ fn automatic_color_on_non_tty() {
|
73 | 75 | );
|
74 | 76 | }
|
75 | 77 | }
|
| 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