Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/TestCatalogTests.py

Source at documentation-generation time. See Test catalog for fixture associations.

1"""Regression checks for the documentation inventory, without running game tests."""
2import importlib.util
3import json
4from pathlib import Path
5import unittest
6
7ROOT = Path(__file__).resolve().parents[1]
8SPEC = importlib.util.spec_from_file_location('catalog', ROOT / 'docs/BuildTestCatalog.py')
9catalog = importlib.util.module_from_spec(SPEC)
10SPEC.loader.exec_module(catalog)
11
12
13class CatalogTests(unittest.TestCase):
14 def test_raw_shader_and_comments_are_not_cases(self):
15 """Ignore apparent test functions embedded in shaders, comments and strings."""
16 source = '''const char* shader = R"HLSL(
17void Fake() { Check(false, "not a C++ test"); }
18)HLSL";
19// void AlsoFake() { Check(false, "comment"); }
20void Actual() { Check(true, "real assertion"); }
21'''
22 self.assertEqual(list(catalog.cpp_cases(source)), ['Actual'])
23
24 def test_nested_expression_strings_are_not_descriptions(self):
25 """Keep assertion messages separate from strings inside the tested expression."""
26 source = 'void Case() { Check(Find("input") == 0, "expected " "behavior"); }'
27 self.assertEqual(catalog.cpp_cases(source)['Case']['messages'], ['expected behavior'])
28
29 def test_function_try_and_lowercase_checks(self):
30 """Include function-try entry points and lowercase local assertion helpers."""
31 source = 'int main() try { check(true, "visible pixels"); } catch(...) { return 1; }'
32 self.assertEqual(catalog.cpp_cases(source)['main']['messages'], ['visible pixels'])
33
34 def test_dispatchers_are_not_extra_cases(self):
35 """Do not count assertion-free dispatchers as additional verification cases."""
36 self.assertEqual(catalog.cpp_cases('int main() { CaseOne(); CaseTwo(); }'), {})
37
38 def test_unlabelled_entry_assertions_are_retained(self):
39 """Retain an entry point that uses unlabeled C++ assertions for editorial description."""
40 self.assertIn('main', catalog.cpp_cases('int main() { assert(value == 5); }'))
41
42 def test_python_classes_disambiguate_method_names(self):
43 """Associate identically named unittest methods with their actual fixture classes."""
44 source = 'class One:\n def test_value(self): pass\nclass Two:\n def test_value(self): pass\n'
45 self.assertEqual(set(catalog.python_cases(source)), {'One.test_value', 'Two.test_value'})
46
47 def test_documentation_metacharacters_are_escaped(self):
48 """Preserve readable punctuation while escaping HTML and Doxygen syntax."""
49 escaped = catalog.escape('<script> @page bad */ \\ref other a/b_name')
50 for token in ('<script>', '*/', '&#'):
51 self.assertNotIn(token, escaped)
52 self.assertIn(r'\@page', escaped)
53 self.assertIn(r'\\ref', escaped)
54 self.assertIn(r'a/b\_name', escaped)
55
56 def test_fixture_includes_are_explicit(self):
57 """Resolve shared case headers through their real entry-point include chain."""
58 sources = catalog.includes('Tests/TerrainAwarenessTests.cpp')
59 self.assertIn('Tests/GpwsControlsTests.h', sources)
60 self.assertNotIn('Tests/TcasTests.cpp', sources)
61
62 def test_verification_helpers_without_test_suffix_are_cataloged(self):
63 """Include assertion-bearing fixture helpers even without Tests in their filename."""
64 self.assertIn('Tests/LandingLightCollisionChecks.h', catalog.inventory())
65
66 def test_unregistered_and_removed_cases_are_rejected(self):
67 """Reject case additions/removals until the reviewed manifest is updated."""
68 data = json.loads(catalog.read(catalog.MANIFEST))
69 fixture = next(f for f in data['fixtures'] if f['id'] == 'tcastests')
70 cases = fixture['sources']['Tests/TcasTests.cpp']['cases']
71 cases.pop('InhibitsAndResets')
72 cases['RemovedCase'] = 'This no longer exists.'
73 with self.assertRaisesRegex(ValueError, 'Uncataloged case:.*InhibitsAndResets'):
74 catalog.generate(data)
75
76 def test_incorrect_fixture_association_is_rejected(self):
77 """Reject a real test source assigned to an unrelated fixture."""
78 data = json.loads(catalog.read(catalog.MANIFEST))
79 fixture = next(f for f in data['fixtures'] if f['id'] == 'tcastests')
80 source = 'Tests/VehicleVisibilityTests.cpp'
81 fixture['sources'][source] = {'cases': {
82 key: 'Compile-time visibility checks.' for key in catalog.source_cases(source)}}
83 with self.assertRaisesRegex(ValueError, 'Source does not belong to fixture tcastests'):
84 catalog.generate(data)
85
86
87if __name__ == '__main__':
88 unittest.main()