Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test test_cashflows::test_non_matching_dates_add Fails with SIGABRT Signal #233

Open
joaquinbejar opened this issue Jun 25, 2024 · 1 comment

Comments

@joaquinbejar
Copy link
Contributor

I am encountering an issue where the test test_non_matching_dates_add fails with a SIGABRT signal. The test is supposed to panic with the message "Dates must match." when adding SimpleCashflow instances with non-matching dates. However, instead of the expected panic, I am getting a SIGABRT signal, which indicates an abort signal in the process.

RUST_BACKTRACE=1 cargo test test_non_matching_dates_add -- --nocapture

running 1 test
thread 'cashflows::cashflow::test_cashflows::test_non_matching_dates_add' panicked at src/cashflows/cashflow.rs:72:9:
assertion `left == right` failed: Dates must match.
  left: 2024-06-25 4:14:44.398515 +00:00:00
 right: 2024-06-26 4:14:44.398515 +00:00:00
stack backtrace:
libunwind: stepWithCompactEncoding - invalid compact unwind encoding
error: test failed, to rerun pass `--lib`

Caused by:
  process didn't exit successfully: `RustQuant-c0a882e3717c1824 test_non_matching_dates_add --nocapture` (signal: 6, SIGABRT: process abort signal)

Original test

    // Test for non-matching dates during addition (should panic).
    #[test]
    #[should_panic(expected = "Dates must match.")]
    fn test_non_matching_dates_add() {
        let date1 = OffsetDateTime::now_utc();
        let date2 = date1 + Duration::days(1);
        let cf1 = SimpleCashflow::new(100.0, date1);
        let cf2 = SimpleCashflow::new(50.0, date2);
        let _ = cf1 + cf2;
    }

I added this test that failed as well.

    #[test]
    fn test_non_matching_dates_add_unwing() {
        let result = panic::catch_unwind(|| {
            let date1 = OffsetDateTime::now_utc();
            let date2 = date1 + Duration::days(1);
            let cf1 = SimpleCashflow::new(100.0, date1);
            let cf2 = SimpleCashflow::new(50.0, date2);
            let _ = cf1 + cf2;
        });

        assert!(result.is_err());
        if let Err(err) = result {
            if let Some(string) = err.downcast_ref::<String>() {
                assert_eq!(string, "Dates must match.");
            } else if let Some(&str) = err.downcast_ref::<&str>() {
                assert_eq!(str, "Dates must match.");
            } else {
                panic!("Unexpected panic message");
            }
        }
    }
    ```
@avhz
Copy link
Owner

avhz commented Jun 25, 2024

The assertion fails as expected, so the test passes.

I am not sure why you're getting a SIGABRT. Are you using stable or nightly ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants