3 # Copyright 2007 The Closure Linter Authors. All Rights Reserved.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS-IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 """Full regression-type (Medium) tests for gjslint.
19 Tests every error that can be thrown by gjslint. Based heavily on
20 devtools/javascript/gpylint/full_test.py
23 __author__ = ('robbyw@google.com (Robert Walker)',
24 'ajp@google.com (Andy Perelson)')
31 import gflags as flags
32 import unittest as googletest
34 from closure_linter import checker
35 from closure_linter import errors
36 from closure_linter import error_check
37 from closure_linter.common import filetestcase
39 _RESOURCE_PREFIX = 'closure_linter/testdata'
41 flags.FLAGS.strict = True
42 flags.FLAGS.custom_jsdoc_tags = ('customtag', 'requires')
43 flags.FLAGS.closurized_namespaces = ('goog', 'dummy')
44 flags.FLAGS.limited_doc_files = ('externs.js', 'dummy.js',
45 'limited_doc_checks.js')
46 flags.FLAGS.jslint_error = error_check.Rule.ALL
48 # List of files under testdata to test.
49 # We need to list files explicitly since pyglib can't list directories.
50 # TODO(user): Figure out how to list the directory.
58 'html_parse_error.html',
62 'limited_doc_checks.js',
68 'require_all_caps.js',
71 'require_function.js',
72 'require_function_missing.js',
73 'require_function_through_both.js',
74 'require_function_through_namespace.js',
75 'require_interface.js',
76 'require_interface_base.js',
77 'require_lower_case.js',
80 'require_provide_blank.js',
81 'require_provide_ok.js',
82 'require_provide_missing.js',
87 'unused_private_members.js',
92 class GJsLintTestSuite(unittest.TestSuite):
93 """Test suite to run a GJsLintTest for each of several files.
95 If sys.argv[1:] is non-empty, it is interpreted as a list of filenames in
96 testdata to test. Otherwise, _TEST_FILES is used.
99 def __init__(self, tests=()):
100 unittest.TestSuite.__init__(self, tests)
102 argv = sys.argv and sys.argv[1:] or []
106 test_files = _TEST_FILES
107 for test_file in test_files:
108 resource_path = os.path.join(_RESOURCE_PREFIX, test_file)
109 self.addTest(filetestcase.AnnotatedFileTestCase(resource_path,
110 checker.GJsLintRunner(), errors.ByName))
112 if __name__ == '__main__':
113 # Don't let main parse args; it happens in the TestSuite.
114 googletest.main(argv=sys.argv[0:1], defaultTest='GJsLintTestSuite')