Lints and suggestions for the Nix programming language
1use std::{io::Write, process::Command};
2
3use tempfile::NamedTempFile;
4
5pub fn test_cli(expression: &str, args: &[&str]) -> anyhow::Result<String> {
6 let mut fixture = NamedTempFile::with_suffix(".nix")?;
7 fixture.write_all(expression.as_bytes())?;
8 fixture.write_all(b"\n")?; // otherwise diff says there's no newline at end of file
9
10 let output = Command::new("cargo")
11 .arg("run")
12 .arg("--")
13 .args(args)
14 .arg(fixture.path())
15 .output()?;
16
17 let stdout = strip_ansi_escapes::strip(output.stdout)?;
18 let stdout = String::from_utf8(stdout)?;
19 let stdout = stdout.replace(fixture.path().to_str().unwrap(), "<temp_file_path>");
20
21 Ok(stdout)
22}