summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVidar Holen <spam@vidarholen.net>2018-10-01 17:10:43 -0700
committerVidar Holen <spam@vidarholen.net>2018-10-01 17:10:43 -0700
commit8d13add1eddeaf6111d1fa539a8977f45d5cbdb6 (patch)
tree4159391791ff8aded692138698a27f2669eede0b
parentdadfdfde979b025215721b011bbb553e71d36007 (diff)
Add automated cross-distro testing via Docker
-rwxr-xr-xtest/buildtest35
-rwxr-xr-xtest/distrotest75
2 files changed, 110 insertions, 0 deletions
diff --git a/test/buildtest b/test/buildtest
new file mode 100755
index 0000000..e3aa1eb
--- /dev/null
+++ b/test/buildtest
@@ -0,0 +1,35 @@
+#!/bin/bash
+# This script configures, builds and runs tests.
+# It's meant for automatic cross-distro testing.
+
+die() { echo "$*" >&2; exit 1; }
+
+[ -e "ShellCheck.cabal" ] ||
+ die "ShellCheck.cabal not in current dir"
+command -v cabal ||
+ die "cabal is missing"
+
+cabal update ||
+ die "can't update"
+cabal install --dependencies-only --enable-tests ||
+ die "can't install dependencies"
+cabal configure --enable-tests ||
+ die "configure failed"
+cabal build ||
+ die "build failed"
+cabal test ||
+ die "test failed"
+
+dist/build/shellcheck/shellcheck - << 'EOF' || die "execution failed"
+#!/bin/sh
+echo "Hello World"
+EOF
+
+dist/build/shellcheck/shellcheck - << 'EOF' && die "negative execution failed"
+#!/bin/sh
+echo $1
+EOF
+
+
+echo "Success"
+exit 0
diff --git a/test/distrotest b/test/distrotest
new file mode 100755
index 0000000..0465c3a
--- /dev/null
+++ b/test/distrotest
@@ -0,0 +1,75 @@
+#!/bin/bash
+# This script runs 'buildtest' on each of several distros
+# via Docker.
+set -o pipefail
+
+exec 3>&1 4>&2
+die() { echo "$*" >&4; exit 1; }
+
+[ -e "ShellCheck.cabal" ] || die "ShellCheck.cabal not in this dir"
+
+[ "$1" = "--run" ] || {
+cat << EOF
+This script pulls multiple distros via Docker and compiles
+ShellCheck and dependencies for each one. It takes hours,
+and is still highly experimental.
+
+Make sure you're plugged in and have screen/tmux in place,
+then re-run with $0 --run to continue.
+EOF
+exit 0
+}
+
+
+log=$(mktemp) || die "Can't create temp file"
+date >> "$log" || die "Can't write to log"
+
+echo "Logging to $log" >&3
+exec >> "$log" 2>&1
+
+final=0
+while read -r distro setup
+do
+ [[ "$distro" = "#"* || -z "$distro" ]] && continue
+ printf '%s ' "$distro" >&3
+ docker pull "$distro" || die "Can't pull $distro"
+ printf 'pulled. ' >&3
+
+ tmp=$(mktemp -d) || die "Can't make temp dir"
+ cp -r . "$tmp/" || die "Can't populate test dir"
+ printf 'Result: ' >&3
+ < /dev/null docker run -v "$tmp:/mnt" "$distro" sh -c "
+ $setup
+ cd /mnt || exit 1
+ test/buildtest
+ "
+ ret=$?
+ if [ "$ret" = 0 ]
+ then
+ echo "OK" >&3
+ else
+ echo "FAIL with $ret. See $log" >&3
+ final=1
+ fi
+ rm -rf "$tmp"
+done << EOF
+# Docker tag Setup command
+debian:stable apt-get update && apt-get install -y cabal-install
+debian:testing apt-get update && apt-get install -y cabal-install
+ubuntu:latest apt-get update && apt-get install -y cabal-install
+opensuse:latest zypper install -y cabal-install ghc
+
+# Older Ubuntu versions we want to support
+ubuntu:18.04 apt-get update && apt-get install -y cabal-install
+ubuntu:17.10 apt-get update && apt-get install -y cabal-install
+
+# Misc
+haskell:latest true
+
+# Known to currently fail
+centos:latest yum install -y epel-release && yum install -y cabal-install
+fedora:latest dnf install -y cabal-install
+base/archlinux:latest pacman -S -y --noconfirm cabal-install ghc-static base-devel
+EOF
+
+exit "$final"