Initial LinuxCNC WebAssembly workspace snapshot
This commit is contained in:
59
scripts/test_source_symbols.py
Normal file
59
scripts/test_source_symbols.py
Normal file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
|
||||
from generate_source_symbols import generate, parse_file
|
||||
|
||||
|
||||
class SourceSymbolsTests(unittest.TestCase):
|
||||
def test_parses_c_python_and_comp_entries(self):
|
||||
with TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
for sub in ("linuxcnc/src/emc", "linuxcnc/src/hal", "linuxcnc/lib/python"):
|
||||
(root / sub).mkdir(parents=True, exist_ok=True)
|
||||
c = root / "linuxcnc/src/emc/demo.c"
|
||||
c.write_text("#define DEMO 1\nint demo(int x) { return x; }\n", encoding="utf-8")
|
||||
py = root / "linuxcnc/lib/python/demo.py"
|
||||
py.write_text("class Demo:\n async def run(self):\n pass\n", encoding="utf-8")
|
||||
comp = root / "linuxcnc/src/hal/demo.comp"
|
||||
comp.write_text("component demo;\npin in bit enable;\nfunction update;\n", encoding="utf-8")
|
||||
rows, report = parse_file(root, c)
|
||||
self.assertEqual({row["symbol"] for row in rows}, {"DEMO", "demo"})
|
||||
self.assertEqual(report["parse_status"], "parsed")
|
||||
rows, _ = parse_file(root, py)
|
||||
self.assertEqual({row["symbol_kind"] for row in rows}, {"class", "async_function"})
|
||||
rows, _ = parse_file(root, comp)
|
||||
self.assertEqual({row["symbol_kind"] for row in rows}, {"component", "pin", "function"})
|
||||
|
||||
def test_generation_is_deterministic(self):
|
||||
with TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
for sub in ("linuxcnc/src/emc", "linuxcnc/src/hal", "linuxcnc/lib/python"):
|
||||
(root / sub).mkdir(parents=True, exist_ok=True)
|
||||
(root / "linuxcnc/src/emc/demo.c").write_text("void z(void) {}\n", encoding="utf-8")
|
||||
first = root / "one.jsonl"
|
||||
second = root / "two.jsonl"
|
||||
report = root / "report.json"
|
||||
_, digest_one = generate(root, first, report)
|
||||
_, digest_two = generate(root, second, report)
|
||||
self.assertEqual(digest_one, digest_two)
|
||||
self.assertEqual(first.read_bytes(), second.read_bytes())
|
||||
|
||||
def test_decode_error_is_reported(self):
|
||||
with TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
path = root / "linuxcnc/src/emc"
|
||||
path.mkdir(parents=True)
|
||||
bad = path / "bad.c"
|
||||
bad.write_bytes(b"\xff\xfe")
|
||||
rows, report = parse_file(root, bad)
|
||||
self.assertEqual(rows, [])
|
||||
self.assertEqual(report["parse_status"], "decode_error")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user