From 61ac9a5348c21443c3e6de204f85ce3fb138cb92 Mon Sep 17 00:00:00 2001 From: "Jan Chren (rindeal)" Date: Sat, 3 Jun 2017 21:33:20 +0200 Subject: [PATCH] add tests for `capture` in `configure_file()` --- .../common/16 configure file/basename.py | 28 +++++++++++++++++++ .../common/16 configure file/file_contains.py | 22 +++++++++++++++ .../common/16 configure file/meson.build | 17 +++++++++++ test cases/common/16 configure file/touch.py | 16 +++++++++++ 4 files changed, 83 insertions(+) create mode 100644 test cases/common/16 configure file/basename.py create mode 100644 test cases/common/16 configure file/file_contains.py create mode 100644 test cases/common/16 configure file/touch.py diff --git a/test cases/common/16 configure file/basename.py b/test cases/common/16 configure file/basename.py new file mode 100644 index 000000000..d2c866216 --- /dev/null +++ b/test cases/common/16 configure file/basename.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()) diff --git a/test cases/common/16 configure file/file_contains.py b/test cases/common/16 configure file/file_contains.py new file mode 100644 index 000000000..25634f534 --- /dev/null +++ b/test cases/common/16 configure file/file_contains.py @@ -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()) diff --git a/test cases/common/16 configure file/meson.build b/test cases/common/16 configure file/meson.build index 0d0e46107..9dc5fb55e 100644 --- a/test cases/common/16 configure file/meson.build +++ b/test cases/common/16 configure file/meson.build @@ -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 diff --git a/test cases/common/16 configure file/touch.py b/test cases/common/16 configure file/touch.py new file mode 100644 index 000000000..b48f48162 --- /dev/null +++ b/test cases/common/16 configure file/touch.py @@ -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())