forked from istio/istio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_bazel_version_test.py
71 lines (50 loc) · 1.61 KB
/
check_bazel_version_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# stub out the native object
class Native(object):
def __init__(self, v):
self.bazel_version = v
class Output(object):
def __init__(self):
self.output = ""
class TestCase(object):
def __init__(self, min_ver, max_ver, ver, output):
self.min_ver = min_ver
self.max_ver = max_ver
self.ver = ver
self.output = output
def __repr__(self):
return self.__dict__.__repr__()
def test_check_version():
global native
global fail
ok = True
import shutil
import os
shutil.copyfile("check_bazel_version.bzl", "check_bazel_version.py")
import check_bazel_version as cv
ts = [TestCase("0.5.3", "0.5.4", "0.6.0", "too new"),
TestCase("0.5.3", "0.5.4", "0.5.1", "too old"),
TestCase("0.5.3", "0.5.4", "0.11.0", "too new"),
TestCase("0.5.3", "0.5.4", "0.5.3", ""),
TestCase("0.5.3", "0.5.4", "0.5.4", "")]
for tc in ts:
cv.native = Native(tc.ver)
op = Output()
def _fail(msg):
op.output = msg
cv.fail = _fail
cv.check_bazel_version(tc.min_ver, tc.max_ver)
if tc.output == "":
if op.output != "":
print "Test Failed", tc, "Want [ ", tc.output, "] Got [", op.output, "]"
ok = False
if tc.output in op.output:
continue
print "Test Failed", tc, "Want [ ", tc.output, "] Got [", op.output, "]"
ok = False
os.remove("check_bazel_version.py")
if ok:
return 0
return -1
if __name__ == "__main__":
import sys
sys.exit(test_check_version())