add tests for `capture` in `configure_file()`

pull/1874/head
Jan Chren (rindeal) 7 years ago
parent bd52a5c5aa
commit 61ac9a5348
  1. 28
      test cases/common/16 configure file/basename.py
  2. 22
      test cases/common/16 configure file/file_contains.py
  3. 17
      test cases/common/16 configure file/meson.build
  4. 16
      test cases/common/16 configure file/touch.py

@ -0,0 +1,28 @@
#!/usr/bin/env python3
import sys
import argparse
import os
def main():
parser = argparse.ArgumentParser()
parser.add_argument('text', nargs='*', type=str)
args = parser.parse_args()
text = args.text if isinstance(args.text, list) else [args.text]
output = ''
for t in text:
t = os.path.basename(t)
if not output:
output += t
else:
output += ' ' + t
output += '\n'
sys.stdout.write(output)
if __name__ == '__main__':
sys.exit(main())

@ -0,0 +1,22 @@
#!/usr/bin/env python3
import sys
import argparse
def main():
parser = argparse.ArgumentParser()
parser.add_argument('file', nargs=1, type=str)
parser.add_argument('text', nargs=1, type=str)
args = parser.parse_args()
text = args.text[0]
with open(args.file[0], 'r', encoding='utf-8') as f:
for line in f:
if line.strip() == text:
return 0
return 1
if __name__ == '__main__':
sys.exit(main())

@ -86,3 +86,20 @@ foreach config_template : config_templates
endforeach
test('Substituted', executable('prog4', 'prog4.c'))
# Test `capture` keyword
basename_py = find_program('basename.py')
file_contains_py = find_program('file_contains.py')
test_string = 'hello world'
test_input_file = join_paths(meson.current_build_dir(), test_string)
run_command(find_program('touch.py'), test_input_file)
configs = [
# no input
configure_file(command: [ basename_py, test_string ], capture: true, output: 'capture test 1'),
# with input
configure_file(input: test_input_file, command: [ basename_py, '@INPUT@' ], capture: true, output: 'capture test 2'),
]
foreach c : configs
test('@0@'.format(c), file_contains_py, args: [ c, test_string ])
endforeach

@ -0,0 +1,16 @@
#!/usr/bin/env python3
import sys
import argparse
from pathlib import Path
def main():
parser = argparse.ArgumentParser()
parser.add_argument('files', nargs='*', type=str)
args = parser.parse_args()
for filepath in args.files:
Path(filepath).touch()
if __name__ == '__main__':
sys.exit(main())
Loading…
Cancel
Save