chiark / gitweb /
tests: Provide advance-tested script
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 30 Dec 2019 12:50:30 +0000 (12:50 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 30 Dec 2019 13:08:42 +0000 (13:08 +0000)
Useful for our own testing.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
tests/advance-tested [new file with mode: 0755]

diff --git a/tests/advance-tested b/tests/advance-tested
new file mode 100755 (executable)
index 0000000..fc38869
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/bash
+# subdirmk - test suite runner helper script
+# Copyright various contributors - see top level README.
+# SPDX-License-Identifier: LGPL-2.0-or-later
+# There is NO WARRANTY.
+
+set -e
+
+branch=$(git symbolic-ref -q HEAD || test $? = 1)
+base=$(git merge-base tested HEAD)
+
+git branch -D test-failed 2>&1 ||:
+
+case "$branch" in
+refs/heads/tested|refs/heads/test-failed)
+       echo >&2 "unexpectedly on branch $branch"; exit 1 ;;
+refs/heads/*)
+       branch=${branch#refs/heads/} ;;
+*)
+       branch='';
+esac
+
+restore-branch () {
+       if [ "$branch" ]; then git checkout $branch; fi
+}
+
+git checkout --detach
+git clean -xdff
+
+if ! git rebase --exec 'tests/check && git branch -f tested' $base; then
+       git branch -f test-failed
+       git rebase --abort
+       echo >&2 '^ ignore previous message from git-rebase!'
+       echo >&2 'Test failed, made local branch ref test-failed'
+       restore-branch
+       exit 1
+fi
+
+restore-branch