OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 # Copyright 2013 The Closure Linter Authors. All Rights Reserved. | |
3 # | |
4 # Licensed under the Apache License, Version 2.0 (the "License"); | |
5 # you may not use this file except in compliance with the License. | |
6 # You may obtain a copy of the License at | |
7 # | |
8 # http://www.apache.org/licenses/LICENSE-2.0 | |
9 # | |
10 # Unless required by applicable law or agreed to in writing, software | |
11 # distributed under the License is distributed on an "AS-IS" BASIS, | |
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 # See the License for the specific language governing permissions and | |
14 # limitations under the License. | |
15 | |
16 """Tests for gjslint --strict. | |
17 | |
18 Tests errors that can be thrown by gjslint when in strict mode. | |
19 """ | |
20 | |
21 | |
22 | |
23 import unittest | |
24 | |
25 import gflags as flags | |
26 import unittest as googletest | |
27 | |
28 from closure_linter import errors | |
29 from closure_linter import runner | |
30 from closure_linter.common import erroraccumulator | |
31 | |
32 flags.FLAGS.strict = True | |
33 | |
34 | |
35 class StrictTest(unittest.TestCase): | |
36 """Tests scenarios where strict generates warnings.""" | |
37 | |
38 def testUnclosedString(self): | |
39 """Tests warnings are reported when nothing is disabled. | |
40 | |
41 b/11450054. | |
42 """ | |
43 original = [ | |
44 'bug = function() {', | |
45 ' (\'foo\'\');', | |
46 '};', | |
47 '', | |
48 ] | |
49 | |
50 expected = [errors.FILE_DOES_NOT_PARSE, errors.MULTI_LINE_STRING, | |
51 errors.FILE_IN_BLOCK] | |
52 self._AssertErrors(original, expected) | |
53 | |
54 def _AssertErrors(self, original, expected_errors): | |
55 """Asserts that the error fixer corrects original to expected.""" | |
56 | |
57 # Trap gjslint's output parse it to get messages added. | |
58 error_accumulator = erroraccumulator.ErrorAccumulator() | |
59 runner.Run('testing.js', error_accumulator, source=original) | |
60 error_nums = [e.code for e in error_accumulator.GetErrors()] | |
61 | |
62 error_nums.sort() | |
63 expected_errors.sort() | |
64 self.assertListEqual(error_nums, expected_errors) | |
65 | |
66 if __name__ == '__main__': | |
67 googletest.main() | |
68 | |
OLD | NEW |