use std::path::PathBuf;
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_run(&prefix).await
}
};
}
async fn blr_run(prefix: &str) {
let mut filepath = PathBuf::from("tests/integration").join(prefix);
filepath.set_extension("blr");
let mut filepath_out = PathBuf::from("integration").join(prefix);
filepath_out.set_extension("out");
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");
match blr_lang::run(&src, "..").await {
Ok(value) => {
expect_file![filepath_out].assert_eq(&blr_lang::val_to_string(value));
}
Err(e) => {
expect_file![filepath_out].assert_eq(&Report::from_error(e).to_string());
}
}
}
test_case!(binary_ops);
test_case!(closure);
test_case!(df);
test_case!(external);
test_case!(external_record);
test_case!(external_nested_record);
test_case!(explicit_main);
test_case!(first_class_record_func);
test_case!(import);
test_case!(one_plus_one);
test_case!(partial_app);
test_case!(print);
test_case!(poly_id);
test_case!(poly_item);
test_case!(record_value);
test_case!(record_concat);
test_case!(record_func);
test_case!(record_nested);
test_case!(record_poly);
test_case!(record_poly_simple);
test_case!(record_select);
test_case!(return_one);
test_case!(string);
test_case!(sums);