示例#1
0
 def test_print_results_missing_line(self):
     with retrieve_stdout() as stdout:
         print_results(
             self.log_printer,
             Section(""),
             [Result.from_values("t", "msg", file="file", line=5),
              Result.from_values("t", "msg", file="file", line=6)],
             {abspath("file"): ["line " + str(i + 1) for i in range(5)]},
             {},
             color=False)
         self.assertEqual("\n"
                          "file\n"
                          "|   5| {0}\n"
                          "|    | [NORMAL] t:\n"
                          "|    | {1}\n"
                          "\n"
                          "file\n"
                          "|   6| {2}\n"
                          "|    | [NORMAL] t:\n"
                          "|    | {1}\n".format(
                              highlight_text('line 5', self.lexer),
                              highlight_text("msg",
                                             style=BackgroundMessageStyle),
                              STR_LINE_DOESNT_EXIST),
                          stdout.getvalue())
示例#2
0
    def test_print_results_multiple_ranges(self):
        affected_code = (
            SourceRange.from_values("some_file", 5, end_line=7),
            SourceRange.from_values("another_file", 1, 3, 1, 5),
            SourceRange.from_values("another_file", 3, 3, 3, 5))
        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer,
                Section(""),
                [Result("ClangCloneDetectionBear",
                        "Clone Found",
                        affected_code)],
                {abspath("some_file"): ["line " + str(i + 1) + "\n"
                                        for i in range(10)],
                 abspath("another_file"): ["line " + str(i + 1) + "\n"
                                           for i in range(10)]},
                {},
                color=False)
            self.assertEqual("""
another_file
|   1| line 1

another_file
|   3| line 3

some_file
|   5| line 5
|   6| line 6
|   7| line 7
|    | [NORMAL] ClangCloneDetectionBear:
|    | Clone Found
""",
                             stdout.getvalue())
示例#3
0
    def test_print_results_sorting(self):
        with retrieve_stdout() as stdout:
            print_results(self.log_printer,
                          Section(""),
                          [Result.from_values("SpaceConsistencyBear",
                                              "Trailing whitespace found",
                                              file="file",
                                              line=5),
                           Result.from_values("SpaceConsistencyBear",
                                              "Trailing whitespace found",
                                              file="file",
                                              line=2)],
                          {abspath("file"): ["test line\n",
                                             "\t\n",
                                             "line 3\n",
                                             "line 4\n",
                                             "line 5\t\n"]},
                          {},
                          color=False)

            self.assertEqual("""
file
|   2| {0}
|    | [NORMAL] SpaceConsistencyBear:
|    | {1}

file
|   5| {2}
|    | [NORMAL] SpaceConsistencyBear:
|    | {1}\n""".format(highlight_text('\t', self.lexer),
                       highlight_text("Trailing whitespace found",
                                      style=BackgroundMessageStyle),
                       highlight_text('line 5\t', self.lexer)),
                stdout.getvalue())
示例#4
0
    def test_print_results_sorting(self):
        with retrieve_stdout() as stdout:
            print_results(self.log_printer,
                          Section(''),
                          [Result.from_values('SpaceConsistencyBear',
                                              'Trailing whitespace found',
                                              file='file',
                                              line=5),
                           Result.from_values('SpaceConsistencyBear',
                                              'Trailing whitespace found',
                                              file='file',
                                              line=2)],
                          {abspath('file'): ['test line\n',
                                             '\t\n',
                                             'line 3\n',
                                             'line 4\n',
                                             'line 5\t\n']},
                          {},
                          self.console_printer)

            self.assertEqual("""
file
|   2| {0}
|    | [NORMAL] SpaceConsistencyBear:
|    | {1}

file
|   5| {2}
|    | [NORMAL] SpaceConsistencyBear:
|    | {1}\n""".format(highlight_text(self.no_color, '\t', self.lexer),
                       highlight_text(self.no_color,
                                      'Trailing whitespace found',
                                      style=BackgroundMessageStyle),
                       highlight_text(self.no_color, 'line 5\t', self.lexer)),
                stdout.getvalue())
