/
plz_e2e_test.build_defs
55 lines (52 loc) · 2.69 KB
/
plz_e2e_test.build_defs
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
# Rules for end-to-end tests on Please itself.
def plz_e2e_test(name:str, cmd:str, pre_cmd:str=None, expected_output:str=None,
expected_failure:bool=False, expect_output_contains:str=None,
expect_output_doesnt_contain:str=None, deps:list=None, data:list=[],
labels:list=None, sandbox:bool=None, completion:bool=False,
expect_file_exists:str=None, expect_file_doesnt_exist:str=None):
# Please isn't really designed to work this way (running a test against the entire source repo)
# but we can make it do it and it's a convenient way of testing the tool itself.
def _e2e_test_cmd(cmd):
profile_flag = '--profile ci' if CONFIG.get('CI') else ''
if package_name().startswith('test/parse'):
profile_flag += ' -o parse.buildfilename:BUILD,BUILD.plz,BUILD.test '
cmd = cmd.replace('plz ', f'$(location //src:please) --nolock -o cache.rpcurl:"" {profile_flag} -o cache.dirclean:false --log_file plz-out/log/{name}.log ')
if expected_failure:
test_cmd = '%s 2>&1 | tee output; if [ $? -eq 0 ]; then exit 1; fi; ' % cmd
else:
test_cmd = '%s 2>&1 | tee output && ' % cmd
if expected_output and expect_output_contains:
raise ValueError('Can only pass one of expected_output and expect_output_contains')
elif expected_output:
test_cmd += 'diff -au output $(location %s)' % expected_output
elif expect_output_contains:
test_cmd += 'if ! grep -q "%s" output; then cat output; exit 1; fi' % expect_output_contains
elif expect_output_doesnt_contain:
test_cmd += 'if grep -q "%s" output; then cat output; exit 1; fi' % expect_output_doesnt_contain
elif expect_file_exists:
test_cmd += 'if [ ! -f %s ]; then cat output; exit 1; fi' % expect_file_exists
elif expect_file_doesnt_exist:
test_cmd += 'if [ -f %s ]; then cat output; exit 1; fi' % expect_file_doesnt_exist
else:
test_cmd += 'true'
if completion:
test_cmd = "export GO_FLAGS_COMPLETION=1; " + test_cmd
if pre_cmd:
test_cmd = pre_cmd + ' && ' + test_cmd
return test_cmd
if expected_output:
data += [expected_output]
gentest(
name = name,
test_cmd = {
'opt': _e2e_test_cmd(cmd),
'dbg': _e2e_test_cmd(cmd.replace('plz ', 'plz -c dbg ')),
'cover': _e2e_test_cmd(cmd.replace('plz ', 'plz -c cover ')),
},
data = data + ['//src:please'],
deps = deps,
labels = ['e2e'] + (labels or []),
no_test_output = True,
sandbox = False,
local = True,
)