Skip to content

Commit

Permalink
Run cmake tests as part of a rust test
Browse files Browse the repository at this point in the history
  • Loading branch information
bjfish committed Feb 3, 2019
1 parent 5d9e05c commit 6f7db90
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ test:
# cargo test --all -- --test-threads=1 $(runargs)
# cargo test --all --exclude wasmer-emscripten -- --test-threads=1 $(runargs)
cargo test -p wasmer-spectests -- --test-threads=1 $(runargs)
cargo test -p wasmer-runtime-c-api -- --nocapture

release:
# If you are in OS-X, you will need mingw-w64 for cross compiling to windows
Expand Down
6 changes: 4 additions & 2 deletions lib/runtime-c-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
Run `make capi` from wasmer project root directory

## Running tests
`cmake . && make && make test` from runtime-c-api/tests directory
(TODO run this within a rust test)
The tests can be run via `cargo test`, E.g. `cargo test -p wasmer-runtime-c-api -- --nocapture`

*Running manually*
`cmake . && make && make test` from the `lib/runtime-c-api/tests` directory
37 changes: 36 additions & 1 deletion lib/runtime-c-api/tests/runtime_c_api_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@
use std::process::Command;

#[test]
fn test_c_api() {
// TODO run `cmake . && make && make test`
let project_tests_dir = concat!(env!("CARGO_MANIFEST_DIR"), "/tests");
run_command("cmake", project_tests_dir, Some("."));
run_command("make", project_tests_dir, None);
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);
let mut command = Command::new(command_str);
if let Some(a) = arg {
command.arg(a);
}
command.current_dir(dir);
let result = command.output();
match result {
Ok(r) => {
println!("output:");
if let Some(code) = r.status.code() {
println!("status: {}", code);
} else {
println!("status: None");
}
println!("stdout:");
println!("{}", String::from_utf8_lossy(&r.stdout[..]));
println!("stderr:");
println!("{}", String::from_utf8_lossy(&r.stderr[..]));
if r.status.success() {
assert!(true)
} else {
panic!("Command failed with exit status: {:?}", r.status);
}
}
Err(e) => panic!("Command failed: {}", e),
}
}

0 comments on commit 6f7db90

Please sign in to comment.