示例#5
0
 def test_print_results_missing_line(self):
     with retrieve_stdout() as stdout:
         print_results(
             self.log_printer,
             Section(""),
             [
                 Result.from_values("t", "msg", file="file", line=5),
                 Result.from_values("t", "msg", file="file", line=6),
             ],
             {abspath("file"): ["line " + str(i + 1) for i in range(5)]},
             {},
             color=False,
         )
         self.assertEqual(
             "\n"
             "file\n"
             "|   5| line 5\n"
             "|    | [NORMAL] t:\n"
             "|    | msg\n"
             "\n"
             "file\n"
             "|    | {}\n"
             "|    | [NORMAL] t:\n"
             "|    | msg\n".format(STR_LINE_DOESNT_EXIST),
             stdout.getvalue(),
         )
    def test_print_results_sorting(self):
        with retrieve_stdout() as stdout:
            print_results(self.log_printer,
                          Section(""),
                          [Result("SpaceConsistencyBear",
                                  "Trailing whitespace found",
                                  "proj/white",
                                  line_nr=5),
                           Result("SpaceConsistencyBear",
                                  "Trailing whitespace found",
                                  "proj/white",
                                  line_nr=2)],
                          {"proj/white": ["test line\n",
                                          "line 2\n",
                                          "line 3\n",
                                          "line 4\n",
                                          "line 5\n"]},
                          {},
                          color=False)

            self.assertEqual("""\n\nproj/white
|   1|   1| test line
|   2|   2| line 2
|    |    | [{}] SpaceConsistencyBear:
|    |    | Trailing whitespace found
|   3|   3| line 3
|   4|   4| line 4
|   5|   5| line 5
|    |    | [{}] SpaceConsistencyBear:
|    |    | Trailing whitespace found
""".format(RESULT_SEVERITY.__str__(RESULT_SEVERITY.NORMAL),
           RESULT_SEVERITY.__str__(RESULT_SEVERITY.NORMAL)),
                             stdout.getvalue())
示例#7
0
 def test_print_results_missing_line(self):
     with retrieve_stdout() as stdout:
         print_results(
             self.log_printer,
             Section(''),
             [Result.from_values('t', 'msg', file='file', line=5),
              Result.from_values('t', 'msg', file='file', line=6)],
             {abspath('file'): ['line ' + str(i + 1) for i in range(5)]},
             {},
             self.console_printer)
         self.assertEqual('\n'
                          'file\n'
                          '|   5| {0}\n'
                          '|    | [NORMAL] t:\n'
                          '|    | {1}\n'
                          '\n'
                          'file\n'
                          '|   6| {2}\n'
                          '|    | [NORMAL] t:\n'
                          '|    | {1}\n'.format(
                              highlight_text(self.no_color,
                                             'line 5', self.lexer),
                              highlight_text(self.no_color, 'msg',
                                             style=BackgroundMessageStyle),
                              STR_LINE_DOESNT_EXIST),
                          stdout.getvalue())
示例#8
0
    def test_print_results_sorting(self):
        with retrieve_stdout() as stdout:
            print_results(self.log_printer,
                          Section(""),
                          [Result.from_values("SpaceConsistencyBear",
                                              "Trailing whitespace found",
                                              file="file",
                                              line=5),
                           Result.from_values("SpaceConsistencyBear",
                                              "Trailing whitespace found",
                                              file="file",
                                              line=2)],
                          {abspath("file"): ["test line\n",
                                             "line 2\n",
                                             "line 3\n",
                                             "line 4\n",
                                             "line 5\n"]},
                          {},
                          color=False)

            self.assertEqual("""
file
|   2| line 2
|    | [NORMAL] SpaceConsistencyBear:
|    | Trailing whitespace found

file
|   5| line 5
|    | [NORMAL] SpaceConsistencyBear:
|    | Trailing whitespace found
""",
                             stdout.getvalue())
示例#9
0
 def test_print_results_without_line(self):
     with retrieve_stdout() as stdout:
         print_results(
             self.log_printer,
             Section(""),
             [Result.from_values("t", "msg", file="file")],
             {abspath("file"): []},
             {},
             color=False,
         )
         self.assertEqual("\nfile\n" "|    | [NORMAL] t:\n" "|    | msg\n", stdout.getvalue())
