edlang/lib/edlang_driver/tests/programs.rs
2024-02-14 11:21:33 +01:00

24 lines
1,011 B
Rust

use crate::common::{compile_program, run_program};
use test_case::test_case;
mod common;
#[test_case(include_str!("programs/simple.ed"), "simple", false, 0, &["1"] ; "simple.ed 1")]
#[test_case(include_str!("programs/simple.ed"), "simple", false, 1, &["a", "b"] ; "simple.ed 3")]
#[test_case(include_str!("programs/basic_ifs.ed"), "basic_ifs", false, 9, &[] ; "basic_ifs")]
#[test_case(include_str!("programs/while.ed"), "while", false, 10, &[] ; "r#while")]
#[test_case(include_str!("programs/factorial.ed"), "factorial", false, 6, &[] ; "factorial")]
fn example_tests(source: &str, name: &str, is_library: bool, status_code: i32, args: &[&str]) {
let program = compile_program(source, name, is_library).unwrap();
assert!(program.binary_file.exists(), "program not compiled");
let result = run_program(&program.binary_file, args).unwrap();
assert_eq!(
result.status.code().unwrap(),
status_code,
"Program {} returned a unexpected status code",
name
);
}