Skip to content

Commit

Permalink
Add --no-create-golden-file flag to run-tests.sh
Browse files Browse the repository at this point in the history
This flag makes run-tests.sh not create golden files when they are
missing. This is useful when iterating on a new test so the golden
file doesn't need to be reset every time.
  • Loading branch information
laurenthuberdeau committed Feb 16, 2025
1 parent 2eeab86 commit d6a4822
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ bootstrap=0
safe=0
fast=0
compile_only=0
create_golden_file=1 # Create golden files by default
shell="$SHELL" # Use current shell as the default
pattern=".*"
while [ $# -gt 0 ]; do
case $1 in
--shell) shell="$2"; shift 2;;
--match) pattern="$2"; shift 2;;
--bootstrap) bootstrap=1; shift 1;;
--safe) safe=1; shift 1;;
--fast) fast=1; shift 1;;
--compile-only) compile_only=1; shift 1;;
--shell) shell="$2"; shift 2;;
--match) pattern="$2"; shift 2;;
--bootstrap) bootstrap=1; shift 1;;
--safe) safe=1; shift 1;;
--fast) fast=1; shift 1;;
--compile-only) compile_only=1; shift 1;;
--no-create-golden-file) create_golden_file=0; shift 1;;
*) echo "Unknown option: $1"; exit 1;;
esac
done
Expand Down Expand Up @@ -247,7 +249,9 @@ run_test() { # file_to_test: $1
$dir/$filename-gcc.$ext $(test_args $file) > "$dir/$filename-gcc.output"
if diff "$dir/$filename-gcc.output" "$dir/$filename.output"; then
echo "🟡 Golden file generated by pnut"
cp "$dir/$filename.output" "$golden_file"
if [ "$create_golden_file" -eq 1 ]; then
cp "$dir/$filename.output" "$golden_file"
fi
else
echo "❌ Program compiled by gcc and pnut produced different outputs"
fi
Expand Down Expand Up @@ -282,7 +286,7 @@ run_test() { # file_to_test: $1
chmod +x "$dir/$filename.$ext"
execute_test "$dir/$filename.$ext" "$(test_timeout $file)" "$(test_args $file)" > "$dir/$filename.output" 2> "$dir/$filename.err"
if [ $? -eq 0 ]; then # If the executable ran successfully
diff_out=$(diff "$dir/$filename.output" "$dir/$filename.golden")
diff_out=$(diff "$dir/$filename.output" "$golden_file")
if [ $? -eq 0 ]; then # If the output matches the golden file
echo "✅ Test passed"
return 0
Expand Down

0 comments on commit d6a4822

Please sign in to comment.