diff --git a/src/ast.rs b/src/ast.rs index 3d4e890b..5e99c454 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -505,18 +505,17 @@ impl Book { } let mut book = hvm::Book { defs: Vec::new() }; for (fid, name) in &fid_to_name { - if let Some(ast_def) = self.defs.get(name) { - let mut def = hvm::Def { - name: name.clone(), - safe: true, - root: hvm::Port(0), - rbag: vec![], - node: vec![], - vars: 0, - }; - ast_def.build(&mut def, &name_to_fid, &mut BTreeMap::new()); - book.defs.push(def); - } + let ast_def = self.defs.get(name).expect("missing `@main` definition"); + let mut def = hvm::Def { + name: name.clone(), + safe: true, + root: hvm::Port(0), + rbag: vec![], + node: vec![], + vars: 0, + }; + ast_def.build(&mut def, &name_to_fid, &mut BTreeMap::new()); + book.defs.push(def); } return book; } diff --git a/tests/programs/empty.hvm b/tests/programs/empty.hvm new file mode 100644 index 00000000..e69de29b diff --git a/tests/run.rs b/tests/run.rs index 743c0add..baf805bc 100644 --- a/tests/run.rs +++ b/tests/run.rs @@ -60,7 +60,7 @@ fn execute_hvm(args: &[&OsStr]) -> Result> { stderr.read_to_string(&mut output)?; Ok(if !status.success() { - format!("exited with code {status}:\n{output}") + format!("{status}\n{output}") } else { parse_output(&output).unwrap_or_else(|err| { panic!("error parsing output:\n{err}\n\n{output}") diff --git a/tests/snapshots/run__file@empty.hvm.snap b/tests/snapshots/run__file@empty.hvm.snap new file mode 100644 index 00000000..b5b4735e --- /dev/null +++ b/tests/snapshots/run__file@empty.hvm.snap @@ -0,0 +1,9 @@ +--- +source: tests/run.rs +expression: rust_output +input_file: tests/programs/empty.hvm +--- +exit status: 101 +thread 'main' panicked at src/ast.rs:508:41: +missing `@main` definition +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace