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 problem = problems[0] |
| 28 index = problem.find('testdata/allowed/test.h') |
| 29 self.failUnless(index != -1) |
| 30 index = problem.find('-tools/checkdeps/testdata/disallowed', index + 1) |
| 31 self.failUnless(index != -1) |
| 32 index = problem.find('-third_party/explicitly_disallowed', index + 1) |
| 33 self.failUnless(index != -1) |
| 34 index = problem.find('Because of no rule applying', index + 1) |
| 35 self.failUnless(index != -1) |
| 36 |
| 37 problem = problems[1] |
| 38 index = problem.find('testdata/disallowed/test.h') |
| 39 self.failUnless(index != -1) |
| 40 index = problem.find('-third_party/explicitly_disallowed', index + 1) |
| 41 self.failUnless(index != -1) |
| 42 index = problem.find('Because of no rule applying', index + 1) |
| 43 self.failUnless(index != -1) |
| 44 index = problem.find('Because of no rule applying', index + 1) |
| 45 self.failUnless(index != -1) |
| 46 |
| 47 problem = problems[2] |
| 48 index = problem.find('disallowed/allowed/test.h') |
| 49 self.failUnless(index != -1) |
| 50 index = problem.find('-third_party/explicitly_disallowed', index + 1) |
| 51 self.failUnless(index != -1) |
| 52 index = problem.find('Because of no rule applying', index + 1) |
| 53 self.failUnless(index != -1) |
| 54 index = problem.find('Because of no rule applying', index + 1) |
| 55 self.failUnless(index != -1) |
| 56 |
| 57 def testCheckAddedIncludesAllGood(self): |
| 58 problems = self.deps_checker.CheckAddedCppIncludes( |
| 59 [['tools/checkdeps/testdata/allowed/test.cc', |
| 60 ['#include "tools/checkdeps/testdata/allowed/good.h"', |
| 61 '#include "tools/checkdeps/testdata/disallowed/allowed/good.h"'] |
| 62 ]]) |
| 63 self.failIf(problems) |
| 64 |
| 65 def testCheckAddedIncludesManyGarbageLines(self): |
| 66 garbage_lines = ["My name is Sam%d\n" % num for num in range(50)] |
| 67 problems = self.deps_checker.CheckAddedCppIncludes( |
| 68 [['tools/checkdeps/testdata/allowed/test.cc', garbage_lines]]) |
| 69 self.failIf(problems) |
| 70 |
| 71 def testCheckAddedIncludesNoRule(self): |
| 72 problems = self.deps_checker.CheckAddedCppIncludes( |
| 73 [['tools/checkdeps/testdata/allowed/test.cc', |
| 74 ['#include "no_rule_for_this/nogood.h"'] |
| 75 ]]) |
| 76 self.failUnless(problems) |
| 77 |
| 78 def testCheckAddedIncludesSkippedDirectory(self): |
| 79 problems = self.deps_checker.CheckAddedCppIncludes( |
| 80 [['tools/checkdeps/testdata/disallowed/allowed/skipped/test.cc', |
| 81 ['#include "whatever/whocares.h"'] |
| 82 ]]) |
| 83 self.failIf(problems) |
| 84 |
| 85 def testCheckAddedIncludesTempAllowed(self): |
| 86 problems = self.deps_checker.CheckAddedCppIncludes( |
| 87 [['tools/checkdeps/testdata/allowed/test.cc', |
| 88 ['#include "tools/checkdeps/testdata/disallowed/temporarily_allowed.h"'] |
| 89 ]]) |
| 90 self.failUnless(problems) |
| 91 |
| 92 |
| 93 if __name__ == '__main__': |
| 94 unittest.main() |
OLD | NEW |