From a1979c6feb528779ee26e1dd6c6edbaf4272c9ce Mon Sep 17 00:00:00 2001 From: Felipe Coury Date: Thu, 4 Jul 2024 21:55:46 -0300 Subject: [PATCH] feat: better integrated tests --- tests/scripts/loop.hk.err | 0 tests/scripts/loop.hk.out | 18 ++++++++++++++++++ tests/scripts/struct.hk.err | 0 tests/scripts/test.sh | 27 ++++++++++++++++++--------- tests/scripts/update.sh | 2 +- 5 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 tests/scripts/loop.hk.err create mode 100644 tests/scripts/loop.hk.out create mode 100644 tests/scripts/struct.hk.err diff --git a/tests/scripts/loop.hk.err b/tests/scripts/loop.hk.err new file mode 100644 index 0000000..e69de29 diff --git a/tests/scripts/loop.hk.out b/tests/scripts/loop.hk.out new file mode 100644 index 0000000..04124ed --- /dev/null +++ b/tests/scripts/loop.hk.out @@ -0,0 +1,18 @@ +1 +2 +1 +2 +3 +4 +5 +1 +2 +1 +2 +4 +5 +6 +7 +8 +9 +10 diff --git a/tests/scripts/struct.hk.err b/tests/scripts/struct.hk.err new file mode 100644 index 0000000..e69de29 diff --git a/tests/scripts/test.sh b/tests/scripts/test.sh index 55ec7f9..6b96cd6 100755 --- a/tests/scripts/test.sh +++ b/tests/scripts/test.sh @@ -22,36 +22,45 @@ do base_name=$(basename "$file") # Run the script and capture the output - ./target/debug/husk run "$file" > "$TEMP_STDOUT" 2> "$TEMP_STDERR" + ./target/debug/husk "$file" > "$TEMP_STDOUT" 2> "$TEMP_STDERR" + + echo "$base_name" # Compare stdout if the .out file exists if [ -f "$SCRIPT_DIR/$base_name.out" ]; then - if diff -q "$TEMP_STDOUT" "$SCRIPT_DIR/$base_name.out" > /dev/null; then - echo "stdout matches for $base_name" + if diff --color=always "$TEMP_STDOUT" "$SCRIPT_DIR/$base_name.out" > /dev/null; then + echo " stdout ✅ " else - echo "stdout does not match for $base_name" + echo " stdout ❌" + diff "$TEMP_STDOUT" "$SCRIPT_DIR/$base_name.out" ANY_TEST_FAILED=1 fi + else + echo " skipped stdout" fi # Compare stderr if the .err file exists if [ -f "$SCRIPT_DIR/$base_name.err" ]; then - if diff -q "$TEMP_STDERR" "$SCRIPT_DIR/$base_name.err" > /dev/null; then - echo "stderr matches for $base_name" + if diff --color=always "$TEMP_STDERR" "$SCRIPT_DIR/$base_name.err" > /dev/null; then + echo " stderr ✅ " else - echo "stderr does not match for $base_name" + echo " stderr ❌" + diff "$TEMP_STDERR" "$SCRIPT_DIR/$base_name.err" ANY_TEST_FAILED=1 fi + else + echo " skipped stdout" fi + + echo "" done # Cleanup temporary files rm -f "$TEMP_STDOUT" "$TEMP_STDERR" - # Exit with error code if any test failed if [ $ANY_TEST_FAILED -ne 0 ]; then - echo Some tests failed. + echo "Some tests failed." exit 1 else exit 0 diff --git a/tests/scripts/update.sh b/tests/scripts/update.sh index 0849ada..223efdb 100755 --- a/tests/scripts/update.sh +++ b/tests/scripts/update.sh @@ -39,7 +39,7 @@ do fi # Run the command and update .out and .err files - cargo run -q -- run "$file" > "$out_file" 2> "$err_file" + cargo run -q -- "$file" > "$out_file" 2> "$err_file" echo "Updated $base_name.hk.out and $base_name.hk.err" done