Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <mike@mikegerwitz.com>2014-06-16 23:24:18 -0400
committerMike Gerwitz <mike@mikegerwitz.com>2014-06-17 01:37:24 -0400
commita073da42f8d74cb81927a995d8e57a0789a99ccd (patch)
tree83912e69e8c7cffef4113d76d969af6ce4034da2
parent6bd5a531255e6760d1e948899413259928de7c3f (diff)
downloadpkgsh-a073da42f8d74cb81927a995d8e57a0789a99ccd.tar.gz
pkgsh-a073da42f8d74cb81927a995d8e57a0789a99ccd.tar.bz2
pkgsh-a073da42f8d74cb81927a995d8e57a0789a99ccd.zip
Test runner added
-rwxr-xr-xtest/run-test42
-rwxr-xr-xtest/runner50
2 files changed, 92 insertions, 0 deletions
diff --git a/test/run-test b/test/run-test
new file mode 100755
index 0000000..d8e4873
--- /dev/null
+++ b/test/run-test
@@ -0,0 +1,42 @@
+#!/bin/bash
+# Prepare and run a test
+#
+# Copyright (C) 2014 Mike Gerwitz
+#
+# This file is part of pkgsh.
+#
+# pkgsh is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# This sets up the environment prior to running a test.
+##
+
+# change wd to root to place us in a known state for sourcing
+declare -r __wd_orig="$( pwd )"
+cd "$( dirname "$0" )/../" || {
+ echo "fatal: could not determine root directory" >&2
+ exit 1
+}
+
+
+main()
+{
+ local tpath="$1"
+
+ # fail on any sort of command failure
+ set -e
+ source "$__wd_orig/$tpath"
+}
+
+main "${1?Missing test path}"
+
diff --git a/test/runner b/test/runner
new file mode 100755
index 0000000..6d50173
--- /dev/null
+++ b/test/runner
@@ -0,0 +1,50 @@
+#!/bin/bash
+# Test runner
+#
+# Copyright (C) 2014 Mike Gerwitz
+#
+# This file is part of pkgsh.
+#
+# pkgsh is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# You should invoke all tests using this runner rather than executing the
+# tests directly.
+##
+
+# determine our wd, but don't change directories (so that run-test can do
+# its own magic)
+__mypath="$( dirname "$0" )" || {
+ echo "fatal: could not determine runner directory" >&2
+ exit 1
+}
+readonly __mypath
+
+
+main()
+{
+ local -i fail=0
+
+ # run each test in an isolated process with a fresh environment
+ for tcase in "$@"; do
+ env -i "$__mypath/run-test" "$tcase" || {
+ echo "failure [$?]: $tcase" >&2
+ fail=1
+ }
+ done
+
+ test "$fail" -eq 0
+}
+
+main "$@"
+