use k9::assert_equal;
use iocore::{
Path, shell_command, shell_command_stdout, shell_command_string_output,
shell_command_vec_output,
};
use sanitation::SString;
#[test]
fn test_shell_command_vec_output() {
let (exit_code, out, err) = shell_command_vec_output("echo 'out'", ".").unwrap();
assert_equal!(SString::new(&out).unchecked_safe(), "out\n");
assert_equal!(exit_code, 0);
assert_equal!(SString::new(&err).unchecked_safe(), "");
let (exit_code, out, err) = shell_command_vec_output("dd if=/dev/null of=/", ".").unwrap();
assert_equal!(exit_code, 1);
assert_equal!(SString::new(&err).unchecked_safe().len() > 0, true);
assert_equal!(SString::new(&out).unchecked_safe(), "");
}
#[test]
fn test_shell_command_string_output() {
let (exit_code, out, err) = shell_command_string_output("echo -n out", ".").unwrap();
assert_equal!(out, "out");
assert_equal!(exit_code, 0);
assert_equal!(err, "");
let (exit_code, out, err) = shell_command_string_output("dd if=/dev/null of=/", ".").unwrap();
assert_equal!(exit_code, 1);
assert_equal!(err.len() > 0, true);
assert_equal!(out, "");
}
#[test]
fn test_shell_command() {
let exit_code = shell_command("test 'a z' == \"a z\"", ".").unwrap();
assert_equal!(exit_code, 0);
}
#[test]
fn test_shell_command_stdout() {
let stdout = shell_command_stdout("mktemp -qd", ".").unwrap();
assert_equal!(Path::raw(stdout.trim()).exists(), true);
assert_equal!(Path::raw(stdout.trim()).is_directory(), true);
}