diff options
author | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-31 10:40:01 +0000 |
---|---|---|
committer | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-31 10:40:01 +0000 |
commit | 0aa12e030026c0f3657744fc828b934f3b700e3f (patch) | |
tree | 28f539f827a4995f31383dc23497b229259547ca /tools/checkdeps/checkdeps_test.py | |
parent | a0a045252015fef2c45deaac991467c0d2bd4576 (diff) | |
download | chromium_src-0aa12e030026c0f3657744fc828b934f3b700e3f.zip chromium_src-0aa12e030026c0f3657744fc828b934f3b700e3f.tar.gz chromium_src-0aa12e030026c0f3657744fc828b934f3b700e3f.tar.bz2 |
Implement ability to specify temporarily-allowed dependencies in DEPS
files, and use this ability in a few DEPS files where appropriate.
This has no effect on the normal running of checkdeps; "!"
dependencies are treated just like "+" dependencies when checkdeps is
run on our bots.
An upcoming change will use the new checkdeps.CheckAddedIncludes
function, and will error out if you add a new include that violates a
"-" rule, and show a presubmit warning when you add a new include that
violates a "!" rule (the warning will say something like "We are in
the process of removing dependencies from this directory to that file,
can you avoid adding more?"
While I was in there, fixed path handling so that checkdeps will work
on case-sensitive platforms with paths that include upper-case
characters (e.g. a checkout of Chrome at ~/c/Chrome/src rather than
~/c/chrome/src).
Since the pipes.quote method seems unreliable on Windows (it failed on
my setup), switched to subprocess.list2cmdline which I believe is
stable.
Added a small manual testing mode to checkdeps. It currently only
verifies the CheckAddedIncludes function.
TBR=jam@chromium.org
BUG=138280
Review URL: https://chromiumcodereview.appspot.com/10805042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149163 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/checkdeps/checkdeps_test.py')
-rwxr-xr-x | tools/checkdeps/checkdeps_test.py | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/tools/checkdeps/checkdeps_test.py b/tools/checkdeps/checkdeps_test.py new file mode 100755 index 0000000..e650baf --- /dev/null +++ b/tools/checkdeps/checkdeps_test.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""Tests for checkdeps. +""" + +import os +import unittest + + +import checkdeps + + +class CheckDepsTest(unittest.TestCase): + + def setUp(self): + self.deps_checker = checkdeps.DepsChecker(being_tested=True) + + def testRegularCheckDepsRun(self): + problems = self.deps_checker.CheckDirectory( + os.path.join(self.deps_checker.base_directory, + 'tools/checkdeps/testdata')) + self.failUnlessEqual(3, len(problems)) + + def VerifySubstringsInProblems(key_path, substrings_in_sequence): + found = False + key_path = os.path.normpath(key_path) + for problem in problems: + index = problem.find(key_path) + if index != -1: + for substring in substrings_in_sequence: + index = problem.find(substring, index + 1) + self.failUnless(index != -1) + found = True + break + if not found: + self.fail('Found no problem for file %s' % key_path) + + VerifySubstringsInProblems('testdata/allowed/test.h', + ['-tools/checkdeps/testdata/disallowed', + '-third_party/explicitly_disallowed', + 'Because of no rule applying']) + VerifySubstringsInProblems('testdata/disallowed/test.h', + ['-third_party/explicitly_disallowed', + 'Because of no rule applying', + 'Because of no rule applying']) + VerifySubstringsInProblems('disallowed/allowed/test.h', + ['-third_party/explicitly_disallowed', + 'Because of no rule applying', + 'Because of no rule applying']) + + def testCheckAddedIncludesAllGood(self): + problems = self.deps_checker.CheckAddedCppIncludes( + [['tools/checkdeps/testdata/allowed/test.cc', + ['#include "tools/checkdeps/testdata/allowed/good.h"', + '#include "tools/checkdeps/testdata/disallowed/allowed/good.h"'] + ]]) + self.failIf(problems) + + def testCheckAddedIncludesManyGarbageLines(self): + garbage_lines = ["My name is Sam%d\n" % num for num in range(50)] + problems = self.deps_checker.CheckAddedCppIncludes( + [['tools/checkdeps/testdata/allowed/test.cc', garbage_lines]]) + self.failIf(problems) + + def testCheckAddedIncludesNoRule(self): + problems = self.deps_checker.CheckAddedCppIncludes( + [['tools/checkdeps/testdata/allowed/test.cc', + ['#include "no_rule_for_this/nogood.h"'] + ]]) + self.failUnless(problems) + + def testCheckAddedIncludesSkippedDirectory(self): + problems = self.deps_checker.CheckAddedCppIncludes( + [['tools/checkdeps/testdata/disallowed/allowed/skipped/test.cc', + ['#include "whatever/whocares.h"'] + ]]) + self.failIf(problems) + + def testCheckAddedIncludesTempAllowed(self): + problems = self.deps_checker.CheckAddedCppIncludes( + [['tools/checkdeps/testdata/allowed/test.cc', + ['#include "tools/checkdeps/testdata/disallowed/temporarily_allowed.h"'] + ]]) + self.failUnless(problems) + + +if __name__ == '__main__': + unittest.main() |