Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: third_party/closure_compiler/coding_conventions_test.py

Issue 421253006: Add ChromeCodingConvention.java to Closure Compiler to preserve getInstance() type (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@A_typechecking_about
Patch Set: Fix comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
7 import os
8 import tempfile
9 import unittest
10
11 from checker import Checker
12
13
14 def rel_to_abs(rel_path):
Dan Beam 2014/07/29 19:17:16 unused
Vitaly Pavlenko 2014/07/29 20:26:18 Done.
15 script_path = os.path.dirname(os.path.abspath(__file__))
16 return os.path.join(script_path, rel_path)
17
18
19 class CodingConventionTest(unittest.TestCase):
20 def __init__(self, *args, **kwargs):
21 unittest.TestCase.__init__(self, *args, **kwargs)
22 self.maxDiff = None
23
24 def setUp(self):
25 self._checker = Checker(verbose=False, return_output=True)
26
27 def _runCheckerTest(self, config):
Dan Beam 2014/07/29 19:17:17 only used once, adds more code
Vitaly Pavlenko 2014/07/29 20:26:19 Done.
28 test_name = config["name"]
29 file_content = config["file"]
30 expected_output = config["expected_output"]
31
32 temp_path = tempfile.mktemp()
33 with open(temp_path, "w") as temp_file:
34 print >> temp_file, file_content
Dan Beam 2014/07/29 19:17:16 just sutff the file into FileCache._cache instead
Vitaly Pavlenko 2014/07/29 20:26:18 Done.
35 output = self._checker.check(temp_path)
36 os.remove(temp_path)
37
38 self.assertTrue(expected_output in output,
39 msg="{}\n\nExpected line: \n{}\n\nOutput:\n{}\n".format(
40 test_name, expected_output, output))
Dan Beam 2014/07/29 19:17:16 "{}".format() -> "%s" % ()
Vitaly Pavlenko 2014/07/29 20:26:19 Done.
41
42 def testGetInstance(self):
43 self._runCheckerTest({
44 "name": "getInstance",
45 "file": """
46 var cr = {
47 /** @param {!Function} ctor */
48 addSingletonGetter: function(ctor) {
49 ctor.getInstance = function() {
50 return ctor.instance_ || (ctor.instance_ = new ctor());
51 };
52 }
53 };
54
55 /** @constructor */
56 function Class() {
57 /** @param {number} num */
58 this.needsNumber = function(num) {};
59 }
60
61 cr.addSingletonGetter(Class);
62 Class.getInstance().needsNumber("wrong type");
63 """,
64 "expected_output": "WARNING - actual parameter 1 of Class.needsNumber does not match formal parameter",
65 })
66
67
68 if __name__ == "__main__":
69 parser = argparse.ArgumentParser()
70 parser.add_argument("-v", "--verbose", action="store_true",
71 help="Show more information as this script runs")
72 opts = parser.parse_args()
73
74 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698