improve output of C tests

This commit is contained in:
Dustin J. Mitchell
2022-02-13 21:02:18 +00:00
parent 41a578ab2b
commit ca904d6288
5 changed files with 59 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
use lazy_static::lazy_static;
use std::sync::Mutex;
use tempfile::TempDir;
lazy_static! {
// the C library running the tests is not reentrant, so we use a mutex to ensure that only one
@@ -11,8 +12,18 @@ macro_rules! suite(
{ $s:ident } => {
#[test]
fn $s() {
let _guard = MUTEX.lock().unwrap();
assert_eq!(integration_tests::bindings_tests::$s(), 0);
let tmp_dir = TempDir::new().expect("TempDir failed");
let (res, output) = {
let _guard = MUTEX.lock().unwrap();
// run the tests in the temp dir (NOTE: this must be inside
// the mutex guard!)
std::env::set_current_dir(tmp_dir.as_ref()).unwrap();
integration_tests::bindings_tests::$s()
};
println!("{}", output);
if res != 0 {
assert!(false, "test failed");
}
}
};
);