From 74fa543a7187e2c3608c87ce798708b5f0bf2914 Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Mon, 12 Feb 2024 23:33:54 +0100 Subject: [PATCH] Export detailed test results to a JSON file and expose it as an artifact for CI runs --- .github/workflows/ci.yml | 3 +++ run-upstream-testsuite.sh | 34 +++++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e8fdff7..45f1f53 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,6 +60,9 @@ jobs: - run: ./run-upstream-testsuite.sh release || true env: TERM: xterm + - uses: actions/upload-artifact@v4 + with: + file: test-results.json coverage: name: Code Coverage diff --git a/run-upstream-testsuite.sh b/run-upstream-testsuite.sh index cd4a2e6..f512b7e 100755 --- a/run-upstream-testsuite.sh +++ b/run-upstream-testsuite.sh @@ -43,25 +43,45 @@ else fi echo "Running $(echo "$tests" | wc -w) tests" export LC_ALL=C -pass="$(tput setaf 2)PASS$(tput sgr0)" -fail="$(tput setaf 1)FAIL$(tput sgr0)" -skip=SKIP +export KEEP=yes exitcode=0 +json="" for test in $tests do - result=$fail + result="FAIL" # Run only the tests that invoke `diff`, because other binaries aren't implemented yet if ! grep -E -s -q "(cmp|diff3|sdiff)" "$test" then - sh "$test" &> /dev/null && result=$pass || exitcode=1 + sh "$test" &> /dev/null && result="PASS" || exitcode=1 + json="$json{\"test\":\"$test\",\"result\":\"$result\",\"files\":{" + cd gt-$test.* + for file in * + do + if [[ -f "$file" ]] + then + content=$(base64 -w0 < "$file") + json="$json\"$file\":\"$content\"," + fi + done + json="${json%,}}}," + cd - > /dev/null else - result=$skip + result="SKIP" + json="$json{\"test\":\"$test\",\"result\":\"$result\"}," fi - printf " %-40s $result\n" "$test" + color=2 # green + [[ "$result" = "FAIL" ]] && color=1 # red + [[ "$result" = "SKIP" ]] && color=3 # yellow + printf " %-40s $(tput setaf $color)$result$(tput sgr0)\n" "$test" done +json="[${json%,}]" # Clean up cd "$scriptpath" rm -rf "$tempdir" +resultsfile="test-results.json" +echo "$json" | jq > "$resultsfile" +echo "Results written to $resultsfile" + exit $exitcode