From a28e72e84a383c37b6a28eb2ee505a9eb1cb410e Mon Sep 17 00:00:00 2001
From: Eric Freese <ericdfreese@gmail.com>
Date: Tue, 15 Mar 2016 09:03:57 -0600
Subject: [PATCH] Test Runner now supports running specific tests and choosing
 zsh bin

---
 Makefile               |  2 +-
 script/test_runner.zsh | 43 +++++++++++++++++++++++++++++++++---------
 2 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile
index 6a7679e..bd649f6 100644
--- a/Makefile
+++ b/Makefile
@@ -56,4 +56,4 @@ clean:
 
 .PHONY: test
 test: all $(TEST_PREREQS)
-	script/test_runner.zsh
+	script/test_runner.zsh $(TESTS)
diff --git a/script/test_runner.zsh b/script/test_runner.zsh
index 5ab06d6..848cb94 100755
--- a/script/test_runner.zsh
+++ b/script/test_runner.zsh
@@ -15,15 +15,40 @@ header() {
 	EOF
 }
 
-local -a tests
+# ZSH binary to use
+local zsh_bin="zsh"
 
-# Test suites to run
-tests=($TEST_DIR/**/*_test.zsh)
-
-local retval=0
-for suite in $tests; do
-	header "${suite#"$TEST_DIR"}"
-	zsh -f "$suite" || retval=$?
+while getopts ":z:" opt; do
+	case $opt in
+		z)
+			zsh_bin="$OPTARG"
+			;;
+		\?)
+			echo "Invalid option: -$OPTARG" >&2
+			exit 1
+			;;
+		:)
+			echo "Option -$OPTARG requires an argument" >&2
+			exit 1
+			;;
+	esac
 done
 
-exit retval
+shift $((OPTIND -1))
+
+# Test suites to run
+local -a tests
+if [ $#@ -gt 0 ]; then
+	tests=($@)
+else
+	tests=($TEST_DIR/**/*_test.zsh)
+fi
+
+local -i retval=0
+
+for suite in $tests; do
+	header "${suite#"$TEST_DIR"}"
+	"$zsh_bin" -f "$suite" || retval=$?
+done
+
+exit $retval