| 1 |
project('run command', version : run_command('get-version.py', check : true).stdout().strip(), meson_version: '>=0.1.0') |
| 2 |
|
| 3 |
if build_machine.system() == 'windows' |
| 4 |
c = run_command('cmd', '/c', 'echo', 'hello', check: false) |
| 5 |
else |
| 6 |
c = run_command('echo', 'hello', check: false) |
| 7 |
endif |
| 8 |
|
| 9 |
correct = 'hello' |
| 10 |
|
| 11 |
if c.returncode() != 0 |
| 12 |
error('Executing echo failed.') |
| 13 |
endif |
| 14 |
|
| 15 |
result = c.stdout().strip() |
| 16 |
|
| 17 |
if result != correct |
| 18 |
error('Getting stdout failed.') |
| 19 |
endif |
| 20 |
|
| 21 |
if c.stderr() != '' |
| 22 |
error('Extra text in stderr.') |
| 23 |
endif |
| 24 |
|
| 25 |
# Now the same with a script. |
| 26 |
|
| 27 |
if build_machine.system() == 'windows' |
| 28 |
cs = run_command('scripts/hello.bat', check: false) |
| 29 |
else |
| 30 |
cs = run_command('scripts/hello.sh', check: false) |
| 31 |
endif |
| 32 |
|
| 33 |
if cs.returncode() != 0 |
| 34 |
error('Executing script failed.') |
| 35 |
endif |
| 36 |
|
| 37 |
if cs.stdout().strip() != correct |
| 38 |
error('Getting stdout failed (script).') |
| 39 |
endif |
| 40 |
|
| 41 |
if cs.stderr() != '' |
| 42 |
error('Extra text in stderr (script).') |
| 43 |
endif |
| 44 |
|
| 45 |
# We should be able to have files() in argument |
| 46 |
f = files('meson.build') |
| 47 |
|
| 48 |
if build_machine.system() == 'windows' |
| 49 |
c = run_command('cmd', '/c', 'echo', f, check: false) |
| 50 |
else |
| 51 |
c = run_command('echo', f, check: false) |
| 52 |
endif |
| 53 |
|
| 54 |
if c.returncode() != 0 |
| 55 |
error('Using files() in argument failed.') |
| 56 |
endif |
| 57 |
|
| 58 |
py3 = import('python3').find_python() |
| 59 |
|
| 60 |
# No runtime output expected, not captured |
| 61 |
ret = run_command( |
| 62 |
py3, |
| 63 |
'-c', |
| 64 |
'import sys; print("stdout|capture:false,console:false"); print("stderr|capture:false,console:false", file=sys.stderr)', |
| 65 |
check: true, |
| 66 |
capture: false, |
| 67 |
console: false, |
| 68 |
) |
| 69 |
assert(ret.returncode() == 0, 'failed to run python3: ' + ret.stderr()) |
| 70 |
assert(ret.stdout() == '', 'stdout is "@0@" instead of empty'.format(ret.stdout())) |
| 71 |
assert(ret.stderr() == '', 'stderr is "@0@" instead of empty'.format(ret.stderr())) |
| 72 |
|
| 73 |
# Expect runtime output, not captured |
| 74 |
ret = run_command( |
| 75 |
py3, |
| 76 |
'-c', |
| 77 |
'import sys; print("stdout|capture:false,console:true"); print("stderr|capture:false,console:true", file=sys.stderr)', |
| 78 |
check: true, |
| 79 |
capture: false, |
| 80 |
console: true, |
| 81 |
) |
| 82 |
assert(ret.returncode() == 0, 'failed to run python3: ' + ret.stderr()) |
| 83 |
assert(ret.stdout() == '', 'stdout is "@0@" instead of empty'.format(ret.stdout())) |
| 84 |
assert(ret.stderr() == '', 'stderr is "@0@" instead of empty'.format(ret.stderr())) |
| 85 |
|
| 86 |
# No runtime output expected, but captured |
| 87 |
ret = run_command( |
| 88 |
py3, |
| 89 |
'-c', |
| 90 |
'import sys; print("stdout|capture:true,console:false"); print("stderr|capture:true,console:false", file=sys.stderr)', |
| 91 |
check: true, |
| 92 |
capture: true, |
| 93 |
console: false, |
| 94 |
) |
| 95 |
assert(ret.returncode() == 0, 'failed to run python3: ' + ret.stderr()) |
| 96 |
assert(ret.stdout() == 'stdout|capture:true,console:false\n', 'failed to capture stdout:' + ret.stdout()) |
| 97 |
assert(ret.stderr() == 'stderr|capture:true,console:false\n', 'failed to capture stderr:' + ret.stderr()) |
| 98 |
|
| 99 |
# Expect runtime output, and captured |
| 100 |
ret = run_command( |
| 101 |
py3, |
| 102 |
'-c', |
| 103 |
'import sys; print("stdout|capture:true,console:true"); print("stderr|capture:true,console:true", file=sys.stderr)', |
| 104 |
check: true, |
| 105 |
capture: true, |
| 106 |
console: true, |
| 107 |
) |
| 108 |
assert(ret.returncode() == 0, 'failed to run python3: ' + ret.stderr()) |
| 109 |
assert(ret.stdout() == 'stdout|capture:true,console:true\n', 'failed to capture stdout:' + ret.stdout()) |
| 110 |
assert(ret.stderr() == 'stderr|capture:true,console:true\n', 'failed to capture stderr:' + ret.stderr()) |
| 111 |
|
| 112 |
c_env = environment() |
| 113 |
c_env.append('CUSTOM_ENV_VAR', 'FOOBAR') |
| 114 |
ret = run_command(py3, '-c', 'import os; print(os.environ.get("CUSTOM_ENV_VAR"))', env: c_env, check: false) |
| 115 |
assert(ret.returncode() == 0, 'failed to run python3: ' + ret.stderr()) |
| 116 |
assert(ret.stdout() == 'FOOBAR\n', 'stdout is "@0@" instead of FOOBAR'.format(ret.stdout())) |
| 117 |
|
| 118 |
dd = find_program('dd', required : false) |
| 119 |
if dd.found() |
| 120 |
ret = run_command(dd, 'if=/dev/urandom', 'bs=10', 'count=1', 'of=/dev/null', check: false, capture: false) |
| 121 |
assert(ret.returncode() == 0, 'failed to run dd: ' + ret.stderr()) |
| 122 |
assert(ret.stdout() == '', 'stdout is "@0@" instead of empty'.format(ret.stdout())) |
| 123 |
endif |
| 124 |
|
| 125 |
env = environment() |
| 126 |
env.append('MY_PATH', '1') |
| 127 |
env.append('MY_PATH', '2') |
| 128 |
env.prepend('MY_PATH', '0') |
| 129 |
run_command('check-env.py', env: env, check: true) |