OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 from ast import literal_eval | 6 from ast import literal_eval |
7 import os | 7 import os |
8 import tempfile | 8 import tempfile |
9 import unittest | 9 import unittest |
10 | 10 |
11 from compile import Checker | 11 from compile import Checker |
12 from processor import FileCache, Processor | 12 from processor import FileCache, Processor |
13 | 13 |
14 | 14 |
15 _SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 15 _SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
16 _SRC_DIR = os.path.join(_SCRIPT_DIR, os.pardir, os.pardir) | 16 _SRC_DIR = os.path.join(_SCRIPT_DIR, os.pardir, os.pardir) |
17 _RESOURCES_DIR = os.path.join(_SRC_DIR, "ui", "webui", "resources", "js") | 17 _RESOURCES_DIR = os.path.join(_SRC_DIR, "ui", "webui", "resources", "js") |
18 _ASSERT_JS = os.path.join(_RESOURCES_DIR, "assert.js") | 18 _ASSERT_JS = os.path.join(_RESOURCES_DIR, "assert.js") |
19 _CR_JS = os.path.join(_RESOURCES_DIR, "cr.js") | 19 _CR_JS = os.path.join(_RESOURCES_DIR, "cr.js") |
20 _CR_UI_JS = os.path.join(_RESOURCES_DIR, "cr", "ui.js") | 20 _CR_UI_JS = os.path.join(_RESOURCES_DIR, "cr", "ui.js") |
21 _PROMISE_RESOLVER_JS = os.path.join(_RESOURCES_DIR, "promise_resolver.js") | 21 _PROMISE_RESOLVER_JS = os.path.join(_RESOURCES_DIR, "promise_resolver.js") |
22 _POLYMER_EXTERNS = os.path.join(_SCRIPT_DIR, "externs", "polymer-1.0.js") | 22 _POLYMER_EXTERNS = os.path.join(_SCRIPT_DIR, "externs", "polymer-1.0.js") |
23 _CHROME_SEND_EXTERNS = os.path.join(_SRC_DIR, "third_party", "closure_compiler", | 23 _CHROME_SEND_EXTERNS = os.path.join(_SRC_DIR, "third_party", "closure_compiler", |
24 "externs", "chrome_send.js") | 24 "externs", "chrome_send.js") |
25 _CLOSURE_ARGS_GYPI = os.path.join(_SCRIPT_DIR, "closure_args.gypi") | 25 _CLOSURE_ARGS_GYPI = os.path.join(_SCRIPT_DIR, "closure_args.gypi") |
26 _GYPI_DICT = literal_eval(open(_CLOSURE_ARGS_GYPI).read()) | 26 _GYPI_DICT = literal_eval(open(_CLOSURE_ARGS_GYPI).read()) |
27 _COMMON_CLOSURE_ARGS = _GYPI_DICT["closure_args"] + \ | 27 _COMMON_CLOSURE_ARGS = _GYPI_DICT["default_closure_args"] + \ |
28 _GYPI_DICT["default_disabled_closure_args"] | 28 _GYPI_DICT["default_disabled_closure_args"] |
29 | 29 _RUNNER_ARGS = ["enable-chrome-pass"] |
30 | 30 |
31 class CompilerTest(unittest.TestCase): | 31 class CompilerTest(unittest.TestCase): |
32 _ASSERT_DEFINITION = Processor(_ASSERT_JS).contents | 32 _ASSERT_DEFINITION = Processor(_ASSERT_JS).contents |
33 _PROMISE_RESOLVER_DEFINITION = (_ASSERT_DEFINITION + | 33 _PROMISE_RESOLVER_DEFINITION = (_ASSERT_DEFINITION + |
34 Processor(_PROMISE_RESOLVER_JS).contents) | 34 Processor(_PROMISE_RESOLVER_JS).contents) |
35 _CR_DEFINE_DEFINITION = (_PROMISE_RESOLVER_DEFINITION + | 35 _CR_DEFINE_DEFINITION = (_PROMISE_RESOLVER_DEFINITION + |
36 Processor(_CR_JS).contents) | 36 Processor(_CR_JS).contents) |
37 _CR_UI_DECORATE_DEFINITION = Processor(_CR_UI_JS).contents | 37 _CR_UI_DECORATE_DEFINITION = Processor(_CR_UI_JS).contents |
38 | 38 |
39 def setUp(self): | 39 def setUp(self): |
40 self._checker = Checker() | 40 self._checker = Checker() |
41 self._tmp_files = [] | 41 self._tmp_files = [] |
42 | 42 |
43 def tearDown(self): | 43 def tearDown(self): |
44 for file in self._tmp_files: | 44 for file in self._tmp_files: |
45 if os.path.exists(file): | 45 if os.path.exists(file): |
46 os.remove(file) | 46 os.remove(file) |
47 | 47 |
48 def _runChecker(self, source_code, closure_args=None): | 48 def _runChecker(self, source_code, closure_args=None): |
49 file_path = "/script.js" | 49 file_path = "/script.js" |
50 FileCache._cache[file_path] = source_code | 50 FileCache._cache[file_path] = source_code |
51 out_file, out_map = self._createOutFiles() | 51 out_file, out_map = self._createOutFiles() |
52 args = _COMMON_CLOSURE_ARGS + (closure_args or []) | 52 args = _COMMON_CLOSURE_ARGS + (closure_args or []) |
53 | 53 |
54 externs = [_POLYMER_EXTERNS, _CHROME_SEND_EXTERNS] | 54 externs = [_POLYMER_EXTERNS, _CHROME_SEND_EXTERNS] |
55 found_errors, stderr = self._checker.check(file_path, | 55 found_errors, stderr = self._checker.check(file_path, |
56 externs=externs, | 56 externs=externs, |
57 out_file=out_file, | 57 out_file=out_file, |
| 58 runner_args=_RUNNER_ARGS, |
58 closure_args=args) | 59 closure_args=args) |
59 return found_errors, stderr, out_file, out_map | 60 return found_errors, stderr, out_file, out_map |
60 | 61 |
61 def _runCheckerTestExpectError(self, source_code, expected_error, | 62 def _runCheckerTestExpectError(self, source_code, expected_error, |
62 closure_args=None): | 63 closure_args=None): |
63 _, stderr, out_file, out_map = self._runChecker(source_code, closure_args) | 64 _, stderr, out_file, out_map = self._runChecker(source_code, closure_args) |
64 | 65 |
65 self.assertTrue(expected_error in stderr, | 66 self.assertTrue(expected_error in stderr, |
66 msg="Expected chunk: \n%s\n\nOutput:\n%s\n" % ( | 67 msg="Expected chunk: \n%s\n\nOutput:\n%s\n" % ( |
67 expected_error, stderr)) | 68 expected_error, stderr)) |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 """ | 367 """ |
367 args = ['warning_level=VERBOSE'] | 368 args = ['warning_level=VERBOSE'] |
368 self._runCheckerTestExpectError(template % '', 'Missing return', | 369 self._runCheckerTestExpectError(template % '', 'Missing return', |
369 closure_args=args) | 370 closure_args=args) |
370 self._runCheckerTestExpectSuccess(template % 'assertNotReached();', | 371 self._runCheckerTestExpectSuccess(template % 'assertNotReached();', |
371 closure_args=args) | 372 closure_args=args) |
372 | 373 |
373 | 374 |
374 if __name__ == "__main__": | 375 if __name__ == "__main__": |
375 unittest.main() | 376 unittest.main() |
OLD | NEW |