Something went wrong. Try again.
Lints and suggestions for the Nix programming language forked from oppi.li/statix
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041use std::{io::Write, process::Command, process::Stdio};
use tempfile::NamedTempFile;
#[allow(dead_code)]pub fn test_cli(expression: &str, args: &[&str]) -> anyhow::Result<String> { let mut fixture = NamedTempFile::with_suffix(".nix")?; fixture.write_all(expression.as_bytes())?;
let output = Command::new(env!("CARGO_BIN_EXE_statix")) .args(args) .arg(fixture.path()) .output()?;
let stdout = strip_ansi_escapes::strip(output.stdout); let stdout = String::from_utf8(stdout)?; let stdout = stdout.replace(fixture.path().to_str().unwrap(), "<temp_file_path>");
Ok(stdout)}
#[allow(dead_code)]pub fn test_cli_stdin(input: &str, args: &[&str]) -> anyhow::Result<String> { let mut child = Command::new(env!("CARGO_BIN_EXE_statix")) .args(args) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .spawn()?;
child .stdin .as_mut() .expect("stdin should be piped") .write_all(input.as_bytes())?;
let output = child.wait_with_output()?; let stdout = strip_ansi_escapes::strip(output.stdout);
Ok(String::from_utf8(stdout)?)}