Skip to content
This repository was archived by the owner on Feb 10, 2026. It is now read-only.

Commit 20cabfa

Browse files
committed
test.py: only run *.gen.sh scripts actually generated during that run
Otherwise, a previously generated `*.gen.sh` file will still be run even if it's no longer supposed to be generated (and isn't anymore).
1 parent 7afd5be commit 20cabfa

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ def print_requirements(args):
4242
elif not conf.project_dirs and len(args.projects) > 0:
4343
util.die(f"no such project: {args.project}")
4444
else:
45-
templates.autogen(conf)
46-
tests.run_tests(conf)
45+
generated_scripts = set(templates.autogen(conf))
46+
tests.run_tests(conf, generated_scripts)

tests/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ class Test(object):
2121
"check": ["check.sh", "test.sh"]
2222
}
2323

24-
def __init__(self, directory: str):
24+
def __init__(self, directory: str, generated_scripts: set[str]):
2525
ff = next(os.walk(directory))[2]
26-
self.scripts = set(filter(lambda f: f.endswith(".sh"), ff))
26+
self.scripts = {
27+
f for f in ff if f.endswith(".sh") and
28+
(not f.endswith(".gen.sh") or f in generated_scripts)
29+
}
2730
self.dir = directory
2831
self.conf_file = os.path.join(directory, CONF_YML)
2932
self.name = os.path.basename(directory)
@@ -206,11 +209,11 @@ def __call__(self, conf: Config):
206209
return True
207210

208211

209-
def run_tests(conf):
212+
def run_tests(conf: Config, generated_scripts: set[str]):
210213
if not conf.ignore_requirements:
211214
check(conf)
212215

213-
tests = [Test(td) for td in conf.project_dirs]
216+
tests = [Test(td, generated_scripts) for td in conf.project_dirs]
214217

215218
failure = False
216219
for tt in tests:

tests/templates.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import stat
33
from collections.abc import Mapping
4-
from typing import Any, Dict, List
4+
from typing import Any, Dict, Generator, List
55

66
from tests.util import *
77
from jinja2 import Template
@@ -94,16 +94,16 @@ def render_script(template: str, out_path: str, params: Dict):
9494
os.chmod(out_path, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)
9595

9696

97-
def autogen_cargo(conf_file, yaml: Dict):
98-
def render_stage(stage_conf: Mapping[str, Any] | None, filename: str) -> bool:
97+
def autogen_cargo(conf_file, yaml: Dict) -> Generator[str]:
98+
def render_stage(stage_conf: Mapping[str, Any] | None, filename: str) -> Generator[str]:
9999
if not isinstance(stage_conf, Mapping):
100-
return False
100+
return
101101
if not stage_conf:
102-
return False
102+
return
103103

104104
ag = stage_conf.get("autogen")
105105
if not (ag and isinstance(ag, bool)):
106-
return False
106+
return
107107

108108
params: Dict[str, str] = {}
109109
rustflags = stage_conf.get("rustflags")
@@ -115,16 +115,16 @@ def render_stage(stage_conf: Mapping[str, Any] | None, filename: str) -> bool:
115115
filename
116116
)
117117
render_script(CARGO_SH, out_path, params)
118-
return True
118+
yield out_path
119119

120120
for key, fname in (
121121
("cargo.transpile", "cargo.transpile.gen.sh"),
122122
("cargo.refactor", "cargo.refactor.gen.sh"),
123123
):
124-
render_stage(yaml.get(key), fname)
124+
yield from render_stage(yaml.get(key), fname)
125125

126126

127-
def autogen_refactor(conf_file, yaml: Dict):
127+
def autogen_refactor(conf_file, yaml: Dict) -> Generator[str]:
128128
refactor = yaml.get("refactor")
129129
if refactor and isinstance(refactor, Dict):
130130
ag = refactor.get("autogen")
@@ -149,9 +149,10 @@ def autogen_refactor(conf_file, yaml: Dict):
149149
"refactor.gen.sh"
150150
)
151151
render_script(REFACTOR_SH, out_path, params)
152+
yield out_path
152153

153154

154-
def autogen_transpile(conf_file, yaml: Dict):
155+
def autogen_transpile(conf_file, yaml: Dict) -> Generator[str]:
155156
transpile = yaml.get("transpile")
156157
if transpile and isinstance(transpile, Dict):
157158
ag = transpile.get("autogen")
@@ -180,10 +181,11 @@ def autogen_transpile(conf_file, yaml: Dict):
180181
"transpile.gen.sh"
181182
)
182183
render_script(TRANSPILE_SH, out_path, params)
184+
yield out_path
183185

184186

185-
def autogen(conf: Config):
187+
def autogen(conf: Config) -> Generator[str]:
186188
for (cf, yaml) in conf.project_conf.items():
187-
autogen_transpile(cf, yaml)
188-
autogen_refactor(cf, yaml)
189-
autogen_cargo(cf, yaml)
189+
yield from autogen_transpile(cf, yaml)
190+
yield from autogen_refactor(cf, yaml)
191+
yield from autogen_cargo(cf, yaml)

0 commit comments

Comments
 (0)