Skip to content

Commit

Permalink
rust-rewrite: Improved gernerator test output.
Browse files Browse the repository at this point in the history
  • Loading branch information
schilkp committed May 8, 2024
1 parent da1ebfc commit 588869c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ jobs:
toolchain: stable
- uses: carlosperate/arm-none-eabi-gcc-action@v1
- name: Run generator tests.
run: REGINALD_TEST_C_FUNCPACK_ADDITIONAL_COMPILERS=arm-none-eabi-gcc cargo test --workspace -- --ignored
run: REGINALD_TEST_C_FUNCPACK_ADDITIONAL_COMPILERS=arm-none-eabi-gcc cargo test --workspace -- --ignored --show-output
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
full_check:
cargo test --workspace
REGINALD_TEST_C_FUNCPACK_ADDITIONAL_COMPILERS=arm-none-eabi-gcc cargo test --workspace -- --ignored
REGINALD_TEST_C_FUNCPACK_ADDITIONAL_COMPILERS=arm-none-eabi-gcc cargo test --workspace -- --ignored --show-output
cargo fmt --check
cargo clippy --all-features --workspace
@echo "ALL CHECKS OK"
Expand Down
15 changes: 10 additions & 5 deletions reginald_codegen/tests/generator_c_funcpack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,20 @@ fn test_generated_code(test_dir: &TempDir, extra_cflags: &[&str], extra_sources:
compile_args.push("-o".to_string());
compile_args.push(test_exe.to_string());

println!("Compiling...");
println!("Args:");
println!(" GCC host args:");
for arg in &compile_args {
println!(" {}", arg);
println!(" {}", arg);
}
println!(" Compiling for host...");
let compile_output = Command::new("gcc").args(&compile_args).output().unwrap();
print_cmd_output(&compile_output);
assert!(compile_output.status.success());

println!("Testing...");
println!(" Running tests...");
let test_output = Command::new(test_exe).output().unwrap();
print_cmd_output(&test_output);
assert!(test_output.status.success());
println!(" >>> OK!");

// ==== Compile with ADDITIONAL_COMPILERS ====

Expand All @@ -83,7 +84,11 @@ fn test_generated_code(test_dir: &TempDir, extra_cflags: &[&str], extra_sources:
// only compile to object, don't link:
compile_args.push("-c".to_string());

println!("Compiling with `{}`...", compiler);
println!(" Compiling with `{}`...", compiler);
println!(" Args:");
for arg in &compile_args {
println!(" {}", arg);
}
let compile_output = Command::new(compiler)
.current_dir(test_dir.path())
.args(&compile_args)
Expand Down
10 changes: 6 additions & 4 deletions reginald_codegen/tests/generator_c_macromap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,21 @@ fn test_generated_code(test_dir: &TempDir, extra_cflags: &[&str], extra_sources:
compile_args.push("-o".to_string());
compile_args.push(test_exe.to_string());

println!("Compiling...");
println!("Args:");
println!(" GCC host args:");
for arg in &compile_args {
println!(" {}", arg);
println!(" {}", arg);
}
println!(" Compiling for host...");
let compile_output = Command::new("gcc").args(&compile_args).output().unwrap();
print_cmd_output(&compile_output);
assert!(compile_output.status.success());

println!("Testing...");
println!(" Running tests...");
let test_output = Command::new(test_exe).output().unwrap();
print_cmd_output(&test_output);
assert!(test_output.status.success());

println!(" >>> OK!");
}

fn finish_test(d: TempDir) {
Expand Down
17 changes: 11 additions & 6 deletions reginald_codegen/tests/generator_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ fn find_test_map_file() -> PathBuf {
}

pub fn print_cmd_output(out: &Output) {
println!("EXIT STATUS:");
println!("{}", &out.status);
println!(" {}", &out.status);
if !out.stdout.is_empty() {
println!("STDOUT:");
println!("{}", String::from_utf8(out.stdout.clone()).unwrap());
println!(" stdout:");
let stdout = String::from_utf8(out.stdout.clone()).unwrap();
for line in stdout.lines() {
println!(" > {line}");
}
}
if !out.stderr.is_empty() {
println!("STDERR:");
println!("{}", String::from_utf8(out.stderr.clone()).unwrap());
println!(" stderr:");
let stderr = String::from_utf8(out.stderr.clone()).unwrap();
for line in stderr.lines() {
println!(" > {line}");
}
}
}

0 comments on commit 588869c

Please sign in to comment.