From 588869c5d36855622a503b7a6f66932b45df869b Mon Sep 17 00:00:00 2001 From: schilkp Date: Wed, 8 May 2024 09:25:49 +0200 Subject: [PATCH] rust-rewrite: Improved gernerator test output. --- .github/workflows/ci.yml | 2 +- justfile | 2 +- .../tests/generator_c_funcpack/mod.rs | 15 ++++++++++----- .../tests/generator_c_macromap/mod.rs | 10 ++++++---- reginald_codegen/tests/generator_tests.rs | 17 +++++++++++------ 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f0cd25..0c8fb1e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/justfile b/justfile index fcadb1f..e13c31b 100644 --- a/justfile +++ b/justfile @@ -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" diff --git a/reginald_codegen/tests/generator_c_funcpack/mod.rs b/reginald_codegen/tests/generator_c_funcpack/mod.rs index c117d19..838685c 100644 --- a/reginald_codegen/tests/generator_c_funcpack/mod.rs +++ b/reginald_codegen/tests/generator_c_funcpack/mod.rs @@ -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 ==== @@ -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) diff --git a/reginald_codegen/tests/generator_c_macromap/mod.rs b/reginald_codegen/tests/generator_c_macromap/mod.rs index 5c63891..672ab85 100644 --- a/reginald_codegen/tests/generator_c_macromap/mod.rs +++ b/reginald_codegen/tests/generator_c_macromap/mod.rs @@ -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) { diff --git a/reginald_codegen/tests/generator_tests.rs b/reginald_codegen/tests/generator_tests.rs index db85c7c..f355912 100644 --- a/reginald_codegen/tests/generator_tests.rs +++ b/reginald_codegen/tests/generator_tests.rs @@ -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}"); + } } }