示例#10
0
 def test_print_results_project_wide(self):
     with retrieve_stdout() as stdout:
         print_results(self.log_printer,
                       Section(""),
                       [Result("origin", "message")],
                       {},
                       {},
                       color=False)
         self.assertEqual(
             "\n{}\n|    | [NORMAL] origin:\n|    | message"
             "\n".format(STR_PROJECT_WIDE),
             stdout.getvalue())
示例#11
0
 def test_print_results_project_wide(self):
     with retrieve_stdout() as stdout:
         print_results(self.log_printer,
                       Section(''),
                       [Result('origin', 'message')],
                       {},
                       {},
                       self.console_printer)
         self.assertEqual(
             '\n{}\n|    | [NORMAL] origin:\n|    | {}\n'.format(
                 STR_PROJECT_WIDE,
                 highlight_text(self.no_color,
                                'message', style=BackgroundMessageStyle)),
             stdout.getvalue())
示例#12
0
 def test_print_results_without_line(self):
     with retrieve_stdout() as stdout:
         print_results(
             self.log_printer,
             Section(''),
             [Result.from_values('t', 'msg', file='file')],
             {abspath('file'): []},
             {},
             self.console_printer)
         self.assertEqual(
             '\nfile\n'
             '|    | [NORMAL] t:\n'
             '|    | {}\n'.format(highlight_text(
                self.no_color, 'msg', style=BackgroundMessageStyle)),
             stdout.getvalue())
示例#13
0
 def test_print_results_without_line(self):
     with retrieve_stdout() as stdout:
         print_results(
             self.log_printer,
             Section(""),
             [Result.from_values("t", "msg", file="file")],
             {"file": []},
             {},
             color=False)
         self.assertEqual(
             "\nfile\n"
             "|    | [{}] t:\n"
             "|    | msg\n".format(
                 RESULT_SEVERITY.__str__(RESULT_SEVERITY.NORMAL)),
             stdout.getvalue())
