[pacman-dev,3/7] gitlab-ci: print output and logs for failed tests

Message ID 20210119183010.12831-3-andrew.gregory.8@gmail.com
State New
Headers show
Series [pacman-dev,1/7] pacman: add -w to -U | expand

Commit Message

Andrew Gregory Jan. 19, 2021, 6:30 p.m. UTC
---
 .gitlab-ci.yml                     |  5 +++++
 build-aux/cat-test-file            | 11 +++++++++++
 build-aux/print-failed-test-output | 17 +++++++++++++++++
 3 files changed, 33 insertions(+)
 create mode 100755 build-aux/cat-test-file
 create mode 100755 build-aux/print-failed-test-output

Patch

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index e889c498..6ca35941 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -2,6 +2,7 @@  variables:
   MAKEFLAGS: "-j10"
   VERBOSE: 1
   PACMAN_OPTS: --needed --noconfirm --cachedir .pkg-cache
+  PACTEST_OPTS: --review --editor=../build-aux/cat-test-file
 
 cache:
   key: pkgs-v1
@@ -9,6 +10,10 @@  cache:
     # For some reason Gitlab CI only supports storing cache/artifacts in a path relative to the build directory
     - .pkg-cache
 
+default:
+  after_script:
+    - build-aux/print-failed-test-output build/meson-logs/testlog.json
+
 .arch-test:
   image: archlinux/base
   before_script:
diff --git a/build-aux/cat-test-file b/build-aux/cat-test-file
new file mode 100755
index 00000000..1bcc1113
--- /dev/null
+++ b/build-aux/cat-test-file
@@ -0,0 +1,11 @@ 
+#!/usr/bin/python3
+
+import sys
+
+for path in sys.argv[1:]:
+    print('# -----------------------------------')
+    print('# ' + path + ':')
+    print('# -----------------------------------')
+    with open(path, 'r') as f:
+        for line in f:
+            print('# ' + line, end='')
diff --git a/build-aux/print-failed-test-output b/build-aux/print-failed-test-output
new file mode 100755
index 00000000..1f1ab76d
--- /dev/null
+++ b/build-aux/print-failed-test-output
@@ -0,0 +1,17 @@ 
+#!/usr/bin/python
+
+import json
+import sys
+
+def print_result(result):
+    print('==================================================================')
+    print(result['name'])
+    print(' '.join(result['command']))
+    print('==================================================================')
+    print(result['stdout'])
+
+with open(sys.argv[1], 'r') as f:
+    for line in f:
+        result = json.loads(line)
+        if result['result'] == 'FAIL':
+            print_result(result)