github.com/sercand/please@v13.4.0+incompatible/build_defs/plz_e2e_test.build_defs (about) 1 # Rules for end-to-end tests on Please itself. 2 3 def plz_e2e_test(name, cmd, pre_cmd=None, expected_output=None, expected_failure=False, 4 expect_output_contains=None, expect_output_doesnt_contain=None, 5 deps=None, data=[], labels=None, sandbox=None, 6 expect_file_exists=None, expect_file_doesnt_exist=None): 7 # Please isn't really designed to work this way (running a test against the entire source repo) 8 # but we can make it do it and it's a convenient way of testing the tool itself. 9 10 def _e2e_test_cmd(cmd): 11 profile_flag = '--profile ci -o buildconfig.ci:true' if CONFIG.get('CI') else '' 12 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 ') 13 if expected_failure: 14 test_cmd = '%s 2>&1 | tee output; if [ $? -eq 0 ]; then exit 1; fi; ' % cmd 15 else: 16 test_cmd = '%s 2>&1 | tee output && ' % cmd 17 if expected_output and expect_output_contains: 18 raise ValueError('Can only pass one of expected_output and expect_output_contains') 19 elif expected_output: 20 test_cmd += 'diff -au output $(location %s)' % expected_output 21 elif expect_output_contains: 22 test_cmd += 'if ! grep -q "%s" output; then cat output; exit 1; fi' % expect_output_contains 23 elif expect_output_doesnt_contain: 24 test_cmd += 'if grep -q "%s" output; then cat output; exit 1; fi' % expect_output_doesnt_contain 25 elif expect_file_exists: 26 test_cmd += 'if [ ! -f %s ]; then cat output; exit 1; fi' % expect_file_exists 27 elif expect_file_doesnt_exist: 28 test_cmd += 'if [ -f %s ]; then cat output; exit 1; fi' % expect_file_doesnt_exist 29 else: 30 test_cmd += 'true' 31 if pre_cmd: 32 test_cmd = pre_cmd + ' && ' + test_cmd 33 return 'set -o pipefail; ' + test_cmd 34 35 if expected_output: 36 data += [expected_output] 37 gentest( 38 name = name, 39 test_cmd = { 40 'opt': _e2e_test_cmd(cmd), 41 'dbg': _e2e_test_cmd(cmd.replace('plz ', 'plz -c dbg ')), 42 'cover': _e2e_test_cmd(cmd.replace('plz ', 'plz -c cover ')), 43 }, 44 data = data + ['//src:please'], 45 deps = deps, 46 labels = ['e2e'] + (labels or []), 47 no_test_output = True, 48 sandbox = False, 49 )