[fine] Test for function return type mismatch
This commit is contained in:
parent
d893002ec2
commit
44bc072b04
4 changed files with 23 additions and 6 deletions
|
|
@ -87,6 +87,11 @@ fn generate_test_for_file(path: PathBuf) -> String {
|
|||
assertions.push(quote! {
|
||||
crate::assert_eval_ok(&_tree, &_lines, #expected);
|
||||
});
|
||||
} else if let Some(line) = line.strip_prefix("@check-error:") {
|
||||
let expected = line.trim();
|
||||
assertions.push(quote! {
|
||||
crate::assert_check_error(&_tree, &_lines, #expected);
|
||||
});
|
||||
} else if line.starts_with("@") {
|
||||
panic!("Test file {display_path} has unknown directive: {line}");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -664,11 +664,6 @@ impl<'a> Semantics<'a> {
|
|||
|
||||
// NOTE: These return `None` if they encounter some problem.
|
||||
let result = result.unwrap_or(Type::Error);
|
||||
|
||||
if result.is_error() {
|
||||
eprintln!("OH NO AN ERROR AT {}: {:?}", t.index(), tree);
|
||||
}
|
||||
|
||||
self.types.borrow_mut()[t.index()] = Incremental::Complete(result.clone());
|
||||
result
|
||||
}
|
||||
|
|
|
|||
|
|
@ -259,7 +259,6 @@ fn assert_no_errors(tree: &SyntaxTree, lines: &Lines) {
|
|||
);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn assert_eval_ok(tree: &SyntaxTree, lines: &Lines, expected: &str) {
|
||||
let semantics = Semantics::new(tree, lines);
|
||||
|
||||
|
|
@ -284,4 +283,17 @@ fn assert_eval_ok(tree: &SyntaxTree, lines: &Lines, expected: &str) {
|
|||
}
|
||||
}
|
||||
|
||||
fn assert_check_error(tree: &SyntaxTree, lines: &Lines, expected: &str) {
|
||||
let semantics = Semantics::new(tree, lines);
|
||||
check(&semantics);
|
||||
|
||||
let errors = semantics.snapshot_errors();
|
||||
semantic_assert!(
|
||||
&semantics,
|
||||
None,
|
||||
errors.iter().any(|e| e.message == expected),
|
||||
"Unable to find the expected error message '{expected}'"
|
||||
);
|
||||
}
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/generated_tests.rs"));
|
||||
|
|
|
|||
5
fine/tests/expression/errors/return_type_mismatch.fine
Normal file
5
fine/tests/expression/errors/return_type_mismatch.fine
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
fun test() -> bool {
|
||||
32
|
||||
}
|
||||
|
||||
// @check-error: the body of this function yields a value of type `f64`, but callers expect this function to produce a `bool`
|
||||
Loading…
Add table
Add a link
Reference in a new issue