示例#14
0
 def test_print_results_without_line(self):
     with retrieve_stdout() as stdout:
         print_results(
             self.log_printer,
             Section(""),
             [Result.from_values("t", "msg", file="file")],
             {abspath("file"): []},
             {},
             color=False)
         self.assertEqual(
             "\nfile\n"
             "|    | [NORMAL] t:\n"
             "|    | {}\n".format(highlight_text(
                 "msg", style=BackgroundMessageStyle)),
             stdout.getvalue())
 def test_print_results_missing_file(self):
     # File isn't in dict, shouldn't print but also shouldn't throw. This
     # can occur if filter writers are doing nonsense. If this happens twice
     # the same should happen (whitebox testing: this is a potential bug.)
     self.log_printer = LogPrinter(NullPrinter())
     with retrieve_stdout() as stdout:
         print_results(
             self.log_printer,
             Section(""),
             [Result("t", "msg", "file", line_nr=5),
              Result("t", "msg", "file", line_nr=5)],
             {},
             {},
             color=False)
         self.assertEqual("", stdout.getvalue())
    def test_print_results_for_file(self):
        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer,
                Section(''),
                [Result.from_values('SpaceConsistencyBear',
                                    'Trailing whitespace found',
                                    file='filename',
                                    line=2)],
                {abspath('filename'): ['test line\n', 'line 2\n', 'line 3\n']},
                {},
                self.console_printer)
            self.assertEqual("""
filename
[   2] {0}
**** SpaceConsistencyBear [Section:  | Severity: NORMAL] ****
!    ! {1}\n""".format(highlight_text(self.no_color, 'line 2', NoColorStyle,
                                      self.lexer),
                       highlight_text(self.no_color,
                                      'Trailing whitespace found',
                                      style=BackgroundMessageStyle), ''),
                stdout.getvalue())

        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer,
                Section(''),
                [Result.from_values('SpaceConsistencyBear',
                                    'Trailing whitespace found',
                                    file='filename',
                                    line=5)],
                {abspath('filename'): ['test line\n',
                                       'line 2\n',
                                       'line 3\n',
                                       'line 4\n',
                                       'line 5\n']},
                {},
                self.console_printer)
            self.assertEqual("""
filename
[   5] {0}
**** SpaceConsistencyBear [Section:  | Severity: NORMAL] ****
!    ! {1}\n""".format(highlight_text(self.no_color, 'line 5', NoColorStyle,
                                      self.lexer),
                       highlight_text(self.no_color,
                                      'Trailing whitespace found',
                                      style=BackgroundMessageStyle), ''),
                stdout.getvalue())
    def test_print_results_multiple_ranges(self):
        affected_code = (
            SourceRange.from_values('some_file', 5, end_line=7),
            SourceRange.from_values('another_file', 1, 3, 1, 5),
            SourceRange.from_values('another_file', 3, 3, 3, 5))
        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer,
                Section(''),
                [Result('Bear_for_detecting_clone',
                        'Clone Found',
                        affected_code)],
                {abspath('some_file'): ['line ' + str(i + 1) + '\n'
                                        for i in range(10)],
                 abspath('another_file'): ['line ' + str(i + 1)
                                           for i in range(10)]},
                {},
                self.console_printer)
            self.assertEqual("""
another_file
[   1] li{0}{1}

another_file
[   3] li{0}{2}

some_file
[   5] li{0}{3}
[   6] li{0}{4}
[   7] li{0}{5}
**** Bear_for_detecting_clone [Section:  | Severity: NORMAL] ****
!    ! {6}\n""".format(highlight_text(self.no_color, 'ne',
                                      BackgroundSourceRangeStyle, self.lexer),
                       highlight_text(self.no_color, ' 1', NoColorStyle,
                                      self.lexer),
                       highlight_text(self.no_color, ' 3', NoColorStyle,
                                      self.lexer),
                       highlight_text(self.no_color, ' 5', NoColorStyle,
                                      self.lexer),
                       highlight_text(self.no_color, ' 6', NoColorStyle,
                                      self.lexer),
                       highlight_text(self.no_color, ' 7', NoColorStyle,
                                      self.lexer),
                       highlight_text(self.no_color, 'Clone Found',
                                      style=BackgroundMessageStyle), ' '),
                stdout.getvalue())
示例#18
0
 def test_print_results_missing_file(self):
     self.log_printer = LogPrinter(NullPrinter())
     with retrieve_stdout() as stdout:
         print_results(
             self.log_printer,
             Section(""),
             [Result("t", "msg"),
              Result.from_values("t", "msg", file="file", line=5)],
             {},
             {},
             color=False)
         self.assertEqual("\n" + STR_PROJECT_WIDE + "\n"
                          "|    | [NORMAL] t:\n"
                          "|    | msg\n"
                          # Second results file isn't there, no context is
                          # printed, only a warning log message which we
                          # don't catch
                          "|    | [NORMAL] t:\n"
                          "|    | msg\n", stdout.getvalue())
示例#19
0
    def test_print_results_for_file(self):
        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer,
                Section(""),
                [Result.from_values("SpaceConsistencyBear",
                                    "Trailing whitespace found",
                                    file="filename",
                                    line=2)],
                {abspath("filename"): ["test line\n", "line 2\n", "line 3\n"]},
                {},
                self.console_printer)
            self.assertEqual("""\nfilename
|   2| {}
|    | [NORMAL] SpaceConsistencyBear:
|    | {}\n""".format(highlight_text(self.no_color, 'line 2', self.lexer),
                      highlight_text(self.no_color, "Trailing whitespace found",
                                     style=BackgroundMessageStyle)),
                stdout.getvalue())

        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer,
                Section(""),
                [Result.from_values("SpaceConsistencyBear",
                                    "Trailing whitespace found",
                                    file="filename",
                                    line=5)],
                {abspath("filename"): ["test line\n",
                                       "line 2\n",
                                       "line 3\n",
                                       "line 4\n",
                                       "line 5\n"]},
                {},
                self.console_printer)
            self.assertEqual("""\nfilename
|   5| {}
|    | [NORMAL] SpaceConsistencyBear:
|    | {}\n""".format(highlight_text(self.no_color, 'line 5', self.lexer),
                      highlight_text(self.no_color, "Trailing whitespace found",
                                     style=BackgroundMessageStyle)),
                stdout.getvalue())
