From 29a0e7050c623ac17e3a91f76bbfc739b271e488 Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 9 Jan 2025 00:54:46 +0200 Subject: [PATCH] runtests.sh: Do it in should_skip function --- runtests.sh | 67 +++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/runtests.sh b/runtests.sh index 48ad94b5..50c5586e 100755 --- a/runtests.sh +++ b/runtests.sh @@ -187,19 +187,37 @@ function should_skip() local joufile="$1" local correct_exit_code="$2" - # Skip tests when: - # * the test is supposed to crash, but optimizations are enabled (unpredictable by design) - # * the test is supposed to fail (crash or otherwise) and we use valgrind (see README) - # * the "test" is actually a GUI program in examples/ - if ( [[ $joufile =~ ^tests/crash/ ]] && ! [[ "$jou_flags" =~ -O0 ]] ) \ - || ( [ $valgrind = yes ] && [ $correct_exit_code != 0 ] ) \ - || [ $joufile = examples/x11_window.jou ] \ - || [ $joufile = examples/memory_leak.jou ] - then - return 0 # true - else - return 1 # false + # For stages 1 and 2, error handling is not important (users won't see it), + # so only test that we support all features of Jou. Skip everything else. + if [ $stage != 3 ] && (grep -qE 'Warning:|Error:' $joufile || ! [[ $joufile =~ should_succeed ]]); then + return 0 + fi + + # When optimizations are enabled, skip tests that are supposed to crash. + # Running them would be unpredictable by design. + if [[ $joufile =~ ^tests/crash/ ]] && ! [[ "$jou_flags" =~ -O0 ]]; then + return 0 + fi + + # When running valgrind, skip tests that are supposed to fail, because: + # - error handling is easier if you don't free memory (OS will do it) + # - in Jou compilers, error handling is simple and not very likely to contain UB + # - valgrinding is slow, this means we valgrind a lot less + if [ $valgrind = yes ] && [ $correct_exit_code != 0 ]; then + return 0 + fi + + # compiler_cli.jou hard-codes ./jou or ./jou.exe, so it tests stage 3 anyway + if [ $stage != 3 ] && [[ $joufile =~ compiler_cli ]]; then + return 0 fi + + # Skip special programs that don't interact nicely with automated tests + if [ $joufile = examples/x11_window.jou ] || [ $joufile = examples/memory_leak.jou ]; then + return 0 + fi + + return 1 # false, don't skip } function run_test() @@ -280,30 +298,9 @@ for joufile in examples/*.jou examples/aoc*/day*/part*.jou tests/*/*.jou tests/s continue fi - # For early bootstrapping stages, we only want to ensure that the bootstrap - # compiler supports all Jou syntax. Getting error handling exactly right - # doesn't matter, because users don't see it anyway. - if [ $stage != 3 ] && grep -qE 'Warning:|Error:' $joufile; then - continue - fi - - # compiler_cli.jou hard-codes ./jou or ./jou.exe, so it tests stage 3 anyway - if [ $stage != 3 ] && [[ $joufile =~ compiler_cli ]]; then - continue - fi - case $joufile in - examples/* | tests/should_succeed/*) - correct_exit_code=0 - ;; - *) - # It's supposed to fail when compiling or at runtime. - # - if [ $stage != 3 ]; then - continue - fi - correct_exit_code=1 - ;; + examples/* | tests/should_succeed/*) correct_exit_code=0; ;; + *) correct_exit_code=1; ;; esac counter=$((counter + 1))