Skip to content

Commit

Permalink
feat: better integrated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fcoury committed Jul 5, 2024
1 parent d531bf9 commit a1979c6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
Empty file added tests/scripts/loop.hk.err
Empty file.
18 changes: 18 additions & 0 deletions tests/scripts/loop.hk.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
1
2
1
2
3
4
5
1
2
1
2
4
5
6
7
8
9
10
Empty file added tests/scripts/struct.hk.err
Empty file.
27 changes: 18 additions & 9 deletions tests/scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a1979c6

Please sign in to comment.