aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Chren (rindeal) <dev.rindeal@gmail.com>2017-06-03 21:33:20 +0200
committerJan Chren (rindeal) <dev.rindeal@gmail.com>2017-06-07 23:51:17 +0200
commit61ac9a5348c21443c3e6de204f85ce3fb138cb92 (patch)
tree259d6bd5bc57ae62cfb3f64ad1139a38b38193da
parentbd52a5c5aa5df4653508003d759399fb24307d54 (diff)
downloadmeson-61ac9a5348c21443c3e6de204f85ce3fb138cb92.zip
meson-61ac9a5348c21443c3e6de204f85ce3fb138cb92.tar.gz
meson-61ac9a5348c21443c3e6de204f85ce3fb138cb92.tar.bz2
add tests for `capture` in `configure_file()`
-rw-r--r--test cases/common/16 configure file/basename.py28
-rw-r--r--test cases/common/16 configure file/file_contains.py22
-rw-r--r--test cases/common/16 configure file/meson.build17
-rw-r--r--test cases/common/16 configure file/touch.py16
4 files changed, 83 insertions, 0 deletions
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 0000000..d2c8662
--- /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 0000000..25634f5
--- /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 0d0e461..9dc5fb5 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 0000000..b48f481
--- /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())