示例#20
0
 def test_print_results_missing_file(self):
     logging.getLogger().setLevel(logging.CRITICAL)
     with retrieve_stdout() as stdout:
         print_results(self.log_printer, Section(''), [
             Result('t', 'msg'),
             Result.from_values('t', 'msg', file='file', line=5)
         ], {}, {}, self.console_printer)
         self.assertEqual(
             '\n' + STR_PROJECT_WIDE + '\n'
             '**** t [Section:  | Severity: NORMAL] ****'
             '\n'
             '!    ! msg\n'
             # Second results file isn't there, no context is
             # printed, only a warning log message which we
             # don't catch
             '**** t [Section:  | Severity: NORMAL] ****'
             '\n'
             '!    ! {0}\n'.format(
                 highlight_text(
                     self.no_color, 'msg', style=BackgroundMessageStyle)),
             stdout.getvalue())
示例#21
0
 def test_print_results_missing_file(self):
     self.log_printer = LogPrinter(NullPrinter())
     with retrieve_stdout() as stdout:
         print_results(
             self.log_printer,
             Section(""), [
                 Result("t", "msg"),
                 Result.from_values("t", "msg", file="file", line=5)
             ], {}, {},
             color=False)
         self.assertEqual(
             "\n" + STR_PROJECT_WIDE + "\n"
             "|    | [NORMAL] t:\n"
             "|    | {0}\n"
             # Second results file isn't there, no context is
             # printed, only a warning log message which we
             # don't catch
             "|    | [NORMAL] t:\n"
             "|    | {0}\n".format(
                 highlight_text("msg", style=BackgroundMessageStyle)),
             stdout.getvalue())
示例#22
0
 def test_print_results_missing_line(self):
     with retrieve_stdout() as stdout:
         print_results(
             self.log_printer,
             Section(""),
             [Result.from_values("t", "msg", file="file", line=5),
              Result.from_values("t", "msg", file="file", line=6)],
             {abspath("file"): ["line " + str(i + 1) for i in range(5)]},
             {},
             color=False)
         self.assertEqual("\n"
                          "file\n"
                          "|   5| line•5\n"
                          "|    | [NORMAL] t:\n"
                          "|    | msg\n"
                          "\n"
                          "file\n"
                          "|    | {}\n"
                          "|    | [NORMAL] t:\n"
                          "|    | msg\n".format(STR_LINE_DOESNT_EXIST),
                          stdout.getvalue())
示例#23
0
    def test_print_results_for_file(self):
        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer,
                Section(""), [
                    Result.from_values("SpaceConsistencyBear",
                                       "Trailing whitespace found",
                                       file="filename",
                                       line=2)
                ],
                {abspath("filename"): ["test line\n", "line 2\n", "line 3\n"]},
                {},
                color=False)
            self.assertEqual(
                """\nfilename
|   2| line•2
|    | [NORMAL] SpaceConsistencyBear:
|    | Trailing whitespace found
""", stdout.getvalue())

        with retrieve_stdout() as stdout:
            print_results(self.log_printer,
                          Section(""), [
                              Result.from_values("SpaceConsistencyBear",
                                                 "Trailing whitespace found",
                                                 file="filename",
                                                 line=5)
                          ], {
                              abspath("filename"): [
                                  "test line\n", "line 2\n", "line 3\n",
                                  "line 4\n", "line 5\n"
                              ]
                          }, {},
                          color=False)
            self.assertEqual(
                """\nfilename
|   5| line•5
|    | [NORMAL] SpaceConsistencyBear:
|    | Trailing whitespace found
""", stdout.getvalue())
示例#24
0
    def test_print_results_multiple_ranges(self):
        affected_code = (
            SourceRange.from_values("some_file", 5, end_line=7),
            SourceRange.from_values("another_file", 1, 3, 1, 5),
            SourceRange.from_values("another_file", 3, 3, 3, 5))
        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer,
                Section(""),
                [Result("ClangCloneDetectionBear",
                        "Clone Found",
                        affected_code)],
                {abspath("some_file"): ["line " + str(i + 1) + "\n"
                                        for i in range(10)],
                 abspath("another_file"): ["line " + str(i + 1)
                                           for i in range(10)]},
                {},
                color=False)
            self.assertEqual("""
another_file
|   1| li{0}{1}

another_file
|   3| li{0}{2}

some_file
|   5| {3}
|   6| {4}
|   7| {5}
|    | [NORMAL] ClangCloneDetectionBear:
|    | {6}\n""".format(highlight_text('ne', self.lexer,
                                      BackgroundSourceRangeStyle),
                       highlight_text(' 1', self.lexer),
                       highlight_text(' 3', self.lexer),
                       highlight_text('line 5', self.lexer),
                       highlight_text('line 6', self.lexer),
                       highlight_text('line 7', self.lexer),
                       highlight_text("Clone Found",
                                      style=BackgroundMessageStyle)),
                stdout.getvalue())
