Add more tests

This commit is contained in:
Gary Guo 2023-10-28 01:06:27 +01:00
parent ad9086f9bb
commit fdf70d1e18
14 changed files with 97 additions and 17 deletions

View File

@ -28,13 +28,8 @@ jobs:
with:
target: ${{ matrix.target }}
- name: Build example binary
- name: Build library
run: cargo build --release $BUILD_STD
- name: Run example binary
run: (cargo run --release $BUILD_STD 2>&1 | tee ../run.log) || true
working-directory: example
- name: Check log
run: |
grep -Pz 'panicked at example/src/main.rs:36:5:\npanic\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\ndropped: "string"\ncaught\npanicked at example/src/main.rs:46:5:\npanic\npanicked at example/src/main.rs:25:9:\npanic on drop\n( *\d+:.*\n)+thread panicked while processing panic\. aborting\.' run.log
- name: Run tests
run: cargo test --release $BUILD_STD

View File

@ -8,7 +8,12 @@ description = "Unwinding library in Rust and for Rust"
repository = "https://github.com/nbdd0121/unwinding/"
[workspace]
members = ["cdylib", "example"]
members = [
"cdylib",
"test_crates/throw_and_catch",
"test_crates/catch_std_exception",
"test_crates/std_catch_exception",
]
[dependencies]
gimli = { version = "0.28", default-features = false, features = ["read-core"] }

View File

@ -1,8 +0,0 @@
[package]
name = "example"
version = "0.1.0"
edition = "2018"
[dependencies]
unwinding = { path = "../", features = ["system-alloc", "personality", "panic-handler"] }
libc = "0.2"

2
rust-toolchain Normal file
View File

@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"

View File

@ -0,0 +1,8 @@
[package]
name = "catch_std_exception"
version = "0.1.0"
edition = "2018"
[dependencies]
unwinding = { path = "../../", features = ["panic"] }
libc = "0.2"

View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -o pipefail
trap "rm -f run.log" EXIT
cargo run --release $BUILD_STD 2>&1 | tee run.log
if [ $? -ne 134 ]; then
echo process is not aborted
exit 1
fi
grep -Pz 'panicked at test_crates/catch_std_exception/src/main.rs:5:9:\nexplicit panic\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace' run.log

View File

@ -0,0 +1,7 @@
extern crate unwinding;
fn main() {
let _ = unwinding::panic::catch_unwind(|| {
panic!();
});
}

View File

@ -0,0 +1,8 @@
[package]
name = "std_catch_exception"
version = "0.1.0"
edition = "2018"
[dependencies]
unwinding = { path = "../../", features = ["panic"] }
libc = "0.2"

View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -o pipefail
trap "rm -f run.log" EXIT
cargo run --release $BUILD_STD 2>&1 | tee run.log
if [ $? -ne 134 ]; then
echo process is not aborted
exit 1
fi
grep -Pz 'fatal runtime error: Rust cannot catch foreign exceptions' run.log

View File

@ -0,0 +1,7 @@
extern crate unwinding;
fn main() {
let _ = std::panic::catch_unwind(|| {
unwinding::panic::begin_panic(Box::new("test"));
});
}

View File

@ -0,0 +1,8 @@
[package]
name = "throw_and_catch"
version = "0.1.0"
edition = "2018"
[dependencies]
unwinding = { path = "../..", features = ["system-alloc", "personality", "panic-handler"] }
libc = "0.2"

View File

@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -o pipefail
trap "rm -f run.log" EXIT
cargo run --release $BUILD_STD 2>&1 | tee run.log
if [ $? -ne 134 ]; then
echo process is not aborted
exit 1
fi
grep -Pz 'panicked at test_crates/throw_and_catch/src/main.rs:36:5:\npanic\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\ndropped: "string"\ncaught\npanicked at test_crates/throw_and_catch/src/main.rs:46:5:\npanic\npanicked at test_crates/throw_and_catch/src/main.rs:25:9:\npanic on drop\n( *\d+:.*\n)+thread panicked while processing panic\. aborting\.' run.log

20
tests/compile_tests.rs Normal file
View File

@ -0,0 +1,20 @@
use std::process::Command;
#[test]
fn main() {
let dir = env!("CARGO_MANIFEST_DIR");
let tests = [
"throw_and_catch",
"catch_std_exception",
"std_catch_exception",
];
for test in tests {
let status = Command::new("./check.sh")
.current_dir(format!("{dir}/test_crates/{test}"))
.status()
.unwrap();
assert!(status.success());
}
}