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-02-03 02:16:53 +00:00
|
|
|
run_command("cmake", project_tests_dir, Some("."));
|
2019-03-06 11:03:38 +00:00
|
|
|
run_command("make", project_tests_dir, Some("-Wdev -Werror=dev"));
|
2019-02-03 02:16:53 +00:00
|
|
|
run_command("make", project_tests_dir, Some("test"));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run_command(command_str: &str, dir: &str, arg: Option<&str>) {
|
|
|
|
println!("Running command: `{}` arg: {:?}", command_str, arg);
|
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-02-03 02:16:53 +00:00
|
|
|
if let Some(a) = arg {
|
|
|
|
command.arg(a);
|
|
|
|
}
|
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
|
|
|
}
|