@@ -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 ):
@@ -768,11 +769,13 @@ def testTypedefForPointerToFunction(self):
768769
769770 def testIncludeWhatYouUseNoImplementationFiles (self ):
770771 code = 'std::vector<int> foo;'
771- self .assertEquals ('Add #include <vector> for vector<>'
772- ' [build/include_what_you_use] [4]' ,
773- self .PerformIncludeWhatYouUse (code , 'foo.h' ))
774- self .assertEquals ('' ,
775- self .PerformIncludeWhatYouUse (code , 'foo.cc' ))
772+ for extension in ['h' , 'hpp' , 'hxx' , 'h++' , 'cuh' ]:
773+ self .assertEquals ('Add #include <vector> for vector<>'
774+ ' [build/include_what_you_use] [4]' ,
775+ self .PerformIncludeWhatYouUse (code , 'foo.' + extension ))
776+ for extension in ['c' , 'cc' , 'cpp' , 'cxx' , 'c++' , 'cu' ]:
777+ self .assertEquals ('' ,
778+ self .PerformIncludeWhatYouUse (code , 'foo.' + extension ))
776779
777780 def testIncludeWhatYouUse (self ):
778781 self .TestIncludeWhatYouUse (
@@ -957,7 +960,12 @@ def testFilesBelongToSameModule(self):
957960 f = cpplint .FilesBelongToSameModule
958961 self .assertEquals ((True , '' ), f ('a.cc' , 'a.h' ))
959962 self .assertEquals ((True , '' ), f ('base/google.cc' , 'base/google.h' ))
960- self .assertEquals ((True , '' ), f ('base/google_test.cc' , 'base/google.h' ))
963+ self .assertEquals ((True , '' ), f ('base/google_test.c' , 'base/google.h' ))
964+ self .assertEquals ((True , '' ), f ('base/google_test.cc' , 'base/google.hpp' ))
965+ self .assertEquals ((True , '' ), f ('base/google_test.cxx' , 'base/google.hxx' ))
966+ self .assertEquals ((True , '' ), f ('base/google_test.cpp' , 'base/google.hpp' ))
967+ self .assertEquals ((True , '' ), f ('base/google_test.c++' , 'base/google.h++' ))
968+ self .assertEquals ((True , '' ), f ('base/google_test.cu' , 'base/google.cuh' ))
961969 self .assertEquals ((True , '' ),
962970 f ('base/google_unittest.cc' , 'base/google.h' ))
963971 self .assertEquals ((True , '' ),
@@ -1098,16 +1106,17 @@ def testMultilineStrings(self):
10981106 'Use C++11 raw strings or concatenation instead.'
10991107 ' [readability/multiline_string] [5]' )
11001108
1101- file_path = 'mydir/foo.cc'
1109+ for extension in ['c' , 'cc' , 'cpp' , 'cxx' , 'c++' , 'cu' ]:
1110+ file_path = 'mydir/foo.' + extension
11021111
1103- error_collector = ErrorCollector (self .assert_ )
1104- cpplint .ProcessFileData (file_path , 'cc' ,
1105- ['const char* str = "This is a\\ ' ,
1106- ' multiline string.";' ],
1107- error_collector )
1108- self .assertEquals (
1109- 2 , # One per line.
1110- error_collector .ResultList ().count (multiline_string_error_message ))
1112+ error_collector = ErrorCollector (self .assert_ )
1113+ cpplint .ProcessFileData (file_path , extension ,
1114+ ['const char* str = "This is a\\ ' ,
1115+ ' multiline string.";' ],
1116+ error_collector )
1117+ self .assertEquals (
1118+ 2 , # One per line.
1119+ error_collector .ResultList ().count (multiline_string_error_message ))
11111120
11121121 # Test non-explicit single-argument constructors
11131122 def testExplicitSingleArgumentConstructors (self ):
@@ -3917,18 +3926,20 @@ def testDuplicateHeader(self):
39173926 error_collector .ResultList ())
39183927
39193928 def testUnnamedNamespacesInHeaders (self ):
3920- self .TestLanguageRulesCheck (
3921- 'foo.h' , 'namespace {' ,
3922- 'Do not use unnamed namespaces in header files. See'
3923- ' http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces'
3924- ' for more information. [build/namespaces] [4]' )
3925- # namespace registration macros are OK.
3926- self .TestLanguageRulesCheck ('foo.h' , 'namespace { \\ ' , '' )
3927- # named namespaces are OK.
3928- self .TestLanguageRulesCheck ('foo.h' , 'namespace foo {' , '' )
3929- self .TestLanguageRulesCheck ('foo.h' , 'namespace foonamespace {' , '' )
3930- self .TestLanguageRulesCheck ('foo.cc' , 'namespace {' , '' )
3931- self .TestLanguageRulesCheck ('foo.cc' , 'namespace foo {' , '' )
3929+ for extension in ['h' , 'hpp' , 'hxx' , 'h++' , 'cuh' ]:
3930+ self .TestLanguageRulesCheck (
3931+ 'foo.' + extension , 'namespace {' ,
3932+ 'Do not use unnamed namespaces in header files. See'
3933+ ' http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces'
3934+ ' for more information. [build/namespaces] [4]' )
3935+ # namespace registration macros are OK.
3936+ self .TestLanguageRulesCheck ('foo.' + extension , 'namespace { \\ ' , '' )
3937+ # named namespaces are OK.
3938+ self .TestLanguageRulesCheck ('foo.' + extension , 'namespace foo {' , '' )
3939+ self .TestLanguageRulesCheck ('foo.' + extension , 'namespace foonamespace {' , '' )
3940+ for extension in ['c' , 'cc' , 'cpp' , 'cxx' , 'c++' , 'cu' ]:
3941+ self .TestLanguageRulesCheck ('foo.' + extension , 'namespace {' , '' )
3942+ self .TestLanguageRulesCheck ('foo.' + extension , 'namespace foo {' , '' )
39323943
39333944 def testBuildClass (self ):
39343945 # Test that the linter can parse to the end of class definitions,
@@ -4645,15 +4656,30 @@ def testClassifyInclude(self):
46454656
46464657 def testTryDropCommonSuffixes (self ):
46474658 self .assertEqual ('foo/foo' , cpplint ._DropCommonSuffixes ('foo/foo-inl.h' ))
4659+ self .assertEqual ('foo/foo' , cpplint ._DropCommonSuffixes ('foo/foo-inl.hxx' ))
4660+ self .assertEqual ('foo/foo' , cpplint ._DropCommonSuffixes ('foo/foo-inl.h++' ))
4661+ self .assertEqual ('foo/foo' , cpplint ._DropCommonSuffixes ('foo/foo-inl.hpp' ))
46484662 self .assertEqual ('foo/bar/foo' ,
46494663 cpplint ._DropCommonSuffixes ('foo/bar/foo_inl.h' ))
46504664 self .assertEqual ('foo/foo' , cpplint ._DropCommonSuffixes ('foo/foo.cc' ))
4665+ self .assertEqual ('foo/foo' , cpplint ._DropCommonSuffixes ('foo/foo.cxx' ))
4666+ self .assertEqual ('foo/foo' , cpplint ._DropCommonSuffixes ('foo/foo.c' ))
46514667 self .assertEqual ('foo/foo_unusualinternal' ,
46524668 cpplint ._DropCommonSuffixes ('foo/foo_unusualinternal.h' ))
4669+ self .assertEqual ('foo/foo_unusualinternal' ,
4670+ cpplint ._DropCommonSuffixes ('foo/foo_unusualinternal.hpp' ))
46534671 self .assertEqual ('' ,
46544672 cpplint ._DropCommonSuffixes ('_test.cc' ))
4673+ self .assertEqual ('' ,
4674+ cpplint ._DropCommonSuffixes ('_test.c' ))
4675+ self .assertEqual ('' ,
4676+ cpplint ._DropCommonSuffixes ('_test.c++' ))
4677+ self .assertEqual ('test' ,
4678+ cpplint ._DropCommonSuffixes ('test.c' ))
46554679 self .assertEqual ('test' ,
46564680 cpplint ._DropCommonSuffixes ('test.cc' ))
4681+ self .assertEqual ('test' ,
4682+ cpplint ._DropCommonSuffixes ('test.c++' ))
46574683
46584684 def testRegression (self ):
46594685 def Format (includes ):
0 commit comments