OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 """Tests for checkdeps. |
| 7 """ |
| 8 |
| 9 import os |
| 10 import unittest |
| 11 |
| 12 |
| 13 import checkdeps |
| 14 |
| 15 |
| 16 class CheckDepsTest(unittest.TestCase): |
| 17 |
| 18 def setUp(self): |
| 19 self.deps_checker = checkdeps.DepsChecker(being_tested=True) |
| 20 |
| 21 def testRegularCheckDepsRun(self): |
| 22 problems = self.deps_checker.CheckDirectory( |
| 23 os.path.join(self.deps_checker.base_directory, |
| 24 'tools/checkdeps/testdata')) |
| 25 self.failUnlessEqual(3, len(problems)) |
| 26 |
| 27 def VerifySubstringsInProblems(key_path, substrings_in_sequence): |
| 28 found = False |
| 29 key_path = os.path.normpath(key_path) |
| 30 for problem in problems: |
| 31 index = problem.find(key_path) |
| 32 if index != -1: |
| 33 for substring in substrings_in_sequence: |
| 34 index = problem.find(substring, index + 1) |
| 35 self.failUnless(index != -1) |
| 36 found = True |
| 37 break |
| 38 if not found: |
| 39 self.fail('Found no problem for file %s' % key_path) |
| 40 |
| 41 VerifySubstringsInProblems('testdata/allowed/test.h', |
| 42 ['-tools/checkdeps/testdata/disallowed', |
| 43 '-third_party/explicitly_disallowed', |
| 44 'Because of no rule applying']) |
| 45 VerifySubstringsInProblems('testdata/disallowed/test.h', |
| 46 ['-third_party/explicitly_disallowed', |
| 47 'Because of no rule applying', |
| 48 'Because of no rule applying']) |
| 49 VerifySubstringsInProblems('disallowed/allowed/test.h', |
| 50 ['-third_party/explicitly_disallowed', |
| 51 'Because of no rule applying', |
| 52 'Because of no rule applying']) |
| 53 |
| 54 def testCheckAddedIncludesAllGood(self): |
| 55 problems = self.deps_checker.CheckAddedCppIncludes( |
| 56 [['tools/checkdeps/testdata/allowed/test.cc', |
| 57 ['#include "tools/checkdeps/testdata/allowed/good.h"', |
| 58 '#include "tools/checkdeps/testdata/disallowed/allowed/good.h"'] |
| 59 ]]) |
| 60 self.failIf(problems) |
| 61 |
| 62 def testCheckAddedIncludesManyGarbageLines(self): |
| 63 garbage_lines = ["My name is Sam%d\n" % num for num in range(50)] |
| 64 problems = self.deps_checker.CheckAddedCppIncludes( |
| 65 [['tools/checkdeps/testdata/allowed/test.cc', garbage_lines]]) |
| 66 self.failIf(problems) |
| 67 |
| 68 def testCheckAddedIncludesNoRule(self): |
| 69 problems = self.deps_checker.CheckAddedCppIncludes( |
| 70 [['tools/checkdeps/testdata/allowed/test.cc', |
| 71 ['#include "no_rule_for_this/nogood.h"'] |
| 72 ]]) |
| 73 self.failUnless(problems) |
| 74 |
| 75 def testCheckAddedIncludesSkippedDirectory(self): |
| 76 problems = self.deps_checker.CheckAddedCppIncludes( |
| 77 [['tools/checkdeps/testdata/disallowed/allowed/skipped/test.cc', |
| 78 ['#include "whatever/whocares.h"'] |
| 79 ]]) |
| 80 self.failIf(problems) |
| 81 |
| 82 def testCheckAddedIncludesTempAllowed(self): |
| 83 problems = self.deps_checker.CheckAddedCppIncludes( |
| 84 [['tools/checkdeps/testdata/allowed/test.cc', |
| 85 ['#include "tools/checkdeps/testdata/disallowed/temporarily_allowed.h"'] |
| 86 ]]) |
| 87 self.failUnless(problems) |
| 88 |
| 89 |
| 90 if __name__ == '__main__': |
| 91 unittest.main() |
OLD | NEW |