示例#25
0
    def test_print_results_for_file(self):
        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer,
                Section(""),
                [Result.from_values("SpaceConsistencyBear",
                                    "Trailing whitespace found",
                                    file="proj/white",
                                    line=2)],
                {"proj/white": ["test line\n", "line 2\n", "line 3\n"]},
                {},
                color=False)
            self.assertEqual("""\nproj/white
|   2| line 2
|    | [{}] SpaceConsistencyBear:
|    | Trailing whitespace found
""".format(RESULT_SEVERITY.__str__(RESULT_SEVERITY.NORMAL)),
                         stdout.getvalue())

        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer,
                Section(""),
                [Result.from_values("SpaceConsistencyBear",
                                    "Trailing whitespace found",
                                    file="proj/white",
                                    line=5)],
                {"proj/white": ["test line\n",
                                "line 2\n",
                                "line 3\n",
                                "line 4\n",
                                "line 5\n"]},
                {},
                color=False)
            self.assertEqual("""\nproj/white
|   5| line 5
|    | [{}] SpaceConsistencyBear:
|    | Trailing whitespace found
""".format(RESULT_SEVERITY.__str__(RESULT_SEVERITY.NORMAL)),
                             stdout.getvalue())
示例#26
0
    def test_print_results_multiple_ranges(self):
        affected_code = (
            SourceRange.from_values('some_file', 5, end_line=7),
            SourceRange.from_values('another_file', 1, 3, 1, 5),
            SourceRange.from_values('another_file', 3, 3, 3, 5))
        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer,
                Section(''),
                [Result('ClangCloneDetectionBear',
                        'Clone Found',
                        affected_code)],
                {abspath('some_file'): ['line ' + str(i + 1) + '\n'
                                        for i in range(10)],
                 abspath('another_file'): ['line ' + str(i + 1)
                                           for i in range(10)]},
                {},
                self.console_printer)
            self.assertEqual("""
another_file
|   1| li{0}{1}

another_file
|   3| li{0}{2}

some_file
|   5| {3}
|   6| {4}
|   7| {5}
|    | [NORMAL] ClangCloneDetectionBear:
|    | {6}\n""".format(highlight_text(self.no_color, 'ne', self.lexer,
                                      BackgroundSourceRangeStyle),
                       highlight_text(self.no_color, ' 1', self.lexer),
                       highlight_text(self.no_color, ' 3', self.lexer),
                       highlight_text(self.no_color, 'line 5', self.lexer),
                       highlight_text(self.no_color, 'line 6', self.lexer),
                       highlight_text(self.no_color, 'line 7', self.lexer),
                       highlight_text(self.no_color, 'Clone Found',
                                      style=BackgroundMessageStyle)),
                stdout.getvalue())
