66 lines
3.1 KiB
Python
66 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
import json
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
from tempfile import TemporaryDirectory
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
|
|
from generate_test_entries import generate
|
|
|
|
|
|
class TestEntriesTests(unittest.TestCase):
|
|
def create_tree(self):
|
|
directory = TemporaryDirectory()
|
|
root = Path(directory.name)
|
|
test_dir = root / "linuxcnc/tests/demo"
|
|
unit_dir = root / "linuxcnc/unit_tests/tp"
|
|
test_dir.mkdir(parents=True)
|
|
unit_dir.mkdir(parents=True)
|
|
(test_dir / "test.sh").write_text("#!/bin/sh\nlinuxcnc demo.ini\n", encoding="utf-8")
|
|
(test_dir / "demo.ini").write_text("[EMC]\nMACHINE = demo\n", encoding="utf-8")
|
|
(test_dir / "expected.txt").write_text("ok\n", encoding="utf-8")
|
|
(test_dir / "checkresult").write_text("#!/bin/sh\nexit 0\n", encoding="utf-8")
|
|
(unit_dir / "meson.build").write_text("test('blendmath', executable('test_blendmath', 'test_blendmath.c'))\n", encoding="utf-8")
|
|
(unit_dir / "test_blendmath.c").write_text("int main(void) { return 0; }\n", encoding="utf-8")
|
|
(root / "linuxcnc/meson.build").write_text("test('top', executable('test_top', 'x.c'))\n", encoding="utf-8")
|
|
return directory, root
|
|
|
|
def test_entries_contain_contract_fields(self):
|
|
directory, root = self.create_tree()
|
|
self.addCleanup(directory.cleanup)
|
|
output = root / "coverage/test-entries.jsonl"
|
|
count, _ = generate(root, output, root / "coverage/report.json")
|
|
self.assertGreaterEqual(count, 4)
|
|
rows = [json.loads(line) for line in output.read_text(encoding="utf-8").splitlines()]
|
|
shell = next(row for row in rows if row["path"].endswith("/test.sh"))
|
|
self.assertEqual(shell["parse_status"], "parsed")
|
|
self.assertIn("linuxcnc/tests/demo/demo.ini", shell["inputs"])
|
|
self.assertIn("linuxcnc/tests/demo/expected.txt", shell["expected"])
|
|
self.assertEqual(shell["portability"], "portable_candidate")
|
|
|
|
def test_hardware_is_real_excluded(self):
|
|
directory, root = self.create_tree()
|
|
self.addCleanup(directory.cleanup)
|
|
test_path = root / "linuxcnc/tests/demo/test.sh"
|
|
test_path.write_text("#!/bin/sh\nloadrt hostmot2\n", encoding="utf-8")
|
|
generate(root, root / "out.jsonl", root / "report.json")
|
|
rows = [json.loads(line) for line in (root / "out.jsonl").read_text(encoding="utf-8").splitlines()]
|
|
shell = next(row for row in rows if row["path"].endswith("/test.sh"))
|
|
self.assertEqual(shell["portability"], "REAL-EXCLUDED")
|
|
|
|
def test_generation_is_deterministic(self):
|
|
directory, root = self.create_tree()
|
|
self.addCleanup(directory.cleanup)
|
|
first, digest_one = root / "one.jsonl", None
|
|
_, digest_one = generate(root, first, root / "report.json")
|
|
second, digest_two = root / "two.jsonl", None
|
|
_, digest_two = generate(root, second, root / "report.json")
|
|
self.assertEqual(digest_one, digest_two)
|
|
self.assertEqual(first.read_bytes(), second.read_bytes())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|