diff --git a/run-tests.sh b/run-tests.sh index f9cdaa72..9aaafb2e 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -75,6 +75,25 @@ shell_version() { esac } +get_time_millis_macos= +get_time_millis() { + # To accurately measure time, we want to exclude the time it takes to detect + # the platform so we do it once and cache the result + if [ -z $get_time_millis_macos ]; then + get_time_millis_macos=0 + if uname | grep -q "Darwin"; then + get_time_millis_macos=1 + fi + fi + + # On MacOS, the date utility doesn't recognize the %N format string + if [ $get_time_millis_macos = 1 ]; then + gdate +%s%3N + else + date +%s%3N + fi +} + # Some tests specify command line arguments in the source file # This function extracts the arguments from the source file # To specify arguments, add a comment in the source file like this: @@ -143,8 +162,10 @@ run_test() { # file_to_test: $1 "$pnut_comp" "$file" > "$dir/$filename.$ext" 2> "$dir/$filename.err" if [ $? -eq 0 ]; then chmod +x "$dir/$filename.$ext" + t0=$(get_time_millis) execute_test "$dir/$filename.$ext" "$(test_timeout $file)" "$(test_args $file)" > "$golden_file" - echo "🟡 Golden file generated by pnut" + t1=$(get_time_millis) + echo "🟡 Golden file generated by pnut [$(($t1 - $t0))ms]" else echo "❌ Failed to compile with pnut" fi @@ -156,26 +177,28 @@ run_test() { # file_to_test: $1 if [ $? -eq 0 ]; then # If compilation was successful chmod +x "$dir/$filename.$ext" + t0=$(get_time_millis) execute_test "$dir/$filename.$ext" "$(test_timeout $file)" "$(test_args $file)" > "$dir/$filename.output" 2> "$dir/$filename.err" + t1=$(get_time_millis) if [ $? -eq 0 ]; then # If the executable ran successfully diff_out=$(diff "$dir/$filename.output" "$dir/$filename.golden") if [ $? -eq 0 ]; then # If the output matches the golden file - echo "✅ Test passed" + echo "✅ Test passed [$(($t1 - $t0))ms]" return 0 elif test_expect_failure_for_shell "$file"; then - echo "⚠️ Test disabled for $shell" + echo "⚠️ Test disabled for $shell [$(($t1 - $t0))ms]" return 0 else - echo "❌ Test failed" + echo "❌ Test failed [$(($t1 - $t0))ms]" echo "diff (output vs expected)" echo "$diff_out" return 1 fi elif test_expect_failure_for_shell "$file"; then - echo "⚠️ Test disabled for $shell" + echo "⚠️ Test disabled for $shell [$(($t1 - $t0))ms]" return 0 else - echo "❌ Failed to run: $(cat "$dir/$filename.err")" + echo "❌ Failed to run: $(cat "$dir/$filename.err") [$(($t1 - $t0))ms]" return 1 fi else