Commit 70818a1f authored by Ben Boeckel's avatar Ben Boeckel

HeaderTesting: check header guards

parent ab61d3af
......@@ -190,6 +190,37 @@ class TestVTKFiles:
self.Error("Does not include parent")
def CheckGuard(self):
guardre = r"^#ifndef\s+([^ ]*)_h$"
guardsetre = r"^#define\s+([^ ]*)_h$"
guardrex = re.compile(guardre)
guardsetrex = re.compile(guardsetre)
guard = None
guard_set = None
expect_trigger = False
for line in self.FileLines:
line = line.strip()
if expect_trigger:
gs = guardsetrex.match(line)
if gs:
guard_set =
g = guardrex.match(line)
if g:
guard =
expect_trigger = True
if not guard or not guard_set:
self.Print("File: %s is missing a header guard." % self.FileName)
self.Error("Missing header guard")
elif not guard == guard_set:
self.Print("File: %s is not guarded properly." % self.FileName)
self.Error("Guard does is not set properly")
elif not ('%s.h' % guard) == os.path.basename(self.FileName):
self.Print("File: %s has a guard (%s) which does not match its filename." % (self.FileName, guard))
self.Error("Guard does not match the filename")
def CheckParent(self):
classre = "^class(\s+[^\s]*_EXPORT)?\s+(vtk[A-Z0-9_][^ :\n]*)\s*:\s*public\s+(vtk[^ \n\{]*)"
cname = ""
......@@ -459,6 +490,7 @@ for a in os.listdir(dirname):
elif stat.S_ISREG(mode) and test.TestFile(pathname):
## Do all the tests
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment