diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2020-03-20 13:22:43 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2020-04-17 10:49:09 -0700 |
commit | e0c9259e79f21c6ee19f996c1f5d817d510de663 (patch) | |
tree | 22cd773b3b0ec7635ce1dfdf31ddbb93d5047fb3 /run_unittests.py | |
parent | 91050e0c7c4920d9e793e0b911f8f3255b4d0e3e (diff) | |
download | meson-e0c9259e79f21c6ee19f996c1f5d817d510de663.zip meson-e0c9259e79f21c6ee19f996c1f5d817d510de663.tar.gz meson-e0c9259e79f21c6ee19f996c1f5d817d510de663.tar.bz2 |
Add a json schema for the test.json used in tests
This does a couple of nice things, one is that editors like vscode can
be configured to use this schema to provide auto completion and error
highlighting if invalid values are added or required values are missing.
It also allows us test that the format of the test matrix work in a unit
test, which I've added. It does require that the python jsonschema
package is installed.
Diffstat (limited to 'run_unittests.py')
-rwxr-xr-x | run_unittests.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/run_unittests.py b/run_unittests.py index 4cd6e17..cc294dd 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -1227,6 +1227,32 @@ class InternalTests(unittest.TestCase): actual = [m() for m in f(env, MachineChoice.HOST, {'required': False})] self.assertListEqual([m.type_name for m in actual], ['cmake', 'pkgconfig']) + def test_validate_json(self) -> None: + """Validate the json schema for the test cases.""" + try: + from jsonschema import validate, ValidationError + except ImportError: + if is_ci(): + raise + raise unittest.SkipTest('Python jsonschema module not found.') + + with Path('data/test.schema.json').open() as f: + schema = json.load(f) + + errors = [] # type: T.Tuple[str, Exception] + for p in Path('test cases').glob('**/test.json'): + with p.open() as f: + try: + validate(json.load(f), schema=schema) + except ValidationError as e: + errors.append((p.resolve(), e)) + + for f, e in errors: + print('Failed to validate: "{}"'.format(f)) + print(str(e)) + + self.assertFalse(errors) + @unittest.skipIf(is_tarball(), 'Skipping because this is a tarball release') class DataTests(unittest.TestCase): |