Skip to content

Commit

Permalink
fix(assert): Show caller on panic
Browse files Browse the repository at this point in the history
Thanks to Rust 1.46, we can show the caller on panic, rather than
`assert_cmd`, as if `assert_cmd` was written with macros.

Fixes #133
  • Loading branch information
epage committed Sep 6, 2021
1 parent 4318788 commit 150d7be
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
- name: No-default features
run: cargo test --workspace --no-default-features
msrv:
name: "Check MSRV: 1.44.0"
name: "Check MSRV: 1.46.0"
needs: smoke
runs-on: ubuntu-latest
steps:
Expand All @@ -78,7 +78,7 @@ jobs:
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.44.0 # MSRV
toolchain: 1.46.0 # MSRV
profile: minimal
override: true
- uses: Swatinem/rust-cache@v1
Expand Down Expand Up @@ -133,7 +133,7 @@ jobs:
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.44.0 # MSRV
toolchain: 1.46.0 # MSRV
profile: minimal
override: true
components: clippy
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rust-next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ jobs:
strategy:
matrix:
rust:
- 1.44.0 # MSRV
- 1.46.0 # MSRV
- stable
continue-on-error: ${{ matrix.rust != '1.44.0' }} # MSRV
continue-on-error: ${{ matrix.rust != '1.46.0' }} # MSRV
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
<!-- next-header -->
## [Unreleased] - ReleaseDate

#### Fixes

- Show caller for panic, rather than `assert_cmd`

## [2.0.0] - 2021-08-05

### Breaking Changes
Expand Down
7 changes: 7 additions & 0 deletions src/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ impl Assert {
/// .assert()
/// .success();
/// ```
#[track_caller]
pub fn success(self) -> Self {
self.try_success().unwrap_or_else(AssertError::panic)
}
Expand Down Expand Up @@ -179,6 +180,7 @@ impl Assert {
/// .assert()
/// .failure();
/// ```
#[track_caller]
pub fn failure(self) -> Self {
self.try_failure().unwrap_or_else(AssertError::panic)
}
Expand All @@ -192,6 +194,7 @@ impl Assert {
}

/// Ensure the command aborted before returning a code.
#[track_caller]
pub fn interrupted(self) -> Self {
self.try_interrupted().unwrap_or_else(AssertError::panic)
}
Expand Down Expand Up @@ -252,6 +255,7 @@ impl Assert {
/// .code(&[2, 42] as &[i32]);
/// ```
///
#[track_caller]
pub fn code<I, P>(self, pred: I) -> Self
where
I: IntoCodePredicate<P>,
Expand Down Expand Up @@ -349,6 +353,7 @@ impl Assert {
/// .stdout("hello\n");
/// ```
///
#[track_caller]
pub fn stdout<I, P>(self, pred: I) -> Self
where
I: IntoOutputPredicate<P>,
Expand Down Expand Up @@ -444,6 +449,7 @@ impl Assert {
/// .stderr("world\n");
/// ```
///
#[track_caller]
pub fn stderr<I, P>(self, pred: I) -> Self
where
I: IntoOutputPredicate<P>,
Expand Down Expand Up @@ -1019,6 +1025,7 @@ enum AssertReason {
}

impl AssertError {
#[track_caller]
fn panic<T>(self) -> T {
panic!("{}", self)
}
Expand Down

0 comments on commit 150d7be

Please sign in to comment.