use std::path::PathBuf;
use blr_lang::{compiler, runtime};
use expect_test::expect_file;
use snafu::Report;
use test_log::test;
use tokio::{fs::File, io::AsyncReadExt as _};
use tracing::debug;
macro_rules! test_case {
($name:ident) => {
#[test(tokio::test)]
async fn $name() {
let prefix = stringify!($name);
blr_type_check(&prefix).await
}
};
}
async fn blr_type_check(prefix: &str) {
let mut filepath = PathBuf::from("tests/type_check").join(prefix);
filepath.set_extension("blr");
let mut filepath_out = PathBuf::from("type_check").join(prefix);
filepath_out.set_extension("typ");
debug!(?filepath, ?filepath_out, "paths");
let mut src = String::new();
File::open(&filepath)
.await
.expect("should be able open test file")
.read_to_string(&mut src)
.await
.expect("should be able to read test file");
let mut item_source = compiler::ItemSource::default();
runtime::binary::register_binary_operator_functions(&mut item_source);
runtime::conv::register_conversion_funcs(&mut item_source);
let mut db = compiler::Database::new("..", src.to_string(), item_source);
let typed_mod = compiler::typed_mod(&mut db, "main").await;
match typed_mod {
Ok(typed_mod) => expect_file![filepath_out].assert_eq(&format!("{:?}", typed_mod)),
Err(e) => {
expect_file![filepath_out].assert_eq(&Report::from_error(e).to_string());
}
}
}
test_case!(missing_field);
test_case!(select_rows);