From 34b26f40262ff9f574c61b701e3a9cb77c1b9496 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Tue, 16 Feb 2021 12:27:56 -0800 Subject: [PATCH 1/3] Break the actual test runner into its own script So that we don't have to run with coverage if we don't want to. Additionally, don't require being in the t directory to run tests Signed-off-by: Stefano Rivera --- Makefile | 2 +- t/run_coverage | 6 +----- t/run_tests | 10 ++++++++++ 3 files changed, 12 insertions(+), 6 deletions(-) create mode 100755 t/run_tests diff --git a/Makefile b/Makefile index 1b7b5124..31f5e3ae 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ build: @echo Nothing to do: filter-repo is a script which needs no compilation. test: - cd t && time ./run_coverage + time t/run_coverage # fixup_locale might matter once we actually have translations, but right now # we don't. It might not even matter then, because python has a fallback podir. diff --git a/t/run_coverage b/t/run_coverage index f72cdd50..2164cc9b 100755 --- a/t/run_coverage +++ b/t/run_coverage @@ -16,12 +16,8 @@ EOF export COVERAGE_PROCESS_START=$tmpdir/.coveragerc export PYTHONPATH=$tmpdir: -# We pretend filenames are unicode for two reasons: (1) because it exercises -# more code, and (2) this setting will detect accidental use of unicode strings -# for file/directory names when it should always be bytestrings. -export PRETEND_UNICODE_ARGS=1 -ls t939*.sh | xargs -n 1 bash +$orig_dir/run_tests cd $tmpdir coverage3 combine diff --git a/t/run_tests b/t/run_tests new file mode 100755 index 00000000..320188af --- /dev/null +++ b/t/run_tests @@ -0,0 +1,10 @@ +#!/bin/bash + +cd $(dirname $0) + +# We pretend filenames are unicode for two reasons: (1) because it exercises +# more code, and (2) this setting will detect accidental use of unicode strings +# for file/directory names when it should always be bytestrings. +export PRETEND_UNICODE_ARGS=1 + +ls t939*.sh | xargs -n 1 bash From 26e3f8c52e4288f0eb8f8b35de0b211f0f5a8044 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Tue, 16 Feb 2021 12:34:58 -0800 Subject: [PATCH 2/3] Exit non-zero if the tests fail Signed-off-by: Stefano Rivera --- t/run_coverage | 8 ++++++++ t/run_tests | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/t/run_coverage b/t/run_coverage index 2164cc9b..5517459b 100755 --- a/t/run_coverage +++ b/t/run_coverage @@ -1,5 +1,7 @@ #!/bin/bash +set -eu + orig_dir=$(cd $(dirname $0) && pwd -P) tmpdir=$(mktemp -d) @@ -17,7 +19,11 @@ EOF export COVERAGE_PROCESS_START=$tmpdir/.coveragerc export PYTHONPATH=$tmpdir: +# Produce a coverage report, even if the tests fail +set +e $orig_dir/run_tests +exitcode=$? +set -e cd $tmpdir coverage3 combine @@ -25,3 +31,5 @@ coverage3 html -d $orig_dir/report coverage3 report -m cd $orig_dir rm -rf $tmpdir + +exit $exitcode diff --git a/t/run_tests b/t/run_tests index 320188af..766519e2 100755 --- a/t/run_tests +++ b/t/run_tests @@ -1,4 +1,5 @@ #!/bin/bash +set -eu cd $(dirname $0) @@ -7,4 +8,9 @@ cd $(dirname $0) # for file/directory names when it should always be bytestrings. export PRETEND_UNICODE_ARGS=1 -ls t939*.sh | xargs -n 1 bash +failed=0 + +for test in t939*.sh; do + ./$test || failed=1 +done +exit $failed From 24f09bd016fc7310bf6983b81f4730ab881554c2 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Tue, 16 Feb 2021 13:32:53 -0800 Subject: [PATCH 3/3] Share implementation with github workflow Signed-off-by: Stefano Rivera --- .github/workflows/test.yml | 16 +++------------- t/run_tests | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1d22fe71..d9bbc980 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,21 +24,11 @@ jobs: printf '#!/bin/sh\n\nexec python "$@"\n' >python3 && export PATH=$PWD:$PATH && - export PYTHONPATH=$PWD && - export TEST_SHELL_PATH=/bin/sh && - failed=0 && - cd t && - for t in t[0-9]*.sh - do - printf '\n\n== %s ==\n' "$t" && - bash $t -q -v -x || - failed=$(($failed+1)) - done && - if test 0 != $failed + if ! t/run_tests -q -v -x then - mkdir ../failed && - tar czf ../failed/failed.tar.gz . + mkdir failed && + tar czf failed/failed.tar.gz t exit 1 fi - name: upload failed tests' directories diff --git a/t/run_tests b/t/run_tests index 766519e2..d5e0ebd6 100755 --- a/t/run_tests +++ b/t/run_tests @@ -3,14 +3,25 @@ set -eu cd $(dirname $0) +# Put git_filter_repo.py on the front of PYTHONPATH +export PYTHONPATH="$PWD/..${PYTHONPATH:+:$PYTHONPATH}" + # We pretend filenames are unicode for two reasons: (1) because it exercises # more code, and (2) this setting will detect accidental use of unicode strings # for file/directory names when it should always be bytestrings. export PRETEND_UNICODE_ARGS=1 +export TEST_SHELL_PATH=/bin/sh + failed=0 -for test in t939*.sh; do - ./$test || failed=1 +for t in t[0-9]*.sh +do + printf '\n\n== %s ==\n' "$t" + bash $t "$@" || failed=$(($failed+1)) done -exit $failed + +if [ 0 -lt $failed ] +then + exit 1 +fi