2 # Copyright 2013 The Closure Linter Authors. All Rights Reserved.
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 """Tests for gjslint --strict.
18 Tests errors that can be thrown by gjslint when in strict mode.
25 import gflags as flags
26 import unittest as googletest
28 from closure_linter import errors
29 from closure_linter import runner
30 from closure_linter.common import erroraccumulator
32 flags.FLAGS.strict = True
35 class StrictTest(unittest.TestCase):
36 """Tests scenarios where strict generates warnings."""
38 def testUnclosedString(self):
39 """Tests warnings are reported when nothing is disabled.
50 expected = [errors.FILE_DOES_NOT_PARSE, errors.MULTI_LINE_STRING,
52 self._AssertErrors(original, expected)
54 def _AssertErrors(self, original, expected_errors):
55 """Asserts that the error fixer corrects original to expected."""
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()]
63 expected_errors.sort()
64 self.assertListEqual(error_nums, expected_errors)
66 if __name__ == '__main__':