Skip to content

Commit

Permalink
Test some more
Browse files Browse the repository at this point in the history
  • Loading branch information
Quaqqer committed Apr 29, 2024
1 parent 3458e6f commit d086b7c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 22 deletions.
11 changes: 10 additions & 1 deletion crates/saft-bytecode/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,16 @@ impl Vm {
let op = call_frame.chunk.get_op(call_frame.i).unwrap().clone();
let s = call_frame.chunk.get_span(call_frame.i).unwrap().clone();

self.exec_op(&op, &s, constants)?;
match self.exec_op(&op, &s, constants) {
Ok(_) => {}
Err(err) => {
// Pop all call stacks but the global one
while self.call_stack.len() > 1 {
self.call_stack.pop();
}
return Err(err);
}
};
}

Ok(())
Expand Down
2 changes: 2 additions & 0 deletions crates/saft-macro/src/discover_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ pub fn expand_discover_tests(
let node_quote = create_tests(node, test_fn_ident);
toks.push(quote! {
mod #id {
use super::#test_fn_ident;

#node_quote
}

Expand Down
9 changes: 9 additions & 0 deletions tests/res/tests/items/functions/assignment.saf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn f(x) {
print("Okay boomer " + x)
}

x := f;
x(1);

# output:
# Okay boomer 1
8 changes: 8 additions & 0 deletions tests/res/tests/items/functions/order.saf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
printadd(1, 2);

fn printadd(a, b) {
print(a + b);
}

# output:
# 3
41 changes: 20 additions & 21 deletions tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
#[cfg(test)]
mod test {
use assert_cmd::Command;
use pretty_assertions::assert_eq;
use saft_macro::discover_tests;
#![cfg(test)]

#[discover_tests(root = "./tests/res/tests", glob = "**/[!_]*.saf")]
fn test(file_name: &str) {
let mut cmd = Command::cargo_bin("saft").unwrap();
cmd.arg(file_name);
use assert_cmd::Command;
use pretty_assertions::assert_eq;
use saft_macro::discover_tests;

let got = String::from_utf8(cmd.unwrap().stdout).unwrap();
#[discover_tests(root = "./tests/res/tests", glob = "**/[!_]*.saf")]
fn test_file(file_name: &str) {
let mut cmd = Command::cargo_bin("saft").unwrap();
cmd.arg(file_name);

let mut expected = Vec::new();
let got = String::from_utf8(cmd.unwrap().stdout).unwrap();

let mut got_output = false;
for line in std::fs::read_to_string(file_name).unwrap().lines() {
if let Some(comment) = line.strip_prefix("# ") {
if got_output {
expected.push(comment.to_string());
} else if comment == "output:" {
got_output = true;
}
let mut expected = Vec::new();

let mut got_output = false;
for line in std::fs::read_to_string(file_name).unwrap().lines() {
if let Some(comment) = line.strip_prefix("# ") {
if got_output {
expected.push(comment.to_string());
} else if comment == "output:" {
got_output = true;
}
}

assert_eq!(got.trim(), expected.join("\n").trim());
}

assert_eq!(got.trim(), expected.join("\n").trim());
}

0 comments on commit d086b7c

Please sign in to comment.