From 6bc7f2204e32fb5ef824fc7ccb5ce28335c606f8 Mon Sep 17 00:00:00 2001 From: coderdreams Date: Sun, 30 May 2021 12:15:20 -0300 Subject: [PATCH] Tests: Run each test in their respective directories This is so they can find their associated resources and it's the same behavior as in Lagom. This also required changing some tests so that they could write their resources in a writable location. --- Base/home/anon/tests/run-tests-and-shutdown.sh | 10 ++++++++-- Userland/Shell/Tests/heredocs.sh | 4 ++++ Userland/Shell/Tests/loop.sh | 6 ++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Base/home/anon/tests/run-tests-and-shutdown.sh b/Base/home/anon/tests/run-tests-and-shutdown.sh index 9bbcf00b1a..018f307bc5 100755 --- a/Base/home/anon/tests/run-tests-and-shutdown.sh +++ b/Base/home/anon/tests/run-tests-and-shutdown.sh @@ -5,9 +5,14 @@ echo "==== Running Tests on SerenityOS ====" run(index) { shift + test_dir=$(dirname $1) + if test -z $test_dir { + test_dir="." + } test_cmd=($*) echo "==== Running test $index out of $count_of_all_tests -- $test_cmd ====" echo "::group::$test_cmd" + cd $test_dir if $test_cmd { echo "::endgroup::" echo "==== $test_cmd passed! ====" @@ -17,6 +22,7 @@ run(index) { echo "==== Added $test_cmd to list of failed tests. Failed tests so far: $failed_tests ====" echo "::error file=$test_cmd:: $test_cmd returned non-zero exit code, check logs!" } + cd - } # Files in /usr/Tests/* that we don't want to execute match these patterns: @@ -25,10 +31,10 @@ run(index) { # UserEmulator: Tests designed to run inside the Userspace Emulator # stack-smash: Intentionally crashes by smashing the stack # TestJSON: AK/TestJSON makes assumptions about $PWD to load its input files -# .frm: Test inputs that are not tests +# .frm,.txt: Test inputs that are not tests # test-web: Requires the window server in order to work # test-js: We start this one manually with the show progress flag set to false -exclude_patterns='Kernel/Legacy|.inc|UserEmulator|stack-smash|TestJSON|.frm|test-web|test-js' +exclude_patterns='Kernel/Legacy|.inc|UserEmulator|stack-smash|TestJSON|.txt|.frm|test-web|test-js' system_tests=((test-js --show-progress=false) (test-crypto -c -t test)) all_tests=${concat_lists $system_tests $(find /usr/Tests -type f | grep -E -v $exclude_patterns | shuf) } diff --git a/Userland/Shell/Tests/heredocs.sh b/Userland/Shell/Tests/heredocs.sh index c1c4c6b376..128c495562 100644 --- a/Userland/Shell/Tests/heredocs.sh +++ b/Userland/Shell/Tests/heredocs.sh @@ -1,6 +1,8 @@ #!/bin/sh source $(dirname "$0")/test-commons.inc +# go to a writable directory +cd /tmp # Simple usage, single doc echo <<-test > sh.doc.test @@ -71,4 +73,6 @@ test test2 rm -f sh.doc.test +# return to original directory +cd - pass diff --git a/Userland/Shell/Tests/loop.sh b/Userland/Shell/Tests/loop.sh index e040280ceb..f5a5602dbe 100644 --- a/Userland/Shell/Tests/loop.sh +++ b/Userland/Shell/Tests/loop.sh @@ -1,7 +1,8 @@ #!/bin/sh source $(dirname "$0")/test-commons.inc - +# go to a writable directory +cd /tmp singlecommand_ok=yes multicommand_ok=yes inlineexec_ok=yes @@ -95,5 +96,6 @@ if not test \ fail "Something failed :(" } - +# return to original directory +cd - echo PASS