Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py

Issue 2136793002: Remove all unused variables. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # -*- coding: utf-8; -*- 1 # -*- coding: utf-8; -*-
2 # 2 #
3 # Copyright (C) 2011 Google Inc. All rights reserved. 3 # Copyright (C) 2011 Google Inc. All rights reserved.
4 # Copyright (C) 2009 Torch Mobile Inc. 4 # Copyright (C) 2009 Torch Mobile Inc.
5 # Copyright (C) 2009 Apple Inc. All rights reserved. 5 # Copyright (C) 2009 Apple Inc. All rights reserved.
6 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) 6 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org)
7 # 7 #
8 # Redistribution and use in source and binary forms, with or without 8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions are 9 # modification, are permitted provided that the following conditions are
10 # met: 10 # met:
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 'body_start_position': (2, 1), 533 'body_start_position': (2, 1),
534 'end_position': (2, 2), 534 'end_position': (2, 2),
535 'is_pure': False, 535 'is_pure': False,
536 'is_declaration': True}) 536 'is_declaration': True})
537 537
538 # Simple test case with something that is not a function. 538 # Simple test case with something that is not a function.
539 self.perform_function_detection(['class Stuff;'], None) 539 self.perform_function_detection(['class Stuff;'], None)
540 540
541 def test_parameter_list(self): 541 def test_parameter_list(self):
542 # A function with no arguments. 542 # A function with no arguments.
543 function_state = self.perform_function_detection( 543 self.perform_function_detection(
544 ['void functionName();'], 544 ['void functionName();'],
545 {'name': 'functionName', 545 {'name': 'functionName',
546 'modifiers_and_return_type': 'void', 546 'modifiers_and_return_type': 'void',
547 'function_name_start_position': (0, 5), 547 'function_name_start_position': (0, 5),
548 'parameter_start_position': (0, 17), 548 'parameter_start_position': (0, 17),
549 'parameter_end_position': (0, 19), 549 'parameter_end_position': (0, 19),
550 'body_start_position': (0, 19), 550 'body_start_position': (0, 19),
551 'end_position': (0, 20), 551 'end_position': (0, 20),
552 'is_pure': False, 552 'is_pure': False,
553 'is_declaration': True, 553 'is_declaration': True,
554 'parameter_list': ()}) 554 'parameter_list': ()})
555 555
556 # A function with one argument. 556 # A function with one argument.
557 function_state = self.perform_function_detection( 557 self.perform_function_detection(
558 ['void functionName(int);'], 558 ['void functionName(int);'],
559 {'name': 'functionName', 559 {'name': 'functionName',
560 'modifiers_and_return_type': 'void', 560 'modifiers_and_return_type': 'void',
561 'function_name_start_position': (0, 5), 561 'function_name_start_position': (0, 5),
562 'parameter_start_position': (0, 17), 562 'parameter_start_position': (0, 17),
563 'parameter_end_position': (0, 22), 563 'parameter_end_position': (0, 22),
564 'body_start_position': (0, 22), 564 'body_start_position': (0, 22),
565 'end_position': (0, 23), 565 'end_position': (0, 23),
566 'is_pure': False, 566 'is_pure': False,
567 'is_declaration': True, 567 'is_declaration': True,
568 'parameter_list': 568 'parameter_list':
569 ({'type': 'int', 'name': '', 'row': 0},)}) 569 ({'type': 'int', 'name': '', 'row': 0},)})
570 570
571 # A function with unsigned and short arguments 571 # A function with unsigned and short arguments
572 function_state = self.perform_function_detection( 572 self.perform_function_detection(
573 ['void functionName(unsigned a, short b, long c, long long short uns igned int);'], 573 ['void functionName(unsigned a, short b, long c, long long short uns igned int);'],
574 {'name': 'functionName', 574 {'name': 'functionName',
575 'modifiers_and_return_type': 'void', 575 'modifiers_and_return_type': 'void',
576 'function_name_start_position': (0, 5), 576 'function_name_start_position': (0, 5),
577 'parameter_start_position': (0, 17), 577 'parameter_start_position': (0, 17),
578 'parameter_end_position': (0, 76), 578 'parameter_end_position': (0, 76),
579 'body_start_position': (0, 76), 579 'body_start_position': (0, 76),
580 'end_position': (0, 77), 580 'end_position': (0, 77),
581 'is_pure': False, 581 'is_pure': False,
582 'is_declaration': True, 582 'is_declaration': True,
583 'parameter_list': 583 'parameter_list':
584 ({'type': 'unsigned', 'name': 'a', 'row': 0}, 584 ({'type': 'unsigned', 'name': 'a', 'row': 0},
585 {'type': 'short', 'name': 'b', 'row': 0}, 585 {'type': 'short', 'name': 'b', 'row': 0},
586 {'type': 'long', 'name': 'c', 'row': 0}, 586 {'type': 'long', 'name': 'c', 'row': 0},
587 {'type': 'long long short unsigned int', 'name': '', 'row': 0} )}) 587 {'type': 'long long short unsigned int', 'name': '', 'row': 0} )})
588 588
589 # Some parameter type with modifiers and no parameter names. 589 # Some parameter type with modifiers and no parameter names.
590 function_state = self.perform_function_detection( 590 self.perform_function_detection(
591 [ 591 [
592 'virtual void determineARIADropEffects(Vector<String>*&, const u nsigned long int*&, const MediaPlayer::Preload, Other<Other2, Other3<P1, P2> >, int);'], 592 'virtual void determineARIADropEffects(Vector<String>*&, const u nsigned long int*&, const MediaPlayer::Preload, Other<Other2, Other3<P1, P2> >, int);'],
593 {'name': 'determineARIADropEffects', 593 {'name': 'determineARIADropEffects',
594 'modifiers_and_return_type': 'virtual void', 594 'modifiers_and_return_type': 'virtual void',
595 'parameter_start_position': (0, 37), 595 'parameter_start_position': (0, 37),
596 'function_name_start_position': (0, 13), 596 'function_name_start_position': (0, 13),
597 'parameter_end_position': (0, 147), 597 'parameter_end_position': (0, 147),
598 'body_start_position': (0, 147), 598 'body_start_position': (0, 147),
599 'end_position': (0, 148), 599 'end_position': (0, 148),
600 'is_pure': False, 600 'is_pure': False,
601 'is_declaration': True, 601 'is_declaration': True,
602 'parameter_list': 602 'parameter_list':
603 ({'type': 'Vector<String>*&', 'name': '', 'row': 0}, 603 ({'type': 'Vector<String>*&', 'name': '', 'row': 0},
604 {'type': 'const unsigned long int*&', 'name': '', 'row': 0}, 604 {'type': 'const unsigned long int*&', 'name': '', 'row': 0},
605 {'type': 'const MediaPlayer::Preload', 'name': '', 'row': 0}, 605 {'type': 'const MediaPlayer::Preload', 'name': '', 'row': 0},
606 {'type': 'Other<Other2, Other3<P1, P2> >', 'name': '', 'row': 0}, 606 {'type': 'Other<Other2, Other3<P1, P2> >', 'name': '', 'row': 0},
607 {'type': 'int', 'name': '', 'row': 0})}) 607 {'type': 'int', 'name': '', 'row': 0})})
608 608
609 # Try parsing a function with a very complex definition. 609 # Try parsing a function with a very complex definition.
610 function_state = self.perform_function_detection( 610 self.perform_function_detection(
611 ['#define MyMacro(a) a', 611 ['#define MyMacro(a) a',
612 'virtual', 612 'virtual',
613 'AnotherTemplate<Class1, Class2> aFunctionName(PassRefPtr<MyClass> paramName,', 613 'AnotherTemplate<Class1, Class2> aFunctionName(PassRefPtr<MyClass> paramName,',
614 'const Other1Class& foo,', 614 'const Other1Class& foo,',
615 'const ComplexTemplate<Class1, NestedTemplate<P1, P2> >* const * pa ram = new ComplexTemplate<Class1, NestedTemplate<P1, P2> >(34, 42),', 615 'const ComplexTemplate<Class1, NestedTemplate<P1, P2> >* const * pa ram = new ComplexTemplate<Class1, NestedTemplate<P1, P2> >(34, 42),',
616 'int* myCount = 0);'], 616 'int* myCount = 0);'],
617 {'name': 'aFunctionName', 617 {'name': 'aFunctionName',
618 'modifiers_and_return_type': 'virtual AnotherTemplate<Class1, Class 2>', 618 'modifiers_and_return_type': 'virtual AnotherTemplate<Class1, Class 2>',
619 'function_name_start_position': (2, 32), 619 'function_name_start_position': (2, 32),
620 'parameter_start_position': (2, 45), 620 'parameter_start_position': (2, 45),
(...skipping 1853 matching lines...) Expand 10 before | Expand all | Expand 10 after
2474 build_storage_class_error_message) 2474 build_storage_class_error_message)
2475 2475
2476 self.assert_lint('int register foo = 0;', 2476 self.assert_lint('int register foo = 0;',
2477 build_storage_class_error_message) 2477 build_storage_class_error_message)
2478 2478
2479 # Since there are a very large number of possibilities, randomly 2479 # Since there are a very large number of possibilities, randomly
2480 # construct declarations. 2480 # construct declarations.
2481 # Make sure that the declaration is logged if there's an error. 2481 # Make sure that the declaration is logged if there's an error.
2482 # Seed generator with an integer for absolute reproducibility. 2482 # Seed generator with an integer for absolute reproducibility.
2483 random.seed(25) 2483 random.seed(25)
2484 for unused_i in range(10): 2484 for _ in range(10):
2485 # Build up random list of non-storage-class declaration specs. 2485 # Build up random list of non-storage-class declaration specs.
2486 other_decl_specs = [random.choice(qualifiers), random.choice(signs), 2486 other_decl_specs = [random.choice(qualifiers), random.choice(signs),
2487 random.choice(types)] 2487 random.choice(types)]
2488 # remove None 2488 # remove None
2489 other_decl_specs = filter(lambda x: x is not None, other_decl_specs) 2489 other_decl_specs = filter(lambda x: x is not None, other_decl_specs)
2490 2490
2491 # shuffle 2491 # shuffle
2492 random.shuffle(other_decl_specs) 2492 random.shuffle(other_decl_specs)
2493 2493
2494 # insert storage class after the first 2494 # insert storage class after the first
(...skipping 25 matching lines...) Expand all
2520 # There should be a copyright message in the first 10 lines 2520 # There should be a copyright message in the first 10 lines
2521 error_collector = ErrorCollector(self.assertTrue) 2521 error_collector = ErrorCollector(self.assertTrue)
2522 self.process_file_data(file_path, 'cpp', [], error_collector) 2522 self.process_file_data(file_path, 'cpp', [], error_collector)
2523 self.assertEqual( 2523 self.assertEqual(
2524 1, 2524 1,
2525 error_collector.result_list().count(legal_copyright_message)) 2525 error_collector.result_list().count(legal_copyright_message))
2526 2526
2527 error_collector = ErrorCollector(self.assertTrue) 2527 error_collector = ErrorCollector(self.assertTrue)
2528 self.process_file_data( 2528 self.process_file_data(
2529 file_path, 'cpp', 2529 file_path, 'cpp',
2530 ['' for unused_i in range(10)] + [copyright_line], 2530 ['' for _ in range(10)] + [copyright_line],
2531 error_collector) 2531 error_collector)
2532 self.assertEqual( 2532 self.assertEqual(
2533 1, 2533 1,
2534 error_collector.result_list().count(legal_copyright_message)) 2534 error_collector.result_list().count(legal_copyright_message))
2535 2535
2536 # Test that warning isn't issued if Copyright line appears early enough. 2536 # Test that warning isn't issued if Copyright line appears early enough.
2537 error_collector = ErrorCollector(self.assertTrue) 2537 error_collector = ErrorCollector(self.assertTrue)
2538 self.process_file_data(file_path, 'cpp', [copyright_line], error_collect or) 2538 self.process_file_data(file_path, 'cpp', [copyright_line], error_collect or)
2539 for message in error_collector.result_list(): 2539 for message in error_collector.result_list():
2540 if message.find('legal/copyright') != -1: 2540 if message.find('legal/copyright') != -1:
2541 self.fail('Unexpected error: %s' % message) 2541 self.fail('Unexpected error: %s' % message)
2542 2542
2543 error_collector = ErrorCollector(self.assertTrue) 2543 error_collector = ErrorCollector(self.assertTrue)
2544 self.process_file_data( 2544 self.process_file_data(
2545 file_path, 'cpp', 2545 file_path, 'cpp',
2546 ['' for unused_i in range(9)] + [copyright_line], 2546 ['' for _ in range(9)] + [copyright_line],
2547 error_collector) 2547 error_collector)
2548 for message in error_collector.result_list(): 2548 for message in error_collector.result_list():
2549 if message.find('legal/copyright') != -1: 2549 if message.find('legal/copyright') != -1:
2550 self.fail('Unexpected error: %s' % message) 2550 self.fail('Unexpected error: %s' % message)
2551 2551
2552 def test_invalid_increment(self): 2552 def test_invalid_increment(self):
2553 self.assert_lint('*count++;', 2553 self.assert_lint('*count++;',
2554 'Changing pointer instead of value (or unused value of ' 2554 'Changing pointer instead of value (or unused value of '
2555 'operator*). [runtime/invalid_increment] [5]') 2555 'operator*). [runtime/invalid_increment] [5]')
2556 2556
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
3289 ('Small and focused functions are preferred: ' 3289 ('Small and focused functions are preferred: '
3290 'TEST_F(GoogleUpdateRecoveryRegistryProtectedTest, ' # 1 space 3290 'TEST_F(GoogleUpdateRecoveryRegistryProtectedTest, ' # 1 space
3291 'FixGoogleUpdate_AllValues_MachineApp) has %d non-comment lines ' 3291 'FixGoogleUpdate_AllValues_MachineApp) has %d non-comment lines '
3292 '(error triggered by exceeding %d lines).' 3292 '(error triggered by exceeding %d lines).'
3293 ' [readability/fn_size] [%d]') 3293 ' [readability/fn_size] [%d]')
3294 % (error_lines, trigger_level, error_level)) 3294 % (error_lines, trigger_level, error_level))
3295 3295
3296 def test_function_length_check_definition_severity1_for_bad_test_doesnt_brea k(self): 3296 def test_function_length_check_definition_severity1_for_bad_test_doesnt_brea k(self):
3297 error_level = 1 3297 error_level = 1
3298 error_lines = self.trigger_test_lines(error_level) + 1 3298 error_lines = self.trigger_test_lines(error_level) + 1
3299 trigger_level = self.trigger_test_lines(self.min_confidence)
3300 # Since the function name isn't valid, the function detection algorithm 3299 # Since the function name isn't valid, the function detection algorithm
3301 # will skip it, so no error is produced. 3300 # will skip it, so no error is produced.
3302 self.assert_function_lengths_check( 3301 self.assert_function_lengths_check(
3303 ('TEST_F(' 3302 ('TEST_F('
3304 + self.function_body(error_lines)), 3303 + self.function_body(error_lines)),
3305 '') 3304 '')
3306 3305
3307 def test_function_length_check_definition_severity1_with_embedded_no_lints(s elf): 3306 def test_function_length_check_definition_severity1_with_embedded_no_lints(s elf):
3308 error_level = 1 3307 error_level = 1
3309 error_lines = self.trigger_lines(error_level) + 1 3308 error_lines = self.trigger_lines(error_level) + 1
(...skipping 1981 matching lines...) Expand 10 before | Expand all | Expand 10 after
5291 def test_ne(self): 5290 def test_ne(self):
5292 """Test __ne__ inequality function.""" 5291 """Test __ne__ inequality function."""
5293 checker1 = self._checker() 5292 checker1 = self._checker()
5294 checker2 = self._checker() 5293 checker2 = self._checker()
5295 5294
5296 # != calls __ne__. 5295 # != calls __ne__.
5297 # By default, __ne__ always returns true on different objects. 5296 # By default, __ne__ always returns true on different objects.
5298 # Thus, just check the distinguishing case to verify that the 5297 # Thus, just check the distinguishing case to verify that the
5299 # code defines __ne__. 5298 # code defines __ne__.
5300 self.assertFalse(checker1 != checker2) 5299 self.assertFalse(checker1 != checker2)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698