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) | |
Dan Beam
2014/07/30 00:40:53
^ this __init__ method is the same as not having t
Vitaly Pavlenko
2014/07/30 17:01:41
Done.
| |
14 | |
15 def setUp(self): | |
16 self._checker = Checker(verbose=False) | |
17 | |
18 def testGetInstance(self): | |
19 file_content = """ | |
20 var cr = { | |
21 /** @param {!Function} ctor */ | |
22 addSingletonGetter: function(ctor) { | |
23 ctor.getInstance = function() { | |
24 return ctor.instance_ || (ctor.instance_ = new ctor()); | |
25 }; | |
26 } | |
27 }; | |
28 | |
29 /** @constructor */ | |
30 function Class() { | |
31 /** @param {number} num */ | |
32 this.needsNumber = function(num) {}; | |
33 } | |
34 | |
35 cr.addSingletonGetter(Class); | |
36 Class.getInstance().needsNumber("wrong type"); | |
37 """ | |
38 expected_chunk = "WARNING - actual parameter 1 of Class.needsNumber does not match formal parameter" | |
39 | |
40 file_path = "/script.js" | |
41 FileCache._cache[file_path] = file_content | |
42 _, output = self._checker.check(file_path) | |
43 | |
44 self.assertTrue(expected_chunk in output, | |
45 msg="%s\n\nExpected chunk: \n%s\n\nOutput:\n%s\n" % ( | |
46 "getInstance", expected_chunk, output)) | |
47 | |
48 | |
49 if __name__ == "__main__": | |
50 unittest.main() | |
OLD | NEW |