2019-02-03 02:16:53 +00:00
|
|
|
use std::process::Command;
|
|
|
|
|
2019-02-02 04:10:36 +00:00
|
|
|
#[test]
|
|
|
|
fn test_c_api() {
|
2019-02-03 02:16:53 +00:00
|
|
|
let project_tests_dir = concat!(env!("CARGO_MANIFEST_DIR"), "/tests");
|
2019-03-06 11:03:38 +00:00
|
|
|
|
2019-11-20 23:41:33 +00:00
|
|
|
let cmake_args = vec![
|
|
|
|
".",
|
|
|
|
#[cfg(feature = "wasi")]
|
|
|
|
"-DWASI_TESTS=ON",
|
|
|
|
];
|
|
|
|
// we use -f so it doesn't fail if the fiel doesn't exist
|
|
|
|
run_command("rm", project_tests_dir, vec!["-f", "CMakeCache.txt"]);
|
|
|
|
run_command("cmake", project_tests_dir, cmake_args);
|
2019-08-01 08:27:36 +00:00
|
|
|
run_command("make", project_tests_dir, vec!["-Wdev", "-Werror=dev"]);
|
|
|
|
run_command("make", project_tests_dir, vec!["test", "ARGS=\"-V\""]);
|
2019-02-03 02:16:53 +00:00
|
|
|
}
|
|
|
|
|
2019-08-01 08:27:36 +00:00
|
|
|
fn run_command(command_str: &str, dir: &str, args: Vec<&str>) {
|
|
|
|
println!("Running command: `{}` args: {:?}", command_str, args);
|
2019-03-06 11:03:38 +00:00
|
|
|
|
2019-02-03 02:16:53 +00:00
|
|
|
let mut command = Command::new(command_str);
|
2019-03-06 11:03:38 +00:00
|
|
|
|
2019-08-01 08:27:36 +00:00
|
|
|
command.args(&args);
|
2019-03-06 11:03:38 +00:00
|
|
|
|
2019-02-03 02:16:53 +00:00
|
|
|
command.current_dir(dir);
|
2019-03-06 11:03:38 +00:00
|
|
|
|
2019-02-03 02:16:53 +00:00
|
|
|
let result = command.output();
|
2019-03-06 11:03:38 +00:00
|
|
|
|
2019-02-03 02:16:53 +00:00
|
|
|
match result {
|
|
|
|
Ok(r) => {
|
|
|
|
println!("output:");
|
2019-03-06 11:03:38 +00:00
|
|
|
|
2019-02-03 02:16:53 +00:00
|
|
|
if let Some(code) = r.status.code() {
|
|
|
|
println!("status: {}", code);
|
|
|
|
} else {
|
|
|
|
println!("status: None");
|
|
|
|
}
|
2019-03-06 11:03:38 +00:00
|
|
|
|
2019-02-03 02:16:53 +00:00
|
|
|
println!("stdout:");
|
|
|
|
println!("{}", String::from_utf8_lossy(&r.stdout[..]));
|
|
|
|
println!("stderr:");
|
|
|
|
println!("{}", String::from_utf8_lossy(&r.stderr[..]));
|
2019-03-06 11:03:38 +00:00
|
|
|
|
2019-02-03 02:16:53 +00:00
|
|
|
if r.status.success() {
|
|
|
|
assert!(true)
|
|
|
|
} else {
|
|
|
|
panic!("Command failed with exit status: {:?}", r.status);
|
|
|
|
}
|
|
|
|
}
|
2019-03-06 11:03:38 +00:00
|
|
|
|
2019-02-03 02:16:53 +00:00
|
|
|
Err(e) => panic!("Command failed: {}", e),
|
|
|
|
}
|
2019-02-02 04:10:36 +00:00
|
|
|
}
|