Various quality-of-life improvements (ideas from @33577 )

* Very basic `hello_main.c`
* Big starting hint to `write_c`
* Better error messages on failed test
  * TODO: also improve it for asmgen, but not sure how to do it in a good way
This commit is contained in:
Janggun Lee
2025-02-25 00:28:55 +09:00
parent fad9d02fea
commit 72dadc608d
50 changed files with 290 additions and 182 deletions

View File

@@ -15,7 +15,6 @@ where
continue;
}
println!("[testing {path:?}]");
f(&path);
}
}
@@ -44,6 +43,8 @@ fn test_opt_between_dirs<O: Optimize<ir::TranslationUnit>>(from: &Path, to: &Pat
}
}
const HELLO_MAIN: &str = "hello_main";
const IRGEN_SMALL_TEST_IGNORE_LIST: [&str; 12] = [
"examples/c/array.c",
"examples/c/array2.c",
@@ -84,14 +85,24 @@ const ASMGEN_SMALL_TEST_IGNORE_LIST: [&str; 12] = [
#[test]
fn test_examples_write_c() {
test_dir(Path::new("examples/c"), OsStr::new("c"), test_write_c);
println!("[testing write_c for \"examples/c/{HELLO_MAIN}.c\"]");
test_write_c(Path::new(&format!("examples/c/{HELLO_MAIN}.c")));
test_dir(Path::new("examples/c"), OsStr::new("c"), |path| {
if !path.to_str().unwrap().contains(HELLO_MAIN) {
println!("[testing write_c for {path:?}]");
test_write_c(path)
}
});
}
#[test]
fn test_examples_irgen_small() {
println!("[testing irgen for \"examples/c/{HELLO_MAIN}.c\"]");
test_irgen(Path::new(&format!("examples/c/{HELLO_MAIN}.c")));
test_dir(Path::new("examples/c"), OsStr::new("c"), |path| {
let path_str = &path.to_str().expect("`path` must be transformed to `&str`");
if !IRGEN_SMALL_TEST_IGNORE_LIST.contains(path_str) {
if !IRGEN_SMALL_TEST_IGNORE_LIST.contains(path_str) && !path_str.contains(HELLO_MAIN) {
println!("[testing irgen for {path:?}]");
test_irgen(path)
}
});
@@ -101,7 +112,8 @@ fn test_examples_irgen_small() {
fn test_examples_irgen_large() {
test_dir(Path::new("examples/c"), OsStr::new("c"), |path| {
let path_str = &path.to_str().expect("`path` must be transformed to `&str`");
if IRGEN_SMALL_TEST_IGNORE_LIST.contains(path_str) {
if IRGEN_SMALL_TEST_IGNORE_LIST.contains(path_str) && !path_str.contains(HELLO_MAIN) {
println!("[testing irgen for {path:?}]");
test_irgen(path)
}
});
@@ -201,6 +213,14 @@ fn test_examples_optimize() {
#[test]
fn test_examples_asmgen_small() {
for dir in ASMGEN_TEST_DIR_LIST.iter() {
test_dir(Path::new(dir), OsStr::new("ir"), |path| {
if path.to_str().unwrap().contains(HELLO_MAIN) {
println!("[testing asmgen for {path:?}]");
test_asmgen(path)
}
});
}
for dir in ASMGEN_TEST_DIR_LIST.iter() {
test_dir(Path::new(dir), OsStr::new("ir"), |path| {
let file_name = &path
@@ -208,7 +228,9 @@ fn test_examples_asmgen_small() {
.expect("`path` must have a file name")
.to_str()
.expect("must be transformable to `&str`");
if !ASMGEN_SMALL_TEST_IGNORE_LIST.contains(file_name) {
if !ASMGEN_SMALL_TEST_IGNORE_LIST.contains(file_name) && !file_name.contains(HELLO_MAIN)
{
println!("[testing asmgen for {path:?}]");
test_asmgen(path)
}
});
@@ -224,7 +246,9 @@ fn test_examples_asmgen_large() {
.expect("`path` must have a file name")
.to_str()
.expect("must be transformable to `&str`");
if ASMGEN_SMALL_TEST_IGNORE_LIST.contains(file_name) {
if ASMGEN_SMALL_TEST_IGNORE_LIST.contains(file_name) && !file_name.contains(HELLO_MAIN)
{
println!("[testing asmgen for {path:?}]");
test_asmgen(path)
}
});