Commit 7d7f0d06e0979317d0c93cad370c877ba77d6cc9

Martin Mitas 2016-10-06T21:15:23

scripts/run-commonmark-tests.sh: Make the script more robust.

diff --git a/scripts/run-commonmark-tests.sh b/scripts/run-commonmark-tests.sh
index 3421e7f..689d0d5 100755
--- a/scripts/run-commonmark-tests.sh
+++ b/scripts/run-commonmark-tests.sh
@@ -2,9 +2,23 @@
 
 set -e
 
+PROGRAM="md2html/md2html"
+if [ ! -x "$PROGRAM" ]; then
+    echo "Cannot find the $PROGRAM." >&2
+    echo "You have to run this script from the build directory." >&2
+    exit 1
+fi
+
 if [ ! -d commonmark ]; then
     git clone https://github.com/jgm/commonmark.git
 fi
 
-commonmark/test/spec_tests.py -s commonmark/spec.txt -p md2html/md2html
+if which python3 2>/dev/null; then
+    PYTHON=python3
+elif which python 2>/dev/null; then
+    if [ `python --version | awk '{print $2}' | cut -d. -f1` -ge 3 ]; then
+        PYTHON=python
+    fi
+fi
 
+$PYTHON commonmark/test/spec_tests.py -s commonmark/spec.txt -p "$PROGRAM" "$@"