Introduce presubmit check for stable mojom changes
Mojom types marked [Stable] must preserve backward-compatibility over
time. This presubmit tool checks for unsafe changes to any such types.
Fixed: 1070663
Change-Id: Ie1d3ca30d608dd95e256c782593c9df910512e96
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2219020
Commit-Queue: Ken Rockot <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Cr-Commit-Position: refs/heads/master@{#773276}
diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py
index dd98461..49c32bfd 100755
--- a/PRESUBMIT_test.py
+++ b/PRESUBMIT_test.py
@@ -3491,5 +3491,31 @@
self.assertEqual([], errors)
+class MojomStabilityCheckTest(unittest.TestCase):
+ def runTestWithAffectedFiles(self, affected_files):
+ mock_input_api = MockInputApi()
+ mock_input_api.files = affected_files
+ mock_output_api = MockOutputApi()
+ return PRESUBMIT._CheckStableMojomChanges(
+ mock_input_api, mock_output_api)
+
+ def testSafeChangePasses(self):
+ errors = self.runTestWithAffectedFiles([
+ MockAffectedFile('foo/foo.mojom',
+ ['[Stable] struct S { [MinVersion=1] int32 x; };'],
+ old_contents=['[Stable] struct S {};'])
+ ])
+ self.assertEqual([], errors)
+
+ def testBadChangeFails(self):
+ errors = self.runTestWithAffectedFiles([
+ MockAffectedFile('foo/foo.mojom',
+ ['[Stable] struct S { int32 x; };'],
+ old_contents=['[Stable] struct S {};'])
+ ])
+ self.assertEqual(1, len(errors))
+ self.assertTrue('not backward-compatible' in errors[0].message)
+
+
if __name__ == '__main__':
unittest.main()