Changeset 159977 in webkit
- Timestamp:
- Dec 2, 2013 3:52:34 PM (10 years ago)
- Location:
- trunk/Tools
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r159969 r159977 1 2013-12-02 László Langó <lango@inf.u-szeged.hu> 2 3 Remove the stderr_write attribute from StyleProcessorConfiguration 4 https://bugs.webkit.org/show_bug.cgi?id=124703 5 6 Reviewed by Ryosuke Niwa. 7 8 Remove the stderr_write attribute from this class in checker and 9 replace its use with calls to a logging module logger. We Should 10 use logging module instead of writing to stderr directly. 11 12 * Scripts/webkitpy/style/checker.py: Change stderr_write attribute to logging module logger. 13 (check_webkit_style_configuration): 14 (CheckerDispatcher.dispatch): Remove FIXME comment. 15 (StyleProcessorConfiguration): 16 (StyleProcessorConfiguration.__init__): 17 (StyleProcessorConfiguration.write_style_error): 18 * Scripts/webkitpy/style/checker_unittest.py: Update test to the modification. 19 There is an "ERROR" prefix in log messiges from now. 20 (StyleProcessorConfigurationTest): 21 (StyleProcessorConfigurationTest._style_checker_configuration): 22 (StyleProcessorConfigurationTest.test_init): 23 (StyleProcessorConfigurationTest.test_write_style_error_emacs): 24 (StyleProcessorConfigurationTest.test_write_style_error_vs7): 25 (StyleProcessor_EndToEndTest.with): 26 (StyleProcessor_EndToEndTest.test_init): 27 (StyleProcessor_EndToEndTest.test_process): 28 (StyleProcessor_CodeCoverageTest.setUp): 29 * Scripts/webkitpy/style/error_handlers.py: Remove stderr_write usage and replace with logging module logger. 30 (DefaultStyleErrorHandler.__call__): 31 * Scripts/webkitpy/style/error_handlers_unittest.py: Update test to the modification. 32 There is an "ERROR" prefix in log messiges from now. 33 (DefaultStyleErrorHandlerTest): 34 (DefaultStyleErrorHandlerTest.setUp): 35 (DefaultStyleErrorHandlerTest._mock_increment_error_count): 36 (DefaultStyleErrorHandlerTest._style_checker_configuration): 37 (DefaultStyleErrorHandlerTest._check_initialized): 38 (DefaultStyleErrorHandlerTest.test_non_reportable_error): 39 (DefaultStyleErrorHandlerTest.test_max_reports_per_category): 40 (DefaultStyleErrorHandlerTest.test_line_numbers): 41 1 42 2013-12-02 Brian J. Burg <burg@cs.washington.edu> 2 43 -
trunk/Tools/Scripts/webkitpy/style/checker.py
r159969 r159977 399 399 max_reports_per_category=_MAX_REPORTS_PER_CATEGORY, 400 400 min_confidence=options.min_confidence, 401 output_format=options.output_format, 402 stderr_write=sys.stderr.write) 401 output_format=options.output_format) 403 402 404 403 … … 655 654 656 655 657 # FIXME: Remove the stderr_write attribute from this class and replace658 # its use with calls to a logging module logger.659 656 class StyleProcessorConfiguration(object): 660 657 … … 667 664 max_reports_per_category: The maximum number of errors to report 668 665 per category, per file. 669 670 stderr_write: A function that takes a string as a parameter and671 serves as stderr.write.672 666 673 667 """ … … 677 671 max_reports_per_category, 678 672 min_confidence, 679 output_format, 680 stderr_write): 673 output_format): 681 674 """Create a StyleProcessorConfiguration instance. 682 675 … … 697 690 and "vs7" which Microsoft Visual Studio 7 can parse. 698 691 699 stderr_write: A function that takes a string as a parameter and700 serves as stderr.write.701 702 692 """ 703 693 self._filter_configuration = filter_configuration … … 706 696 self.max_reports_per_category = max_reports_per_category 707 697 self.min_confidence = min_confidence 708 self.stderr_write = stderr_write709 698 710 699 def is_reportable(self, category, confidence_in_error, file_path): … … 736 725 """Write a style error to the configured stderr.""" 737 726 if self._output_format == 'vs7': 738 format_string = "%s(%s): %s [%s] [%d] \n"727 format_string = "%s(%s): %s [%s] [%d]" 739 728 else: 740 format_string = "%s:%s: %s [%s] [%d] \n"741 742 self.stderr_write(format_string % (file_path,729 format_string = "%s:%s: %s [%s] [%d]" 730 731 _log.error(format_string % (file_path, 743 732 line_number, 744 733 message, -
trunk/Tools/Scripts/webkitpy/style/checker_unittest.py
r159969 r159977 597 597 598 598 599 class StyleProcessorConfigurationTest( unittest.TestCase):599 class StyleProcessorConfigurationTest(LoggingTestCase): 600 600 601 601 """Tests the StyleProcessorConfiguration class.""" 602 603 def setUp(self):604 self._error_messages = []605 """The messages written to _mock_stderr_write() of this class."""606 607 def _mock_stderr_write(self, message):608 self._error_messages.append(message)609 602 610 603 def _style_checker_configuration(self, output_format="vs7"): … … 617 610 max_reports_per_category={"whitespace/newline": 1}, 618 611 min_confidence=3, 619 output_format=output_format, 620 stderr_write=self._mock_stderr_write) 612 output_format=output_format) 621 613 622 614 def test_init(self): … … 627 619 self.assertEqual(configuration.max_reports_per_category, 628 620 {"whitespace/newline": 1}) 629 self.assertEqual(configuration.stderr_write, self._mock_stderr_write)630 621 self.assertEqual(configuration.min_confidence, 3) 631 622 … … 653 644 """Test the write_style_error() method.""" 654 645 self._call_write_style_error("emacs") 655 self.assertEqual(self._error_messages, 656 ["foo.h:100: message [whitespace/tab] [5]\n"]) 646 self.assertLog(["ERROR: foo.h:100: message [whitespace/tab] [5]\n"]) 657 647 658 648 def test_write_style_error_vs7(self): 659 649 """Test the write_style_error() method.""" 660 650 self._call_write_style_error("vs7") 661 self.assertEqual(self._error_messages, 662 ["foo.h(100): message [whitespace/tab] [5]\n"]) 651 self.assertLog(["ERROR: foo.h(100): message [whitespace/tab] [5]\n"]) 663 652 664 653 … … 666 655 667 656 """Test the StyleProcessor class with an emphasis on end-to-end tests.""" 668 669 def setUp(self):670 LoggingTestCase.setUp(self)671 self._messages = []672 673 def _mock_stderr_write(self, message):674 """Save a message so it can later be asserted."""675 self._messages.append(message)676 657 677 658 def test_init(self): … … 681 662 max_reports_per_category={}, 682 663 min_confidence=3, 683 output_format="vs7", 684 stderr_write=self._mock_stderr_write) 664 output_format="vs7") 685 665 processor = StyleProcessor(configuration) 686 666 687 667 self.assertEqual(processor.error_count, 0) 688 self.assertEqual(self._messages, [])689 668 690 669 def test_process(self): … … 693 672 max_reports_per_category={}, 694 673 min_confidence=3, 695 output_format="vs7", 696 stderr_write=self._mock_stderr_write) 674 output_format="vs7") 697 675 processor = StyleProcessor(configuration) 698 676 699 677 processor.process(lines=['line1', 'Line with tab:\t'], 700 678 file_path='foo.txt') 679 701 680 self.assertEqual(processor.error_count, 1) 702 expected_messages = [' foo.txt(2): Line contains tab character. '681 expected_messages = ['ERROR: foo.txt(2): Line contains tab character. ' 703 682 '[whitespace/tab] [5]\n'] 704 self.assert Equal(self._messages,expected_messages)683 self.assertLog(expected_messages) 705 684 706 685 … … 764 743 max_reports_per_category={"whitespace/newline": 1}, 765 744 min_confidence=3, 766 output_format="vs7", 767 stderr_write=self._swallow_stderr_message) 745 output_format="vs7") 768 746 769 747 mock_carriage_checker_class = self._create_carriage_checker_class() -
trunk/Tools/Scripts/webkitpy/style/error_handlers.py
r111864 r159977 50 50 51 51 52 import logging 52 53 import sys 54 55 56 _log = logging.getLogger(__name__) 53 57 54 58 … … 160 164 message=message) 161 165 if category_total == max_reports: 162 self._configuration.stderr_write("Suppressing further [%s] reports "163 "for this file. \n" % category)166 _log.error("Suppressing further [%s] reports " 167 "for this file." % category) 164 168 return True -
trunk/Tools/Scripts/webkitpy/style/error_handlers_unittest.py
r140510 r159977 29 29 from error_handlers import DefaultStyleErrorHandler 30 30 from filter import FilterConfiguration 31 from webkitpy.common.system.logtesting import LoggingTestCase 31 32 32 33 33 class DefaultStyleErrorHandlerTest( unittest.TestCase):34 class DefaultStyleErrorHandlerTest(LoggingTestCase): 34 35 35 36 """Tests the DefaultStyleErrorHandler class.""" 36 37 37 38 def setUp(self): 38 s elf._error_messages = []39 super(DefaultStyleErrorHandlerTest, self).setUp() 39 40 self._error_count = 0 40 41 … … 48 49 self._error_count += 1 49 50 50 def _mock_stderr_write(self, message):51 self._error_messages.append(message)52 53 51 def _style_checker_configuration(self): 54 52 """Return a StyleProcessorConfiguration instance for testing.""" … … 60 58 max_reports_per_category={"whitespace/tab": 2}, 61 59 min_confidence=3, 62 output_format="vs7", 63 stderr_write=self._mock_stderr_write) 60 output_format="vs7") 64 61 65 62 def _error_handler(self, configuration, line_numbers=None): … … 72 69 """Check that count and error messages are initialized.""" 73 70 self.assertEqual(0, self._error_count) 74 self.assertEqual(0, len(self._error_messages))75 71 76 72 def _call_error_handler(self, handle_error, confidence, line_number=100): … … 133 129 134 130 self.assertEqual(0, self._error_count) 135 self.assertEqual([], self._error_messages)136 131 137 132 # Also serves as a reportable error test. … … 147 142 self._call_error_handler(error_handler, confidence) 148 143 self.assertEqual(1, self._error_count) 149 self.assertEqual(1, len(self._error_messages)) 150 self.assertEqual(self._error_messages, 151 ["foo.h(100): message [whitespace/tab] [5]\n"]) 144 self.assertLog(["ERROR: foo.h(100): message [whitespace/tab] [5]\n"]) 152 145 153 146 # Second call: suppression message reported. … … 156 149 # message (but not as an addition to the error count). 157 150 self.assertEqual(2, self._error_count) 158 self.assertEqual(3, len(self._error_messages)) 159 self.assertEqual(self._error_messages[-2], 160 "foo.h(100): message [whitespace/tab] [5]\n") 161 self.assertEqual(self._error_messages[-1], 162 "Suppressing further [whitespace/tab] reports " 163 "for this file.\n") 151 expected_message = ["ERROR: foo.h(100): message [whitespace/tab] [5]\n", 152 "ERROR: Suppressing further [whitespace/tab] reports for this file.\n"] 153 self.assertLog(expected_message) 164 154 165 155 # Third call: no report. 166 156 self._call_error_handler(error_handler, confidence) 167 157 self.assertEqual(3, self._error_count) 168 self.assert Equal(3, len(self._error_messages))158 self.assertLog([]) 169 159 170 160 def test_line_numbers(self): … … 179 169 self._call_error_handler(error_handler, confidence, line_number=60) 180 170 self.assertEqual(0, self._error_count) 181 self.assert Equal([], self._error_messages)171 self.assertLog([]) 182 172 183 173 # Error on modified line: error. 184 174 self._call_error_handler(error_handler, confidence, line_number=50) 185 175 self.assertEqual(1, self._error_count) 186 self.assertEqual(self._error_messages, 187 ["foo.h(50): message [whitespace/tab] [5]\n"]) 176 self.assertLog(["ERROR: foo.h(50): message [whitespace/tab] [5]\n"]) 188 177 189 178 # Error on non-modified line after turning off line filtering: error. … … 191 180 self._call_error_handler(error_handler, confidence, line_number=60) 192 181 self.assertEqual(2, self._error_count) 193 self.assertEqual(self._error_messages, 194 ['foo.h(50): message [whitespace/tab] [5]\n', 195 'foo.h(60): message [whitespace/tab] [5]\n', 196 'Suppressing further [whitespace/tab] reports for this file.\n']) 182 self.assertLog(['ERROR: foo.h(60): message [whitespace/tab] [5]\n', 183 'ERROR: Suppressing further [whitespace/tab] reports for this file.\n'])
Note: See TracChangeset
for help on using the changeset viewer.