Skip to content

Commit 3bd428e

Browse files
committed
Add regression test for test-spec JSON bug
Signed-off-by: Joachim Wiberg <[email protected]>
1 parent 261d3a9 commit 3bd428e

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

self_test/cases/worker.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
= Worker Test Specification
2+
3+
This is a test specification for the worker test case.

self_test/run.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,55 @@ def test_repeat_flag(self):
328328
}
329329
)
330330

331+
def test_spec_json_format(self):
332+
"""Verify test_spec and test_spec_sha keys in JSON output"""
333+
334+
self.env = os.environ.copy()
335+
self.env["NINEPM_TEST_DIR"] = self.create_unique_subdir()
336+
337+
result = subprocess.run(
338+
["python3", self.ninepm, "suites/test-spec.yaml"],
339+
cwd=self.script_dir,
340+
text=True,
341+
env=self.env,
342+
stdout=subprocess.PIPE,
343+
stderr=subprocess.PIPE,
344+
)
345+
346+
if VERBOSE:
347+
print(result.stdout)
348+
print(result.stderr, file=sys.stderr)
349+
350+
assert result.returncode == 0, f"Failed with return code {result.returncode}"
351+
352+
json_path = os.path.join(os.path.expanduser('~/.local/share/9pm/logs/last'), 'result.json')
353+
assert os.path.exists(json_path), f"Could not find {json_path}"
354+
355+
with open(json_path, 'r') as f:
356+
data = json.load(f)
357+
358+
def find_test_spec(obj):
359+
if isinstance(obj, dict):
360+
if 'test_spec' in obj:
361+
return obj
362+
for value in obj.values():
363+
result = find_test_spec(value)
364+
if result:
365+
return result
366+
elif isinstance(obj, list):
367+
for item in obj:
368+
result = find_test_spec(item)
369+
if result:
370+
return result
371+
return None
372+
373+
case = find_test_spec(data['suite'])
374+
assert case is not None, "Could not find test_spec in JSON"
375+
assert 'test_spec' in case, "Missing test_spec key"
376+
assert 'test_spec_sha' in case, "Missing test_spec_sha key"
377+
378+
print_green(f"[PASS] Test spec JSON output")
379+
331380
def cleanup(self):
332381
"""Cleanup temp directory after tests"""
333382
self.temp_dir_base.cleanup()
@@ -357,6 +406,7 @@ def cleanup(self):
357406
tester.test_abort_flag()
358407
tester.test_repeat_flag()
359408
tester.test_proj_config()
409+
tester.test_spec_json_format()
360410
print_green("All tests passed.")
361411
finally:
362412
tester.cleanup()

self_test/suites/test-spec.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- settings:
3+
test-spec: <case>.adoc
4+
5+
- case: "../cases/worker.py"

self_test/test_json_format.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python3
2+
"""Verify test_spec and test_spec_sha keys in JSON output"""
3+
4+
import sys
5+
import os
6+
7+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
8+
9+
from run import Test9pm
10+
11+
if __name__ == "__main__":
12+
tester = Test9pm()
13+
try:
14+
tester.test_spec_json_format()
15+
sys.exit(0)
16+
except AssertionError as e:
17+
print(f"\n✗ Test failed: {e}")
18+
sys.exit(1)
19+
finally:
20+
tester.cleanup()

0 commit comments

Comments
 (0)