(self)
| 5196 | return None |
| 5197 | |
| 5198 | def testBuildHeaderGuard(self): |
| 5199 | file_path = "mydir/foo.h" |
| 5200 | expected_guard = self.GetBuildHeaderGuardPreprocessorSymbol(file_path) |
| 5201 | assert re.search("MYDIR_FOO_H_$", expected_guard) |
| 5202 | |
| 5203 | # No guard at all: expect one error. |
| 5204 | error_collector = ErrorCollector(self.assertTrue) |
| 5205 | cpplint.ProcessFileData(file_path, "h", [], error_collector) |
| 5206 | assert ( |
| 5207 | error_collector.ResultList().count( |
| 5208 | "No #ifndef header guard found, suggested CPP variable is: %s " |
| 5209 | "[build/header_guard] [5]" % expected_guard |
| 5210 | ) |
| 5211 | == 1 |
| 5212 | ), error_collector.ResultList() |
| 5213 | |
| 5214 | # No header guard, but the error is suppressed. |
| 5215 | error_collector = ErrorCollector(self.assertTrue) |
| 5216 | cpplint.ProcessFileData( |
| 5217 | file_path, |
| 5218 | "h", |
| 5219 | ["// Copyright 2014 Your Company.", "// NOLINT(build/header_guard)", ""], |
| 5220 | error_collector, |
| 5221 | ) |
| 5222 | assert error_collector.ResultList() == [] |
| 5223 | |
| 5224 | # Wrong guard |
| 5225 | error_collector = ErrorCollector(self.assertTrue) |
| 5226 | cpplint.ProcessFileData(file_path, "h", ["#ifndef FOO_H", "#define FOO_H"], error_collector) |
| 5227 | assert ( |
| 5228 | error_collector.ResultList().count( |
| 5229 | "#ifndef header guard has wrong style, please use: %s [build/header_guard] [5]" |
| 5230 | % expected_guard |
| 5231 | ) |
| 5232 | == 1 |
| 5233 | ), error_collector.ResultList() |
| 5234 | |
| 5235 | # No define |
| 5236 | error_collector = ErrorCollector(self.assertTrue) |
| 5237 | cpplint.ProcessFileData(file_path, "h", ["#ifndef %s" % expected_guard], error_collector) |
| 5238 | assert ( |
| 5239 | error_collector.ResultList().count( |
| 5240 | "No #ifndef header guard found, suggested CPP variable is: %s " |
| 5241 | "[build/header_guard] [5]" % expected_guard |
| 5242 | ) |
| 5243 | == 1 |
| 5244 | ), error_collector.ResultList() |
| 5245 | |
| 5246 | # Mismatched define |
| 5247 | error_collector = ErrorCollector(self.assertTrue) |
| 5248 | cpplint.ProcessFileData( |
| 5249 | file_path, "h", ["#ifndef %s" % expected_guard, "#define FOO_H"], error_collector |
| 5250 | ) |
| 5251 | assert ( |
| 5252 | error_collector.ResultList().count( |
| 5253 | "No #ifndef header guard found, suggested CPP variable is: %s " |
| 5254 | "[build/header_guard] [5]" % expected_guard |
| 5255 | ) |
nothing calls this directly
no test coverage detected