tests: Windows fixes
authorJannis Harder <me@jix.one>
Tue, 5 Jul 2022 13:34:27 +0000 (15:34 +0200)
committerJannis Harder <me@jix.one>
Tue, 5 Jul 2022 13:34:27 +0000 (15:34 +0200)
Make tests runnable on Windows, as long as a unix like environment as
e.g. provided by MSYS2 is available.

tests/Makefile
tests/make/collect_tests.py
tests/make/test_rules.py

index 9b65da77378f45ac0b40ea731ee5fc516967b6ed..805d1909f29796a6fab9b59dba082ab2cb7b5f8e 100644 (file)
@@ -2,11 +2,27 @@ test:
 
 .PHONY: test clean refresh help
 
+OS_NAME := $(shell python3 -c "import os;print(os.name)")
+ifeq (nt,$(OS_NAME))
+ifeq (quoted,$(shell echo "quoted"))
+OS_NAME := nt-unix-like
+endif
+endif
+
+ifeq (nt,$(OS_NAME))
+$(error This Makefile requires unix-like tools and shell, e.g. MSYS2.)
+endif
+
 help:
        @cat make/help.txt
 
-export SBY_WORKDIR_GITIGNORE=1
-export SBY_MAIN=$(realpath $(dir $(firstword $(MAKEFILE_LIST)))/../sbysrc/sby.py)
+export SBY_WORKDIR_GITIGNORE := 1
+
+SBY_MAIN := $(realpath $(dir $(firstword $(MAKEFILE_LIST)))/../sbysrc/sby.py)
+ifeq (nt-unix-like,$(OS_NAME))
+SBY_MAIN := $(shell cygpath -w $(SBY_MAIN))
+endif
+export SBY_MAIN
 
 make/rules/collect.mk: make/collect_tests.py
        python3 make/collect_tests.py
index 89a68ecaaf009a541f9304f8483f73d5954e6540..b5f769964648548a69c946a33283a2477d99a176 100644 (file)
@@ -4,7 +4,8 @@ import re
 tests = []
 checked_dirs = []
 
-SAFE_PATH = re.compile(r"^[a-zA-Z0-9_./]*$")
+SAFE_PATH = re.compile(r"^[a-zA-Z0-9_./\\]*$")
+
 
 def collect(path):
     # don't pick up any paths that need escaping nor any sby workdirs
@@ -15,8 +16,6 @@ def collect(path):
     for entry in path.glob("*.sby"):
         filename = str(entry)
         if not SAFE_PATH.match(filename):
-            continue
-        if not re.match(r"^[a-zA-Z0-9_./]*$", filename):
             print(f"skipping {filename!r}, use only [a-zA-Z0-9_./] in filenames")
             continue
         tests.append(entry)
@@ -25,6 +24,10 @@ def collect(path):
             collect(entry)
 
 
+def unix_path(path):
+    return "/".join(path.parts)
+
+
 collect(Path("."))
 collect(Path("../docs/examples"))
 
@@ -33,16 +36,18 @@ out_file.parent.mkdir(exist_ok=True)
 
 with out_file.open("w") as output:
 
-
     for checked_dir in checked_dirs:
         print(f"{out_file}: {checked_dir}", file=output)
 
     for test in tests:
-        print(f"make/rules/test/{test}.mk: {test}", file=output)
+        test_unix = unix_path(test)
+        print(f"make/rules/test/{test_unix}.mk: {test_unix}", file=output)
         for ext in [".sh", ".py"]:
             script_file = test.parent / (test.stem + ext)
             if script_file.exists():
-                print(f"make/rules/test/{test}.mk: {script_file}", file=output)
-        print(f"make/rules/test/{test}.mk: make/test_rules.py", file=output)
+                script_file_unix = unix_path(script_file)
+                print(f"make/rules/test/{test_unix}.mk: {script_file_unix}", file=output)
+        print(f"make/rules/test/{test_unix}.mk: make/test_rules.py", file=output)
     for test in tests:
-        print(f"-include make/rules/test/{test}.mk", file=output)
+        test_unix = unix_path(test)
+        print(f"-include make/rules/test/{test_unix}.mk", file=output)
index 5c18acadffafd66cc03c7cb073d1db19aec6de9e..9607d814c4ac646b4ed35ded98813ff27455349d 100644 (file)
@@ -7,6 +7,11 @@ from pathlib import Path
 
 from required_tools import REQUIRED_TOOLS
 
+
+def unix_path(path):
+    return "/".join(path.parts)
+
+
 sby_file = Path(sys.argv[1])
 sby_dir = sby_file.parent
 
@@ -56,7 +61,10 @@ with rules_file.open("w") as rules:
                 solvers.add(solver)
                 engine_solvers.add((engine, solver))
 
-        if any(line.startswith("read -verific") or line.startswith("verific") for line in info["script"]):
+        if any(
+            line.startswith("read -verific") or line.startswith("verific")
+            for line in info["script"]
+        ):
             required_tools.add("verific")
 
         required_tools = sorted(required_tools)
@@ -66,12 +74,17 @@ with rules_file.open("w") as rules:
 
         shell_script = sby_dir / f"{sby_file.stem}.sh"
 
+        sby_dir_unix = unix_path(sby_dir)
+
         if shell_script.exists():
-            command = f"cd {sby_dir} && SBY_FILE={sby_file.name} WORKDIR={workdirname} TASK={task} bash {shell_script.name}"
+            command = f"cd {sby_dir_unix} && env SBY_FILE={sby_file.name} WORKDIR={workdirname} TASK={task} bash {shell_script.name}"
         else:
-            command = f"cd {sby_dir} && python3 $(SBY_MAIN) -f {sby_file.name} {task}"
+            command = f"cd {sby_dir_unix} && python3 $(SBY_MAIN) -f {sby_file.name} {task}"
 
-        print(f"\t@python3 make/required_tools.py run {target} {shlex.quote(command)} {shlex.join(required_tools)}", file=rules)
+        print(
+            f"\t@python3 make/required_tools.py run {target} {shlex.quote(command)} {shlex.join(required_tools)}",
+            file=rules,
+        )
 
         print(f".PHONY: clean-{target}", file=rules)
         print(f"clean-{target}:", file=rules)