diff options
author | Simon Glass <sjg@chromium.org> | 2020-06-14 10:54:07 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2020-07-09 18:57:22 -0600 |
commit | 5c430761e6a618032498fe294376a15a7ed1ee0b (patch) | |
tree | 9f868ea4ead18858a905f6141d6e4db6942ec916 /tools/patman/test_checkpatch.py | |
parent | 89fb8b75bce61c53867f80392cdef9cfc5dbc9cd (diff) |
patman: Add tests for the rest of the checkpatch checks
Finish off the tests for our small collection of checkpatch checks.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/patman/test_checkpatch.py')
-rw-r--r-- | tools/patman/test_checkpatch.py | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/tools/patman/test_checkpatch.py b/tools/patman/test_checkpatch.py index 7f40133b33..710b4a7d88 100644 --- a/tools/patman/test_checkpatch.py +++ b/tools/patman/test_checkpatch.py @@ -348,14 +348,53 @@ index 0000000..2234c87 self.assertEqual(result.lines, 62) os.remove(inf) + def checkSingleMessage(self, pm, msg, pmtype = 'warning'): + """Helper function to run checkpatch and check the result + + Args: + pm: PatchMaker object to use + msg" Expected message (e.g. 'LIVETREE') + pmtype: Type of problem ('error', 'warning') + """ + result = pm.run_checkpatch() + if pmtype == 'warning': + self.assertEqual(result.warnings, 1) + elif pmtype == 'error': + self.assertEqual(result.errors, 1) + if len(result.problems) != 1: + print(result.problems) + self.assertEqual(len(result.problems), 1) + self.assertIn(msg, result.problems[0]['cptype']) + def testUclass(self): """Test for possible new uclass""" pm = PatchMaker() pm.add_line('include/dm/uclass-id.h', 'UCLASS_WIBBLE,') - result = pm.run_checkpatch() - self.assertEqual(result.warnings, 1) - self.assertEqual(len(result.problems), 1) - self.assertIn('NEW_UCLASS', result.problems[0]['cptype']) + self.checkSingleMessage(pm, 'NEW_UCLASS') + + def testLivetree(self): + """Test for Use the livetree API""" + pm = PatchMaker() + pm.add_line('common/main.c', 'fdtdec_do_something()') + self.checkSingleMessage(pm, 'LIVETREE') + + def testNewCommand(self): + """Test for Use the livetree API""" + pm = PatchMaker() + pm.add_line('common/main.c', 'do_wibble(struct cmd_tbl *cmd_tbl)') + self.checkSingleMessage(pm, 'CMD_TEST') + + def testNewCommand(self): + """Test for Use the livetree API""" + pm = PatchMaker() + pm.add_line('common/main.c', '#ifdef CONFIG_YELLOW') + self.checkSingleMessage(pm, "PREFER_IF") + + def testCommandUseDefconfig(self): + """Test for Use the livetree API""" + pm = PatchMaker() + pm.add_line('common/main.c', '#undef CONFIG_CMD_WHICH') + self.checkSingleMessage(pm, 'DEFINE_CONFIG_CMD', 'error') if __name__ == "__main__": |