Add more tests
This commit is contained in:
parent
ad9086f9bb
commit
fdf70d1e18
11
.github/workflows/ci.yml
vendored
11
.github/workflows/ci.yml
vendored
@ -28,13 +28,8 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
target: ${{ matrix.target }}
|
target: ${{ matrix.target }}
|
||||||
|
|
||||||
- name: Build example binary
|
- name: Build library
|
||||||
run: cargo build --release $BUILD_STD
|
run: cargo build --release $BUILD_STD
|
||||||
|
|
||||||
- name: Run example binary
|
- name: Run tests
|
||||||
run: (cargo run --release $BUILD_STD 2>&1 | tee ../run.log) || true
|
run: cargo test --release $BUILD_STD
|
||||||
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
|
|
||||||
|
@ -8,7 +8,12 @@ description = "Unwinding library in Rust and for Rust"
|
|||||||
repository = "https://github.com/nbdd0121/unwinding/"
|
repository = "https://github.com/nbdd0121/unwinding/"
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = ["cdylib", "example"]
|
members = [
|
||||||
|
"cdylib",
|
||||||
|
"test_crates/throw_and_catch",
|
||||||
|
"test_crates/catch_std_exception",
|
||||||
|
"test_crates/std_catch_exception",
|
||||||
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
gimli = { version = "0.28", default-features = false, features = ["read-core"] }
|
gimli = { version = "0.28", default-features = false, features = ["read-core"] }
|
||||||
|
@ -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
2
rust-toolchain
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[toolchain]
|
||||||
|
channel = "nightly"
|
8
test_crates/catch_std_exception/Cargo.toml
Normal file
8
test_crates/catch_std_exception/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "catch_std_exception"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
unwinding = { path = "../../", features = ["panic"] }
|
||||||
|
libc = "0.2"
|
9
test_crates/catch_std_exception/check.sh
Executable file
9
test_crates/catch_std_exception/check.sh
Executable 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
|
7
test_crates/catch_std_exception/src/main.rs
Normal file
7
test_crates/catch_std_exception/src/main.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
extern crate unwinding;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = unwinding::panic::catch_unwind(|| {
|
||||||
|
panic!();
|
||||||
|
});
|
||||||
|
}
|
8
test_crates/std_catch_exception/Cargo.toml
Normal file
8
test_crates/std_catch_exception/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "std_catch_exception"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
unwinding = { path = "../../", features = ["panic"] }
|
||||||
|
libc = "0.2"
|
9
test_crates/std_catch_exception/check.sh
Executable file
9
test_crates/std_catch_exception/check.sh
Executable 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
|
7
test_crates/std_catch_exception/src/main.rs
Normal file
7
test_crates/std_catch_exception/src/main.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
extern crate unwinding;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = std::panic::catch_unwind(|| {
|
||||||
|
unwinding::panic::begin_panic(Box::new("test"));
|
||||||
|
});
|
||||||
|
}
|
8
test_crates/throw_and_catch/Cargo.toml
Normal file
8
test_crates/throw_and_catch/Cargo.toml
Normal 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"
|
10
test_crates/throw_and_catch/check.sh
Executable file
10
test_crates/throw_and_catch/check.sh
Executable 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
20
tests/compile_tests.rs
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user