Пример #1
0
    def test_suppressions_suppressionsRenderableParameter(self):
        def warningExtractor(step, line, match):
            return line.split(':', 2)

        supps = (
            ("abc.c", ".*", 100, 199),
            ("def.c", ".*", 22, 22),
        )

        step = shell.WarningCountingShellCommandNewStyle(
            command=['make'],
            suppressionList=properties.Property("suppressionsList"),
            warningExtractor=warningExtractor)

        stdout = textwrap.dedent("""\
            abc.c:99: warning: seen 1
            abc.c:150: warning: unseen
            def.c:22: warning: unseen
            abc.c:200: warning: seen 2
            """)
        exp_warning_log = textwrap.dedent("""\
            abc.c:99: warning: seen 1
            abc.c:200: warning: seen 2
            """)
        return self.do_test_suppressions(step,
                                         None,
                                         stdout,
                                         2,
                                         exp_warning_log,
                                         props={"suppressionsList": supps})
Пример #2
0
 def test_warnExtractFromRegexpGroups(self):
     step = shell.WarningCountingShellCommandNewStyle(command=['make'])
     we = shell.WarningCountingShellCommandNewStyle.warnExtractFromRegexpGroups
     line, pat, exp_file, exp_lineNo, exp_text = \
         ('foo:123:text', '(.*):(.*):(.*)', 'foo', 123, 'text')
     self.assertEqual(we(step, line, re.match(pat, line)),
                      (exp_file, exp_lineNo, exp_text))
Пример #3
0
    def test_suppressions_directories(self):
        def warningExtractor(step, line, match):
            return line.split(':', 2)

        step = shell.WarningCountingShellCommandNewStyle(
            command=['make'],
            suppressionFile='supps',
            warningExtractor=warningExtractor)
        supps_file = textwrap.dedent("""\
            # these should be suppressed:
            amar-src/amar.c : XXX
            .*/server-src/.* : AAA
            # these should not, as the dirs do not match:
            amar.c : YYY
            server-src.* : BBB
            """).strip()
        # note that this uses the unicode smart-quotes that gcc loves so much
        stdout = textwrap.dedent("""\
            make: Entering directory \u2019amar-src\u2019
            amar.c:164: warning: XXX
            amar.c:165: warning: YYY
            make: Leaving directory 'amar-src'
            make: Entering directory "subdir"
            make: Entering directory 'server-src'
            make: Entering directory `one-more-dir`
            holding.c:999: warning: BBB
            holding.c:1000: warning: AAA
            """)
        exp_warning_log = textwrap.dedent("""\
            amar.c:165: warning: YYY
            holding.c:999: warning: BBB
        """)
        return self.do_test_suppressions(step, supps_file, stdout, 2,
                                         exp_warning_log)
Пример #4
0
    def test_suppressions(self):
        step = shell.WarningCountingShellCommandNewStyle(
            command=['make'], suppressionFile='supps')
        supps_file = textwrap.dedent("""\
            # example suppressions file

            amar.c : .*unused variable.*
            holding.c : .*invalid access to non-static.*
            """).strip()
        stdout = textwrap.dedent("""\
            /bin/sh ../libtool --tag=CC  --silent --mode=link gcc blah
            /bin/sh ../libtool --tag=CC  --silent --mode=link gcc blah
            amar.c: In function 'write_record':
            amar.c:164: warning: unused variable 'x'
            amar.c:164: warning: this should show up
            /bin/sh ../libtool --tag=CC  --silent --mode=link gcc blah
            /bin/sh ../libtool --tag=CC  --silent --mode=link gcc blah
            holding.c: In function 'holding_thing':
            holding.c:984: warning: invalid access to non-static 'y'
            """)
        exp_warning_log = textwrap.dedent("""\
            amar.c:164: warning: this should show up
        """)
        return self.do_test_suppressions(step, supps_file, stdout, 1,
                                         exp_warning_log)
Пример #5
0
 def test_fail_with_warnings(self):
     self.setupStep(
         shell.WarningCountingShellCommandNewStyle(command=['make']))
     self.expectCommands(
         ExpectShell(workdir='wkdir', command=["make"]) +
         ExpectShell.log('stdio', stdout='warning: I might fail') + 3)
     self.expectOutcome(result=FAILURE)
     self.expectProperty("warnings-count", 1)
     self.expectLogfile("warnings (1)", "warning: I might fail\n")
     return self.runStep()
Пример #6
0
 def test_maxWarnCount(self):
     self.setupStep(
         shell.WarningCountingShellCommandNewStyle(command=['make'],
                                                   maxWarnCount=9))
     self.expectCommands(
         ExpectShell(workdir='wkdir', command=["make"]) +
         ExpectShell.log('stdio', stdout='warning: noo!\n' * 10) + 0)
     self.expectOutcome(result=FAILURE)
     self.expectProperty("warnings-count", 10)
     return self.runStep()
