This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 14/22] Add checkers/always_fails.py
- From: David Malcolm <dmalcolm at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: David Malcolm <dmalcolm at redhat dot com>
- Date: Fri, 4 Aug 2017 18:04:45 -0400
- Subject: [PATCH 14/22] Add checkers/always_fails.py
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=dmalcolm at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D2DF64DAF8
- References: <1501884293-9047-1-git-send-email-dmalcolm@redhat.com>
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 <dmalcolm@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