Skip to content

Commit a1c2f1f

Browse files
committed
test: add flag test
Signed-off-by: Zxilly <[email protected]>
1 parent b015701 commit a1c2f1f

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

scripts/ensure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
from argparse import ArgumentParser
33

4-
from tool.remote import load_remote_binaries
4+
from tool.remote import load_remote_binaries_as_test
55

66
if __name__ == "__main__":
77
ap = ArgumentParser()
@@ -20,4 +20,4 @@ def cond(name: str) -> bool:
2020
return not name.startswith("bin-")
2121
return True
2222

23-
load_remote_binaries(cond)
23+
load_remote_binaries_as_test(cond)

scripts/tests.py

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
from tool.html import assert_html_valid
1313
from tool.junit import generate_junit
1414
from tool.merge import merge_covdata
15-
from tool.remote import load_remote_binaries, load_remote_for_unit_test, TestType, get_flag_str
15+
from tool.process import run_process
16+
from tool.remote import load_remote_binaries_as_test, load_remote_for_unit_test, TestType, get_flag_str
1617
from tool.utils import log, get_project_root, ensure_dir, format_time, load_skip, get_covdata_integration_dir, \
1718
find_unused_port, init_dirs, write_github_summary
1819

@@ -173,12 +174,12 @@ def run_integration_tests(typ: str, gsa_path: str):
173174

174175
targets = []
175176
match typ:
176-
case "web":
177+
case "web" | "flag":
177178
pass # analyze itself, nothing to do
178179
case "example":
179-
targets = load_remote_binaries(lambda x: x.startswith("bin-"))
180+
targets = load_remote_binaries_as_test(lambda x: x.startswith("bin-"))
180181
case "real":
181-
targets = load_remote_binaries(lambda x: not x.startswith("bin-"))
182+
targets = load_remote_binaries_as_test(lambda x: not x.startswith("bin-"))
182183
case _:
183184
raise Exception(f"Unknown integration test type: {typ}")
184185

@@ -191,6 +192,9 @@ def run_integration_tests(typ: str, gsa_path: str):
191192
run_web_test(gsa_path)
192193
return
193194

195+
if typ == "flag":
196+
run_version_and_help_test(gsa_path)
197+
194198
all_tests = len(targets)
195199
completed_tests = 0
196200

@@ -222,13 +226,45 @@ def report_typ(rtyp: TestType):
222226
completed_tests += 1
223227

224228
if scope_failed_count == 0:
225-
log("Integration tests passed.")
229+
log(f"Integration tests {typ} passed.")
226230
else:
227-
log(f"{scope_failed_count} integration tests failed.")
231+
log(f"{scope_failed_count} {typ} integration tests failed.")
228232
global global_failed
229233
global_failed += scope_failed_count
230234

231235

236+
def run_version_and_help_test(entry: str):
237+
log("Running flag test...")
238+
239+
def get_file(n: str):
240+
d = os.path.join(get_project_root(), "results", n)
241+
ensure_dir(d)
242+
return os.path.join(d, f"{n}.output.txt")
243+
244+
try:
245+
[out, _] = run_process([entry, "--version"],
246+
"version",
247+
profiler_dir=os.path.join(get_project_root(), "results", "version", "profiler"),
248+
timeout=2,
249+
draw=False)
250+
251+
with open(get_file("version"), "w", encoding="utf-8") as f:
252+
f.write(out)
253+
254+
[out, _] = run_process([entry, "--help"],
255+
"help",
256+
profiler_dir=os.path.join(get_project_root(), "results", "help", "profiler"),
257+
timeout=2,
258+
draw=False)
259+
260+
with open(get_file("help"), "w", encoding="utf-8") as f:
261+
f.write(out)
262+
263+
except Exception as e:
264+
log(f"flag test failed: {e}")
265+
exit(1)
266+
267+
232268
def run_web_test(entry: str):
233269
log("Running web test...")
234270

@@ -345,6 +381,7 @@ def get_parser() -> ArgumentParser:
345381
with build_gsa() as gsa:
346382
if args.integration_example:
347383
run_integration_tests("web", gsa)
384+
run_integration_tests("flag", gsa)
348385
run_integration_tests("example", gsa)
349386
if args.integration_real:
350387
run_integration_tests("real", gsa)

scripts/tool/remote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def get_name(target_name: str):
246246
return ret
247247

248248

249-
def load_remote_binaries(cond: Callable[[str], bool]) -> list[IntegrationTest]:
249+
def load_remote_binaries_as_test(cond: Callable[[str], bool]) -> list[IntegrationTest]:
250250
log("Fetching remote binaries...")
251251

252252
with open(get_binaries_path(), "r", encoding="utf-8") as f:

0 commit comments

Comments
 (0)