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 argparse | |
Dan Beam
2014/07/29 21:50:45
don't need ^
Vitaly Pavlenko
2014/07/29 23:24:25
Done.
| |
7 import unittest | |
8 | |
9 from checker import Checker, FileCache | |
10 | |
11 | |
12 class CodingConventionTest(unittest.TestCase): | |
13 def __init__(self, *args, **kwargs): | |
14 unittest.TestCase.__init__(self, *args, **kwargs) | |
15 self.maxDiff = None | |
16 | |
17 def setUp(self): | |
18 self._checker = Checker(verbose=False, fatal_log_on_error=False) | |
19 | |
20 def testGetInstance(self): | |
21 test_name = "getInstance" | |
22 file_content = """ | |
23 var cr = { | |
24 /** @param {!Function} ctor */ | |
25 addSingletonGetter: function(ctor) { | |
26 ctor.getInstance = function() { | |
27 return ctor.instance_ || (ctor.instance_ = new ctor()); | |
28 }; | |
29 } | |
30 }; | |
31 | |
32 /** @constructor */ | |
33 function Class() { | |
34 /** @param {number} num */ | |
35 this.needsNumber = function(num) {}; | |
36 } | |
37 | |
38 cr.addSingletonGetter(Class); | |
39 Class.getInstance().needsNumber("wrong type"); | |
40 """ | |
41 expected_chunk = "WARNING - actual parameter 1 of Class.needsNumber does not match formal parameter" | |
42 | |
43 file_path = "/script.js" | |
44 FileCache._cache[file_path] = file_content | |
45 _, output = self._checker.check(file_path) | |
46 | |
47 self.assertTrue(expected_chunk in output, | |
48 msg="%s\n\nExpected chunk: \n%s\n\nOutput:\n%s\n" % ( | |
49 test_name, expected_chunk, output)) | |
50 | |
51 | |
52 if __name__ == "__main__": | |
53 parser = argparse.ArgumentParser() | |
54 parser.add_argument("-v", "--verbose", action="store_true", | |
55 help="Show more information as this script runs") | |
56 opts = parser.parse_args() | |
Dan Beam
2014/07/29 21:50:46
^ unused
Vitaly Pavlenko
2014/07/29 23:24:25
Done.
| |
57 | |
58 unittest.main() | |
OLD | NEW |