summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2022-01-01 11:13:06 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2022-01-01 11:13:06 +0000
commitd4856f7b04b5f58118e518fd2a3413363dcad6ce (patch)
tree8ca872103fb5c4a47bfab1b0896df7549f20f8dc
parent3d764c2b7f3c8871d100297e8d7ed01810df9e0d (diff)
downloadsubplot-d4856f7b04b5f58118e518fd2a3413363dcad6ce.tar.gz
check: Cope with polyglot documents
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
-rwxr-xr-xcheck71
1 files changed, 37 insertions, 34 deletions
diff --git a/check b/check
index cb5ffc1..2582709 100755
--- a/check
+++ b/check
@@ -114,7 +114,7 @@ class Runcmd:
]
return subcommand in lines
- def codegen(self, md, output, **kwargs):
+ def codegen(self, md, template, output, **kwargs):
"""Run the Subplot code generator and the test program it produces"""
self.cargo(
[
@@ -124,6 +124,7 @@ class Runcmd:
"--",
f"--resources={os.path.abspath('share')}",
"codegen",
+ f"--template={template}",
md,
f"--output={output}",
],
@@ -160,7 +161,7 @@ class Runcmd:
**kwargs,
)
- def get_template(self, filename):
+ def get_templates(self, filename):
metadata = self.cargo(
[
"run",
@@ -181,7 +182,7 @@ class Runcmd:
if not impls:
sys.exit(f"{filename} does not specify a template")
impl_names = [name for name in impls.keys()]
- return impl_names[0]
+ return impl_names
def find_files(pattern, pred):
@@ -270,38 +271,40 @@ def check_subplots(r):
md = os.path.basename(md0)
base, _ = os.path.splitext(md)
- template = r.get_template(md0)
- if template == "python":
- test_py = os.path.join(output, f"test-{base}.py")
- test_log = os.path.join(output, f"test-{base}.log")
-
- # Remove test log from previous run, if any.
- if os.path.exists(test_log):
- os.remove(test_log)
-
- bindir = get_bin_dir(r)
-
- r.codegen(md, test_py, cwd=dirname)
- p = r.runcmd_unchecked(
- [
- "python3",
- test_py,
- "--log",
- test_log,
- f"--env=SUBPLOT_DIR={bindir}",
- ],
- cwd=dirname,
- )
- if p.returncode != 0:
+ for template in r.get_templates(md0):
+ if template == "python":
+ test_py = os.path.join(output, f"test-{base}.py")
+ test_log = os.path.join(output, f"test-{base}.log")
+
+ # Remove test log from previous run, if any.
if os.path.exists(test_log):
- tail(test_log)
- sys.exit(1)
- elif template == "bash":
- test_sh = os.path.join(output, f"test-{base}.sh")
- r.codegen(md, test_sh, cwd=dirname)
- r.runcmd(["bash", "-x", test_sh], cwd=dirname)
- else:
- sys.exit(f"unknown template {template} in {md0}")
+ os.remove(test_log)
+
+ bindir = get_bin_dir(r)
+
+ r.codegen(md, "python", test_py, cwd=dirname)
+ p = r.runcmd_unchecked(
+ [
+ "python3",
+ test_py,
+ "--log",
+ test_log,
+ f"--env=SUBPLOT_DIR={bindir}",
+ ],
+ cwd=dirname,
+ )
+ if p.returncode != 0:
+ if os.path.exists(test_log):
+ tail(test_log)
+ sys.exit(1)
+ elif template == "bash":
+ test_sh = os.path.join(output, f"test-{base}.sh")
+ r.codegen(md, "bash", test_sh, cwd=dirname)
+ r.runcmd(["bash", "-x", test_sh], cwd=dirname)
+ elif template == "rust":
+ r.msg(f"Ignoring Rust template in {md0}")
+ else:
+ sys.exit(f"unknown template {template} in {md0}")
base = os.path.basename(md)
base, _ = os.path.splitext(md)