MCPcopy Create free account
hub / github.com/amber-lang/amber / test_runtime_errors

Function test_runtime_errors

src/tests/runtime.rs:12–36  ·  view source on GitHub ↗
(file: &str)

Source from the content-addressed store, hash-verified

10
11#[test_resources("src/tests/runtime/*.ab")]
12fn test_runtime_errors(file: &str) {
13 let code =
14 fs::read_to_string(file).unwrap_or_else(|_| panic!("Failed to open {file} test file"));
15
16 let output = extract_output(&code);
17
18 let re = Regex::new(&format!(r#"(?m)"?{output}"?$"#)).unwrap();
19
20 let target = AmberCompiler::resolve_target_shell(None);
21 let options = CompilerOptions::default().with_target(Some(target));
22 let mut compiler = AmberCompiler::new(code.to_string(), Some(file.to_string()), options);
23
24 match compiler.test_eval() {
25 Ok((output, status)) => {
26 assert!(status.code().unwrap_or(0) > 0);
27
28 assert!(
29 re.is_match(&output),
30 "Expected stderr to end with the specific error, but got:\n{:?}",
31 output
32 );
33 }
34 _ => panic!("Expected runtime error."),
35 }
36}

Callers

nothing calls this directly

Calls 4

extract_outputFunction · 0.85
with_targetMethod · 0.80
test_evalMethod · 0.80
to_stringMethod · 0.45

Tested by

no test coverage detected