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 | |
Dan Beam
2014/07/30 00:13:05
^ remove this __init__, maxDiff is only used in as
Vitaly Pavlenko
2014/07/30 00:21:25
Done.
| |
15 | |
16 def setUp(self): | |
17 self._checker = Checker(verbose=False) | |
18 | |
19 def testGetInstance(self): | |
20 test_name = "getInstance" | |
Dan Beam
2014/07/30 00:13:05
just inline "getInstance" instead of making |test_
Vitaly Pavlenko
2014/07/30 00:21:25
Done.
| |
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 |