This patch adds a "checker" that always fails, for ensuring that we can handle failed runs of 3rd-party tools.
checkers/ChangeLog: * always_fails.py: New file. --- checkers/always_fails.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 checkers/always_fails.py diff --git a/checkers/always_fails.py b/checkers/always_fails.py new file mode 100755 index 0000000..35fd4ac --- /dev/null +++ b/checkers/always_fails.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# Copyright 2012, 2013, 2015, 2017 David Malcolm <dmalc...@redhat.com> +# Copyright 2012, 2013, 2015, 2017 Red Hat, Inc. +# +# This is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see +# <http://www.gnu.org/licenses/>. + +import sys +import unittest + +from firehose.model import Failure + +from checker import Checker, CheckerTests, tool_main + +class AlwaysFails(Checker): + """ + Checker subclass that always fails + """ + name = 'always-fails' + + def raw_invoke(self, gccinv, sourcefile): + args = ['/this/executable/does/not/exist', sourcefile] + return self._run_subprocess(sourcefile, args) + +class AlwaysFailsTests(CheckerTests): + def make_tool(self): + tool_class = AlwaysFails + ctxt = self.make_ctxt(tool_class.name, capture_exceptions=True) + return tool_class(ctxt) + + def verify_basic_metadata(self, analysis, sourcefile): + # Verify basic metadata: + self.assert_metadata(analysis, 'always-fails', sourcefile) + + def test_harmless_file(self): + analysis = self.invoke('test-sources/harmless.c') + self.assertEqual(len(analysis.results), 1) + r0 = analysis.results[0] + self.assertIsInstance(r0, Failure) + self.assertEqual(r0.failureid, 'exception') + self.assertEqual(r0.location.file.givenpath, + 'test-sources/harmless.c') + self.assertNotEqual(r0.message.text, None) + +if __name__ == '__main__': + sys.exit(tool_main(sys.argv, AlwaysFails)) -- 1.8.5.3