Commit e7c4392cd1c0bb491ff408a8a99eb8c11d6c5cd1

Martin Mitáš 2024-02-04T01:40:43

CI: Run test also on Windows runners.

diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml
index 20da207..22f4c5c 100644
--- a/.github/workflows/ci-build.yml
+++ b/.github/workflows/ci-build.yml
@@ -20,7 +20,7 @@ jobs:
       - name: Build
         run: make VERBOSE=1
       - name: Test
-        run: ./scripts/run-tests.sh
+        run: python3 ./scripts/run-tests.py
       - name: Create coverage report
         run: |
           sudo apt-get install -y lcov
@@ -29,6 +29,7 @@ jobs:
           lcov --list coverage.info
       - name: Upload coverage report
         uses: codecov/codecov-action@v3
+
   linux-release:
     runs-on: ubuntu-latest
     steps:
@@ -39,7 +40,7 @@ jobs:
       - name: Build
         run: make VERBOSE=1
       - name: Test
-        run: ./scripts/run-tests.sh
+        run: python3 ./scripts/run-tests.py
 
   # Windows builds.
   #
@@ -58,6 +59,10 @@ jobs:
         run: cmake -DCMAKE_BUILD_TYPE=Debug -G "NMake Makefiles" .
       - name: Build
         run: nmake
+      - name: Setyp Python
+        uses: actions/setup-python@v5
+      - name: Test
+        run: python .\scripts\run-tests.py
 
   windows-64-release:
     runs-on: windows-latest
@@ -72,3 +77,5 @@ jobs:
         run: cmake -DCMAKE_BUILD_TYPE=Release -G "NMake Makefiles" .
       - name: Build
         run: nmake
+      - name: Test
+        run: python .\scripts\run-tests.py
diff --git a/scripts/run-tests.py b/scripts/run-tests.py
new file mode 100644
index 0000000..d71cc7b
--- /dev/null
+++ b/scripts/run-tests.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python3
+
+import glob
+import os
+import subprocess
+import sys
+
+
+argv0_dir = os.path.dirname(sys.argv[0])
+project_dir = os.path.abspath(os.path.join(argv0_dir, ".."))
+test_dir = os.path.join(project_dir, "test")
+program = os.path.abspath(os.path.join("md2html", "md2html"))
+
+if __name__ == "__main__":
+    err_count = 0
+
+    os.chdir(test_dir)
+
+    for testsuite in glob.glob('*.txt'):
+        print("Testing {}".format(testsuite))
+        sys.stdout.flush()
+        sys.stderr.flush()
+        args = [
+                sys.executable,
+                "run-testsuite.py",
+                "-s", testsuite,
+                "-p", str(program)
+        ]
+        p = subprocess.run(args)
+        if p.returncode != 0:
+            err_count += 1
+        print()
+
+    print("Testing pathological inputs:")
+    sys.stdout.flush()
+    sys.stderr.flush()
+    args = [
+            sys.executable,
+            "pathological-tests.py",
+            "-p", str(program)
+    ]
+    subprocess.run(args)
+    if p.returncode != 0:
+        err_count += 1
+
+    sys.exit(err_count)
diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh
deleted file mode 100755
index 8af7684..0000000
--- a/scripts/run-tests.sh
+++ /dev/null
@@ -1,75 +0,0 @@
-#!/bin/sh
-#
-# Run this script from build directory.
-
-#set -e
-
-SELF_DIR=`dirname $0`
-PROJECT_DIR="$SELF_DIR/.."
-TEST_DIR="$PROJECT_DIR/test"
-
-
-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 which py >>/dev/null 2>&1; then
-    PYTHON=py
-elif which python3 >>/dev/null 2>&1; then
-    PYTHON=python3
-elif which python >>/dev/null 2>&1; then
-    if [ `python --version | awk '{print $2}' | cut -d. -f1` -ge 3 ]; then
-        PYTHON=python
-    fi
-fi
-
-echo
-echo "CommonMark specification:"
-$PYTHON "$TEST_DIR/run-testsuite.py" -s "$TEST_DIR/spec.txt" -p "$PROGRAM"
-
-echo
-echo "Permissive autolink extensions:"
-$PYTHON "$TEST_DIR/run-testsuite.py" -s "$TEST_DIR/spec-permissive-autolinks.txt" -p "$PROGRAM"
-
-echo
-echo "Hard soft breaks extension:"
-$PYTHON "$TEST_DIR/run-testsuite.py" -s "$TEST_DIR/spec-hard-soft-breaks.txt" -p "$PROGRAM"
-
-echo
-echo "Tables extension:"
-$PYTHON "$TEST_DIR/run-testsuite.py" -s "$TEST_DIR/spec-tables.txt" -p "$PROGRAM"
-
-echo
-echo "Strikethrough extension:"
-$PYTHON "$TEST_DIR/run-testsuite.py" -s "$TEST_DIR/spec-strikethrough.txt" -p "$PROGRAM"
-
-echo
-echo "Task lists extension:"
-$PYTHON "$TEST_DIR/run-testsuite.py" -s "$TEST_DIR/spec-tasklists.txt" -p "$PROGRAM"
-
-echo
-echo "LaTeX extension:"
-$PYTHON "$TEST_DIR/run-testsuite.py" -s "$TEST_DIR/spec-latex-math.txt" -p "$PROGRAM"
-
-echo
-echo "Wiki links extension:"
-$PYTHON "$TEST_DIR/run-testsuite.py" -s "$TEST_DIR/spec-wiki-links.txt" -p "$PROGRAM"
-
-echo
-echo "Underline extension:"
-$PYTHON "$TEST_DIR/run-testsuite.py" -s "$TEST_DIR/spec-underline.txt" -p "$PROGRAM"
-
-echo
-echo "Code coverage:"
-$PYTHON "$TEST_DIR/run-testsuite.py" -s "$TEST_DIR/coverage.txt" -p "$PROGRAM"
-
-echo
-echo "Regressions:"
-$PYTHON "$TEST_DIR/run-testsuite.py" -s "$TEST_DIR/regressions.txt" -p "$PROGRAM"
-
-echo
-echo "Pathological inputs:"
-$PYTHON "$TEST_DIR/pathological-tests.py" -p "$PROGRAM"