示例#27
0
    def test_print_results_multiple_ranges(self):
        affected_code = (SourceRange.from_values("some_file", 5, end_line=7),
                         SourceRange.from_values("another_file", 1, 3, 1, 5),
                         SourceRange.from_values("another_file", 3, 3, 3, 5))
        with retrieve_stdout() as stdout:
            print_results(self.log_printer,
                          Section(""), [
                              Result("ClangCloneDetectionBear", "Clone Found",
                                     affected_code)
                          ], {
                              abspath("some_file"):
                              ["line " + str(i + 1) + "\n" for i in range(10)],
                              abspath("another_file"):
                              ["line " + str(i + 1) for i in range(10)]
                          }, {},
                          color=False)
            self.assertEqual(
                """
another_file
|   1| li{0}{1}

another_file
|   3| li{0}{2}

some_file
|   5| {3}
|   6| {4}
|   7| {5}
|    | [NORMAL] ClangCloneDetectionBear:
|    | {6}\n""".format(
                    highlight_text('ne', self.lexer,
                                   BackgroundSourceRangeStyle),
                    highlight_text(' 1', self.lexer),
                    highlight_text(' 3', self.lexer),
                    highlight_text('line 5', self.lexer),
                    highlight_text('line 6', self.lexer),
                    highlight_text('line 7', self.lexer),
                    highlight_text("Clone Found",
                                   style=BackgroundMessageStyle)),
                stdout.getvalue())
示例#28
0
 def test_print_results_missing_line(self):
     with retrieve_stdout() as stdout:
         print_results(self.log_printer, Section(''), [
             Result.from_values('t', 'msg', file='file', line=5),
             Result.from_values('t', 'msg', file='file', line=6)
         ], {abspath('file'): ['line ' + str(i + 1) for i in range(5)]}, {},
                       self.console_printer)
         self.assertEqual(
             '\n'
             '**** t [Section: ] ****\n\n'
             '!    ! [Severity: NORMAL]\n'
             '!    ! {1}\n'
             '!    !6 {2}'
             '\n\n'
             '**** t [Section: ] ****\n\n'
             '!    ! [Severity: NORMAL]\n'
             '!    ! {1}\n'.format(
                 highlight_text(self.no_color, 'line 5', self.lexer),
                 highlight_text(self.no_color,
                                'msg',
                                style=BackgroundMessageStyle),
                 STR_LINE_DOESNT_EXIST), stdout.getvalue())
示例#29
0
 def test_print_results_missing_file(self):
     self.log_printer.log_level = logging.CRITICAL
     with retrieve_stdout() as stdout:
         print_results(
             self.log_printer,
             Section(''),
             [Result('t', 'msg'),
              Result.from_values('t', 'msg', file='file', line=5)],
             {},
             {},
             self.console_printer)
         self.assertEqual('\n' + STR_PROJECT_WIDE + '\n'
                          '|    | [NORMAL] t:\n'
                          '|    | {0}\n'
                          # Second results file isn't there, no context is
                          # printed, only a warning log message which we
                          # don't catch
                          '|    | [NORMAL] t:\n'
                          '|    | {0}\n'.format(
                              highlight_text(self.no_color, 'msg',
                                             style=BackgroundMessageStyle)),
                          stdout.getvalue())
    def test_print_results_missing_line(self):
        # Line isn't in dict[file], shouldn't print but also shouldn't throw.
        # This can occur if filter writers are doing nonsense.
        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer,
                Section(""),
                [Result("t", "msg", "file", line_nr=5)],
                {"file": []},
                {},
                color=False)
            self.assertEqual("""\n\nfile\n|    |    | {}\n|    |    | [{}] t:
|    |    | msg\n""".format(STR_LINE_DOESNT_EXIST,
                            RESULT_SEVERITY.__str__(RESULT_SEVERITY.NORMAL)),
                             stdout.getvalue())

        self.assertRaises(AssertionError,
                          print_results,
                          self.log_printer,
                          Section(""),
                          [Result("t", "msg", None, line_nr=5)],
                          {},
                          {})
