diff --git a/.gitignore b/.gitignore index 3666d86..09dbe4c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ target/ .vscode/ examples_out/ +tests_out/ book/ \ No newline at end of file diff --git a/src/tests/test_examples.rs b/src/tests/test_examples.rs index eee69c5..40393b4 100644 --- a/src/tests/test_examples.rs +++ b/src/tests/test_examples.rs @@ -58,3 +58,46 @@ fn test_examples() -> Result<(), Error> { } Ok(()) } + +#[test] +#[cfg(feature = "backend_node")] +fn test_testcases() -> Result<(), Error> { + let dir = std::env::current_dir().unwrap(); + + let tests = std::fs::read_dir(dir.join("tests"))?; + + let _ = fs::create_dir("tests_out"); + + for ex in tests { + let example = ex?; + let in_file = dir.join("tests").join(example.file_name()); + let out_file = dir.join("tests_out").join( + example + .file_name() + .into_string() + .unwrap() + .replace(".sb", ".js"), + ); + let success = Command::new("cargo") + .arg("run") + .arg("build") + .arg(&in_file) + .arg("-o") + .arg(&out_file) + .spawn()? + .wait()? + .success(); + assert_eq!(success, true, "{:?}", &in_file); + + let node_installed = Command::new("node").arg("-v").spawn()?.wait()?.success(); + if node_installed { + let execution = Command::new("node") + .arg(out_file) + .spawn()? + .wait()? + .success(); + assert_eq!(execution, true, "{:?}", &in_file) + } + } + Ok(()) +} diff --git a/tests/function_with_return_type.sb b/tests/function_with_return_type.sb new file mode 100644 index 0000000..7d6dc27 --- /dev/null +++ b/tests/function_with_return_type.sb @@ -0,0 +1,8 @@ +fn main() { + let x = add_one(2) + println(x) +} + +fn add_one(x: int): int { + return x + 1 +} \ No newline at end of file