Run the example as a CI test

This commit is contained in:
Gary Guo 2023-05-07 00:29:39 +01:00
parent 863a10ed9a
commit c7f06f852b
2 changed files with 19 additions and 9 deletions

View File

@ -10,13 +10,22 @@ env:
CARGO_TERM_COLOR: always CARGO_TERM_COLOR: always
jobs: jobs:
build: test:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Build - name: Install Rust
run: cargo build --verbose run: rustup update nightly && rustup default nightly
- name: Run tests - name: Run Example Binary
run: cargo test --verbose run: (cargo run --release 2>&1 | tee ../run.log) || true
working-directory: example
- name: Check Log
run: |
grep "panicked at 'panic', example/src/main.rs:36:5" run.log
grep 'note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace' run.log
grep 'dropped: "string"' run.log
grep 'caught' run.log
grep "panicked at 'panic', example/src/main.rs:46:5" run.log
grep "panicked at 'panic on drop', example/src/main.rs:25:9" run.log
grep "thread panicked while processing panic. aborting." run.log

View File

@ -14,7 +14,7 @@ struct PrintOnDrop(String);
impl Drop for PrintOnDrop { impl Drop for PrintOnDrop {
fn drop(&mut self) { fn drop(&mut self) {
println!("dropped: {:?}", self.0); eprintln!("dropped: {:?}", self.0);
} }
} }
@ -26,6 +26,7 @@ impl Drop for PanicOnDrop {
} }
} }
#[track_caller]
fn foo() { fn foo() {
panic!("panic"); panic!("panic");
} }
@ -38,9 +39,9 @@ fn bar() {
fn main() { fn main() {
let _ = unwinding::panic::catch_unwind(|| { let _ = unwinding::panic::catch_unwind(|| {
bar(); bar();
println!("done"); eprintln!("done");
}); });
println!("caught"); eprintln!("caught");
let _p = PanicOnDrop; let _p = PanicOnDrop;
foo(); foo();
} }