Add tests for user crash

This commit is contained in:
Ayaz Hafiz 2022-11-22 16:28:39 -06:00
parent c8accc90e8
commit 9201cf0b32
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
3 changed files with 77 additions and 4 deletions

View file

@ -0,0 +1,68 @@
use indoc::indoc;
#[cfg(feature = "gen-llvm")]
use crate::helpers::llvm::expect_runtime_error_panic;
#[cfg(feature = "gen-wasm")]
use crate::helpers::wasm::expect_runtime_error_panic;
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[should_panic = r#"Roc failed with message: "hello crash""#]
fn crash_literal() {
expect_runtime_error_panic!(indoc!(
r#"
app "test" provides [main] to "./platform"
main = if Bool.true then crash "hello crash" else 1u8
"#
));
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[should_panic = r#"Roc failed with message: "hello crash""#]
fn crash_variable() {
expect_runtime_error_panic!(indoc!(
r#"
app "test" provides [main] to "./platform"
main =
msg = "hello crash"
if Bool.true then crash msg else 1u8
"#
));
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[should_panic = r#"Roc failed with message: "turns out this was fallible""#]
fn crash_in_call() {
expect_runtime_error_panic!(indoc!(
r#"
app "test" provides [main] to "./platform"
getInfallible = \result -> when result is
Ok x -> x
_ -> crash "turns out this was fallible"
main =
x : [Ok U64, Err Str]
x = Err ""
getInfallible x
"#
));
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[should_panic = r#"Roc failed with message: "no new even primes""#]
fn crash_in_passed_closure() {
expect_runtime_error_panic!(indoc!(
r#"
app "test" provides [main] to "./platform"
main = List.map [1, 2, 3] \n -> if n == 2 then crash "no new even primes" else ""
"#
));
}