blob: c999dfafab2865dfc078f2d61f0a2851e89d7f7e [file] [log] [blame]
ronshapiro31d711c2017-01-13 08:58:02 -08001# Copyright (C) 2017 The Dagger Authors.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import ast
16import unittest
17
18class WorkspaceVisitor(ast.NodeVisitor):
19 def __init__(self):
20 self.missing_sha1 = []
21
22 def visit_Call(self, rule):
23 if rule.func.id == 'maven_jar':
24 name = None
25 for parameter in rule.keywords:
26 if parameter.arg == 'sha1':
27 return
28 if parameter.arg == 'name':
29 name = parameter.value.s
30 self.missing_sha1.append(name)
31
32class MavenSha1Test(unittest.TestCase):
33 def test_each_maven_jar_rule_has_sha1(self):
34 with open('WORKSPACE', 'r') as workspace:
35 visitor = WorkspaceVisitor()
36 visitor.visit(ast.parse(workspace.read()))
37 if len(visitor.missing_sha1) > 0:
38 missing = ', '.join(visitor.missing_sha1)
39 self.fail('%s did not specify a sha1' % missing)
40
41if __name__ == '__main__':
42 unittest.main()