Index: third_party/closure_compiler/coding_conventions_test.py |
diff --git a/third_party/closure_compiler/coding_conventions_test.py b/third_party/closure_compiler/coding_conventions_test.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..0677fca864f75cfdae191e40f4f26e74be420631 |
--- /dev/null |
+++ b/third_party/closure_compiler/coding_conventions_test.py |
@@ -0,0 +1,74 @@ |
+#!/usr/bin/env python |
+# Copyright 2014 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import argparse |
+import os |
+import tempfile |
+import unittest |
+ |
+from checker import Checker |
+ |
+ |
+def rel_to_abs(rel_path): |
Dan Beam
2014/07/29 19:17:16
unused
Vitaly Pavlenko
2014/07/29 20:26:18
Done.
|
+ script_path = os.path.dirname(os.path.abspath(__file__)) |
+ return os.path.join(script_path, rel_path) |
+ |
+ |
+class CodingConventionTest(unittest.TestCase): |
+ def __init__(self, *args, **kwargs): |
+ unittest.TestCase.__init__(self, *args, **kwargs) |
+ self.maxDiff = None |
+ |
+ def setUp(self): |
+ self._checker = Checker(verbose=False, return_output=True) |
+ |
+ 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.
|
+ test_name = config["name"] |
+ file_content = config["file"] |
+ expected_output = config["expected_output"] |
+ |
+ temp_path = tempfile.mktemp() |
+ with open(temp_path, "w") as temp_file: |
+ 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.
|
+ output = self._checker.check(temp_path) |
+ os.remove(temp_path) |
+ |
+ self.assertTrue(expected_output in output, |
+ msg="{}\n\nExpected line: \n{}\n\nOutput:\n{}\n".format( |
+ test_name, expected_output, output)) |
Dan Beam
2014/07/29 19:17:16
"{}".format() -> "%s" % ()
Vitaly Pavlenko
2014/07/29 20:26:19
Done.
|
+ |
+ def testGetInstance(self): |
+ self._runCheckerTest({ |
+ "name": "getInstance", |
+ "file": """ |
+var cr = { |
+ /** @param {!Function} ctor */ |
+ addSingletonGetter: function(ctor) { |
+ ctor.getInstance = function() { |
+ return ctor.instance_ || (ctor.instance_ = new ctor()); |
+ }; |
+ } |
+}; |
+ |
+/** @constructor */ |
+function Class() { |
+ /** @param {number} num */ |
+ this.needsNumber = function(num) {}; |
+} |
+ |
+cr.addSingletonGetter(Class); |
+Class.getInstance().needsNumber("wrong type"); |
+""", |
+ "expected_output": "WARNING - actual parameter 1 of Class.needsNumber does not match formal parameter", |
+ }) |
+ |
+ |
+if __name__ == "__main__": |
+ parser = argparse.ArgumentParser() |
+ parser.add_argument("-v", "--verbose", action="store_true", |
+ help="Show more information as this script runs") |
+ opts = parser.parse_args() |
+ |
+ unittest.main() |