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

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

Issue 1409843002: Make Closure Compiler understand assertNotReached (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
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
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 out_file, out_map = self._createOutFiles() 49 out_file, out_map = self._createOutFiles()
50 args = _COMMON_CLOSURE_ARGS + (closure_args or []) 50 args = _COMMON_CLOSURE_ARGS + (closure_args or [])
51 51
52 externs = [_POLYMER_EXTERNS, _CHROME_SEND_EXTERNS] 52 externs = [_POLYMER_EXTERNS, _CHROME_SEND_EXTERNS]
53 found_errors, stderr = self._checker.check(file_path, 53 found_errors, stderr = self._checker.check(file_path,
54 externs=externs, 54 externs=externs,
55 out_file=out_file, 55 out_file=out_file,
56 closure_args=args) 56 closure_args=args)
57 return found_errors, stderr, out_file, out_map 57 return found_errors, stderr, out_file, out_map
58 58
59 def _runCheckerTestExpectError(self, source_code, expected_error): 59 def _runCheckerTestExpectError(self, source_code, expected_error,
60 _, stderr, out_file, out_map = self._runChecker(source_code) 60 closure_args=None):
61 _, stderr, out_file, out_map = self._runChecker(source_code, closure_args)
61 62
62 self.assertTrue(expected_error in stderr, 63 self.assertTrue(expected_error in stderr,
63 msg="Expected chunk: \n%s\n\nOutput:\n%s\n" % ( 64 msg="Expected chunk: \n%s\n\nOutput:\n%s\n" % (
64 expected_error, stderr)) 65 expected_error, stderr))
65 self.assertFalse(os.path.exists(out_file)) 66 self.assertFalse(os.path.exists(out_file))
66 self.assertFalse(os.path.exists(out_map)) 67 self.assertFalse(os.path.exists(out_map))
67 68
68 def _runCheckerTestExpectSuccess(self, source_code, expected_output=None, 69 def _runCheckerTestExpectSuccess(self, source_code, expected_output=None,
69 closure_args=None): 70 closure_args=None):
70 found_errors, stderr, out_file, out_map = self._runChecker(source_code, 71 found_errors, stderr, out_file, out_map = self._runChecker(source_code,
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 336
336 def testExportPathWithTargets(self): 337 def testExportPathWithTargets(self):
337 self._runCheckerTestExpectSuccess(self._CR_DEFINE_DEFINITION + 338 self._runCheckerTestExpectSuccess(self._CR_DEFINE_DEFINITION +
338 "var path = 'a.b.c'; cr.exportPath(path, {}, {});") 339 "var path = 'a.b.c'; cr.exportPath(path, {}, {});")
339 340
340 def testExportPathNoPath(self): 341 def testExportPathNoPath(self):
341 self._runCheckerTestExpectError(self._CR_DEFINE_DEFINITION + 342 self._runCheckerTestExpectError(self._CR_DEFINE_DEFINITION +
342 "cr.exportPath();", 343 "cr.exportPath();",
343 "ERROR - cr.exportPath() should have at least 1 argument: path name") 344 "ERROR - cr.exportPath() should have at least 1 argument: path name")
344 345
346 def testMissingReturnAssertNotReached(self):
347 template = self._ASSERT_DEFINITION + """
348 /** @enum {number} */
349 var Enum = {FOO: 1, BAR: 2};
350
351 /**
352 * @param {Enum} e
353 * @return {number}
354 */
355 function enumToVal(e) {
356 switch (e) {
357 case Enum.FOO:
358 return 1;
359 case Enum.BAR:
360 return 2;
361 }
362 %s
363 }
364 """
365 args = ['warning_level=VERBOSE']
366 self._runCheckerTestExpectError(template % '', 'Missing return',
367 closure_args=args)
368 self._runCheckerTestExpectSuccess(template % 'assertNotReached();',
369 closure_args=args)
370
345 371
346 if __name__ == "__main__": 372 if __name__ == "__main__":
347 unittest.main() 373 unittest.main()
OLDNEW
« no previous file with comments | « no previous file | third_party/closure_compiler/runner/runner.jar » ('j') | ui/webui/resources/js/cr/ui/table.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698