Пример #7
0
 def test_no_warnings(self):
     self.setupStep(
         shell.WarningCountingShellCommandNewStyle(workdir='w',
                                                   command=['make']))
     self.expectCommands(
         ExpectShell(workdir='w', command=["make"]) +
         ExpectShell.log('stdio', stdout='blarg success!') + 0)
     self.expectOutcome(result=SUCCESS)
     self.expectProperty("warnings-count", 0)
     return self.runStep()
Пример #8
0
 def test_custom_pattern(self):
     self.setupStep(
         shell.WarningCountingShellCommandNewStyle(
             command=['make'], warningPattern=r"scary:.*"))
     self.expectCommands(
         ExpectShell(workdir='wkdir', command=["make"]) + ExpectShell.log(
             'stdio', stdout='scary: foo\nwarning: bar\nscary: bar') + 0)
     self.expectOutcome(result=WARNINGS)
     self.expectProperty("warnings-count", 2)
     self.expectLogfile("warnings (2)", "scary: foo\nscary: bar\n")
     return self.runStep()
Пример #9
0
 def test_warn_with_decoderc(self):
     self.setupStep(
         shell.WarningCountingShellCommandNewStyle(command=['make'],
                                                   decodeRC={3: WARNINGS}))
     self.expectCommands(
         ExpectShell(
             workdir='wkdir',
             command=["make"],
         ) + ExpectShell.log('stdio', stdout='I might fail with rc') + 3)
     self.expectOutcome(result=WARNINGS)
     self.expectProperty("warnings-count", 0)
     return self.runStep()
Пример #10
0
 def test_default_pattern(self):
     self.setupStep(
         shell.WarningCountingShellCommandNewStyle(command=['make']))
     self.expectCommands(
         ExpectShell(workdir='wkdir', command=["make"]) +
         ExpectShell.log('stdio',
                         stdout='normal: foo\nwarning: blarg!\n'
                         'also normal\nWARNING: blarg!\n') + 0)
     self.expectOutcome(result=WARNINGS)
     self.expectProperty("warnings-count", 2)
     self.expectLogfile("warnings (2)",
                        "warning: blarg!\nWARNING: blarg!\n")
     return self.runStep()
Пример #11
0
    def test_suppressions_warningExtractor_exc(self):
        def warningExtractor(step, line, match):
            raise RuntimeError("oh noes")

        step = shell.WarningCountingShellCommandNewStyle(
            command=['make'],
            suppressionFile='supps',
            warningExtractor=warningExtractor)
        # need at least one supp to trigger warningExtractor
        supps_file = 'x:y'
        stdout = "abc.c:99: warning: seen 1"
        yield self.do_test_suppressions(step,
                                        supps_file,
                                        stdout,
                                        exp_exception=True)
        self.assertEqual(len(self.flushLoggedErrors(RuntimeError)), 1)
Пример #12
0
    def test_suppressions_directories_custom(self):
        def warningExtractor(step, line, match):
            return line.split(':', 2)

        step = shell.WarningCountingShellCommandNewStyle(
            command=['make'],
            suppressionFile='supps',
            warningExtractor=warningExtractor,
            directoryEnterPattern="^IN: (.*)",
            directoryLeavePattern="^OUT:")
        supps_file = "dir1/dir2/abc.c : .*"
        stdout = textwrap.dedent("""\
            IN: dir1
            IN: decoy
            OUT: decoy
            IN: dir2
            abc.c:123: warning: hello
            """)
        return self.do_test_suppressions(step, supps_file, stdout, 0, '')
Пример #13
0
    def test_suppressions_linenos(self):
        def warningExtractor(step, line, match):
            return line.split(':', 2)

        step = shell.WarningCountingShellCommandNewStyle(
            command=['make'],
            suppressionFile='supps',
            warningExtractor=warningExtractor)
        supps_file = "abc.c:.*:100-199\ndef.c:.*:22"
        stdout = textwrap.dedent("""\
            abc.c:99: warning: seen 1
            abc.c:150: warning: unseen
            def.c:22: warning: unseen
            abc.c:200: warning: seen 2
            """)
        exp_warning_log = textwrap.dedent("""\
            abc.c:99: warning: seen 1
            abc.c:200: warning: seen 2
            """)
        return self.do_test_suppressions(step, supps_file, stdout, 2,
                                         exp_warning_log)
Пример #14
0
 def test_missing_command_error(self):
     # this checks that an exception is raised for invalid arguments
     with self.assertRaisesConfigError(
             "WarningCountingShellCommandNewStyle's `command' argument is not "
             "specified"):
         shell.WarningCountingShellCommandNewStyle()