@@ -257,18 +257,19 @@ def TestIncludeWhatYouUse(self, code, expected_message):
257257 self .PerformIncludeWhatYouUse (code ))
258258
259259 def TestBlankLinesCheck (self , lines , start_errors , end_errors ):
260- error_collector = ErrorCollector (self .assert_ )
261- cpplint .ProcessFileData ('foo.cc' , 'cc' , lines , error_collector )
262- self .assertEquals (
263- start_errors ,
264- error_collector .Results ().count (
265- 'Redundant blank line at the start of a code block '
266- 'should be deleted. [whitespace/blank_line] [2]' ))
267- self .assertEquals (
268- end_errors ,
269- error_collector .Results ().count (
270- 'Redundant blank line at the end of a code block '
271- 'should be deleted. [whitespace/blank_line] [3]' ))
260+ for extension in ['c' , 'cc' , 'cpp' , 'cxx' , 'c++' , 'cu' ]:
261+ error_collector = ErrorCollector (self .assert_ )
262+ cpplint .ProcessFileData ('foo.' + extension , extension , lines , error_collector )
263+ self .assertEquals (
264+ start_errors ,
265+ error_collector .Results ().count (
266+ 'Redundant blank line at the start of a code block '
267+ 'should be deleted. [whitespace/blank_line] [2]' ))
268+ self .assertEquals (
269+ end_errors ,
270+ error_collector .Results ().count (
271+ 'Redundant blank line at the end of a code block '
272+ 'should be deleted. [whitespace/blank_line] [3]' ))
272273
273274
274275class CpplintTest (CpplintTestBase ):
@@ -777,11 +778,13 @@ def testTypedefForPointerToFunction(self):
777778
778779 def testIncludeWhatYouUseNoImplementationFiles (self ):
779780 code = 'std::vector<int> foo;'
780- self .assertEquals ('Add #include <vector> for vector<>'
781- ' [build/include_what_you_use] [4]' ,
782- self .PerformIncludeWhatYouUse (code , 'foo.h' ))
783- self .assertEquals ('' ,
784- self .PerformIncludeWhatYouUse (code , 'foo.cc' ))
781+ for extension in ['h' , 'hpp' , 'hxx' , 'h++' , 'cuh' ]:
782+ self .assertEquals ('Add #include <vector> for vector<>'
783+ ' [build/include_what_you_use] [4]' ,
784+ self .PerformIncludeWhatYouUse (code , 'foo.' + extension ))
785+ for extension in ['c' , 'cc' , 'cpp' , 'cxx' , 'c++' , 'cu' ]:
786+ self .assertEquals ('' ,
787+ self .PerformIncludeWhatYouUse (code , 'foo.' + extension ))
785788
786789 def testIncludeWhatYouUse (self ):
787790 self .TestIncludeWhatYouUse (
@@ -966,7 +969,12 @@ def testFilesBelongToSameModule(self):
966969 f = cpplint .FilesBelongToSameModule
967970 self .assertEquals ((True , '' ), f ('a.cc' , 'a.h' ))
968971 self .assertEquals ((True , '' ), f ('base/google.cc' , 'base/google.h' ))
969- self .assertEquals ((True , '' ), f ('base/google_test.cc' , 'base/google.h' ))
972+ self .assertEquals ((True , '' ), f ('base/google_test.c' , 'base/google.h' ))
973+ self .assertEquals ((True , '' ), f ('base/google_test.cc' , 'base/google.hpp' ))
974+ self .assertEquals ((True , '' ), f ('base/google_test.cxx' , 'base/google.hxx' ))
975+ self .assertEquals ((True , '' ), f ('base/google_test.cpp' , 'base/google.hpp' ))
976+ self .assertEquals ((True , '' ), f ('base/google_test.c++' , 'base/google.h++' ))
977+ self .assertEquals ((True , '' ), f ('base/google_test.cu' , 'base/google.cuh' ))
970978 self .assertEquals ((True , '' ),
971979 f ('base/google_unittest.cc' , 'base/google.h' ))
972980 self .assertEquals ((True , '' ),
@@ -1123,16 +1131,17 @@ def testMultilineStrings(self):
11231131 'Use C++11 raw strings or concatenation instead.'
11241132 ' [readability/multiline_string] [5]' )
11251133
1126- file_path = 'mydir/foo.cc'
1134+ for extension in ['c' , 'cc' , 'cpp' , 'cxx' , 'c++' , 'cu' ]:
1135+ file_path = 'mydir/foo.' + extension
11271136
1128- error_collector = ErrorCollector (self .assert_ )
1129- cpplint .ProcessFileData (file_path , 'cc' ,
1130- ['const char* str = "This is a\\ ' ,
1131- ' multiline string.";' ],
1132- error_collector )
1133- self .assertEquals (
1134- 2 , # One per line.
1135- error_collector .ResultList ().count (multiline_string_error_message ))
1137+ error_collector = ErrorCollector (self .assert_ )
1138+ cpplint .ProcessFileData (file_path , extension ,
1139+ ['const char* str = "This is a\\ ' ,
1140+ ' multiline string.";' ],
1141+ error_collector )
1142+ self .assertEquals (
1143+ 2 , # One per line.
1144+ error_collector .ResultList ().count (multiline_string_error_message ))
11361145
11371146 # Test non-explicit single-argument constructors
11381147 def testExplicitSingleArgumentConstructors (self ):
@@ -3947,18 +3956,20 @@ def testDuplicateHeader(self):
39473956 error_collector .ResultList ())
39483957
39493958 def testUnnamedNamespacesInHeaders (self ):
3950- self .TestLanguageRulesCheck (
3951- 'foo.h' , 'namespace {' ,
3952- 'Do not use unnamed namespaces in header files. See'
3953- ' http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces'
3954- ' for more information. [build/namespaces] [4]' )
3955- # namespace registration macros are OK.
3956- self .TestLanguageRulesCheck ('foo.h' , 'namespace { \\ ' , '' )
3957- # named namespaces are OK.
3958- self .TestLanguageRulesCheck ('foo.h' , 'namespace foo {' , '' )
3959- self .TestLanguageRulesCheck ('foo.h' , 'namespace foonamespace {' , '' )
3960- self .TestLanguageRulesCheck ('foo.cc' , 'namespace {' , '' )
3961- self .TestLanguageRulesCheck ('foo.cc' , 'namespace foo {' , '' )
3959+ for extension in ['h' , 'hpp' , 'hxx' , 'h++' , 'cuh' ]:
3960+ self .TestLanguageRulesCheck (
3961+ 'foo.' + extension , 'namespace {' ,
3962+ 'Do not use unnamed namespaces in header files. See'
3963+ ' http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces'
3964+ ' for more information. [build/namespaces] [4]' )
3965+ # namespace registration macros are OK.
3966+ self .TestLanguageRulesCheck ('foo.' + extension , 'namespace { \\ ' , '' )
3967+ # named namespaces are OK.
3968+ self .TestLanguageRulesCheck ('foo.' + extension , 'namespace foo {' , '' )
3969+ self .TestLanguageRulesCheck ('foo.' + extension , 'namespace foonamespace {' , '' )
3970+ for extension in ['c' , 'cc' , 'cpp' , 'cxx' , 'c++' , 'cu' ]:
3971+ self .TestLanguageRulesCheck ('foo.' + extension , 'namespace {' , '' )
3972+ self .TestLanguageRulesCheck ('foo.' + extension , 'namespace foo {' , '' )
39623973
39633974 def testBuildClass (self ):
39643975 # Test that the linter can parse to the end of class definitions,
@@ -4675,15 +4686,30 @@ def testClassifyInclude(self):
46754686
46764687 def testTryDropCommonSuffixes (self ):
46774688 self .assertEqual ('foo/foo' , cpplint ._DropCommonSuffixes ('foo/foo-inl.h' ))
4689+ self .assertEqual ('foo/foo' , cpplint ._DropCommonSuffixes ('foo/foo-inl.hxx' ))
4690+ self .assertEqual ('foo/foo' , cpplint ._DropCommonSuffixes ('foo/foo-inl.h++' ))
4691+ self .assertEqual ('foo/foo' , cpplint ._DropCommonSuffixes ('foo/foo-inl.hpp' ))
46784692 self .assertEqual ('foo/bar/foo' ,
46794693 cpplint ._DropCommonSuffixes ('foo/bar/foo_inl.h' ))
46804694 self .assertEqual ('foo/foo' , cpplint ._DropCommonSuffixes ('foo/foo.cc' ))
4695+ self .assertEqual ('foo/foo' , cpplint ._DropCommonSuffixes ('foo/foo.cxx' ))
4696+ self .assertEqual ('foo/foo' , cpplint ._DropCommonSuffixes ('foo/foo.c' ))
46814697 self .assertEqual ('foo/foo_unusualinternal' ,
46824698 cpplint ._DropCommonSuffixes ('foo/foo_unusualinternal.h' ))
4699+ self .assertEqual ('foo/foo_unusualinternal' ,
4700+ cpplint ._DropCommonSuffixes ('foo/foo_unusualinternal.hpp' ))
46834701 self .assertEqual ('' ,
46844702 cpplint ._DropCommonSuffixes ('_test.cc' ))
4703+ self .assertEqual ('' ,
4704+ cpplint ._DropCommonSuffixes ('_test.c' ))
4705+ self .assertEqual ('' ,
4706+ cpplint ._DropCommonSuffixes ('_test.c++' ))
4707+ self .assertEqual ('test' ,
4708+ cpplint ._DropCommonSuffixes ('test.c' ))
46854709 self .assertEqual ('test' ,
46864710 cpplint ._DropCommonSuffixes ('test.cc' ))
4711+ self .assertEqual ('test' ,
4712+ cpplint ._DropCommonSuffixes ('test.c++' ))
46874713
46884714 def testRegression (self ):
46894715 def Format (includes ):
0 commit comments