示例#31
0
 def test_print_results_missing_line(self):
     with retrieve_stdout() as stdout:
         print_results(self.log_printer, Section(""), [
             Result.from_values("t", "msg", file="file", line=5),
             Result.from_values("t", "msg", file="file", line=6)
         ], {abspath("file"): ["line " + str(i + 1) for i in range(5)]}, {},
                       self.console_printer)
         self.assertEqual(
             "\n"
             "file\n"
             "|   5| {0}\n"
             "|    | [NORMAL] t:\n"
             "|    | {1}\n"
             "\n"
             "file\n"
             "|   6| {2}\n"
             "|    | [NORMAL] t:\n"
             "|    | {1}\n".format(
                 highlight_text(self.no_color, 'line 5', self.lexer),
                 highlight_text(self.no_color,
                                "msg",
                                style=BackgroundMessageStyle),
                 STR_LINE_DOESNT_EXIST), stdout.getvalue())
    def test_print_results_sorting(self):
        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer, Section(''), [
                    Result.from_values('SpaceConsistencyBear',
                                       'Trailing whitespace found',
                                       file='file',
                                       line=5),
                    Result.from_values('SpaceConsistencyBear',
                                       'Trailing whitespace found',
                                       file='file',
                                       line=2)
                ], {
                    abspath('file'): [
                        'test line\n', '\t\n', 'line 3\n', 'line 4\n',
                        'line 5\t\n'
                    ]
                }, {}, self.console_printer)

            self.assertEqual(
                """
file
[   2] {0}
**** SpaceConsistencyBear [Section:  | Severity: NORMAL] ****
!    ! Trailing whitespace found

file
[   5] {2}
**** SpaceConsistencyBear [Section:  | Severity: NORMAL] ****
!    ! {1}\n""".format(
                    highlight_text(self.no_color, '\t', NoColorStyle,
                                   self.lexer),
                    highlight_text(self.no_color,
                                   'Trailing whitespace found',
                                   style=BackgroundMessageStyle),
                    highlight_text(self.no_color, 'line 5\t', NoColorStyle,
                                   self.lexer)), stdout.getvalue())
示例#33
0
    def test_print_results_sorting(self):
        with retrieve_stdout() as stdout:
            print_results(
                self.log_printer, Section(""), [
                    Result.from_values("SpaceConsistencyBear",
                                       "Trailing whitespace found",
                                       file="file",
                                       line=5),
                    Result.from_values("SpaceConsistencyBear",
                                       "Trailing whitespace found",
                                       file="file",
                                       line=2)
                ], {
                    abspath("file"): [
                        "test line\n", "\t\n", "line 3\n", "line 4\n",
                        "line 5\t\n"
                    ]
                }, {}, self.console_printer)

            self.assertEqual(
                """
file
|   2| {0}
|    | [NORMAL] SpaceConsistencyBear:
|    | {1}

file
|   5| {2}
|    | [NORMAL] SpaceConsistencyBear:
|    | {1}\n""".format(
                    highlight_text(self.no_color, '\t', self.lexer),
                    highlight_text(self.no_color,
                                   "Trailing whitespace found",
                                   style=BackgroundMessageStyle),
                    highlight_text(self.no_color, 'line 5\t', self.lexer)),
                stdout.getvalue())
示例#34
0
 def test_print_results_missing_line(self):
     with retrieve_stdout() as stdout:
         print_results(
             self.log_printer,
             Section(""),
             [Result.from_values("t", "msg", file="file", line=5),
              Result.from_values("t", "msg", file="file", line=6)],
             {"file": ["line " + str(i+1) for i in range(5)]},
             {},
             color=False)
         # "NORMAL" but translated to test system language
         NORMAL = RESULT_SEVERITY.__str__(RESULT_SEVERITY.NORMAL)
         self.assertEqual("\n"
                          "file\n"
                          "|   5| line 5\n"
                          "|    | [{sev}] t:\n"
                          "|    | msg\n"
                          "\n"
                          "file\n"
                          "|    | {}\n"
                          "|    | [{sev}] t:\n"
                          "|    | msg\n".format(STR_LINE_DOESNT_EXIST,
                                                sev=NORMAL),
                          stdout.getvalue())
示例#35
0
 def test_print_results_empty(self):
     with retrieve_stdout() as stdout:
         print_results(self.log_printer, Section(""), [], {}, {})
         self.assertEqual(stdout.getvalue(), "")
示例#36
0
 def test_print_results_empty(self):
     with retrieve_stdout() as stdout:
         print_results(self.log_printer, Section(''), [], {}, {},
                       self.console_printer)
         self.assertEqual(stdout.getvalue(), '')