OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2014 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 import unittest |
| 7 |
| 8 from checker import Checker, FileCache |
| 9 |
| 10 |
| 11 class CodingConventionTest(unittest.TestCase): |
| 12 def __init__(self, *args, **kwargs): |
| 13 unittest.TestCase.__init__(self, *args, **kwargs) |
| 14 self.maxDiff = None |
| 15 |
| 16 def setUp(self): |
| 17 self._checker = Checker(verbose=False, exit_on_fatal=False) |
| 18 |
| 19 def testGetInstance(self): |
| 20 test_name = "getInstance" |
| 21 file_content = """ |
| 22 var cr = { |
| 23 /** @param {!Function} ctor */ |
| 24 addSingletonGetter: function(ctor) { |
| 25 ctor.getInstance = function() { |
| 26 return ctor.instance_ || (ctor.instance_ = new ctor()); |
| 27 }; |
| 28 } |
| 29 }; |
| 30 |
| 31 /** @constructor */ |
| 32 function Class() { |
| 33 /** @param {number} num */ |
| 34 this.needsNumber = function(num) {}; |
| 35 } |
| 36 |
| 37 cr.addSingletonGetter(Class); |
| 38 Class.getInstance().needsNumber("wrong type"); |
| 39 """ |
| 40 expected_chunk = "WARNING - actual parameter 1 of Class.needsNumber does not
match formal parameter" |
| 41 |
| 42 file_path = "/script.js" |
| 43 FileCache._cache[file_path] = file_content |
| 44 _, output = self._checker.check(file_path) |
| 45 |
| 46 self.assertTrue(expected_chunk in output, |
| 47 msg="%s\n\nExpected chunk: \n%s\n\nOutput:\n%s\n" % ( |
| 48 test_name, expected_chunk, output)) |
| 49 |
| 50 |
| 51 if __name__ == "__main__": |
| 52 unittest.main() |
OLD | NEW |