From 5482a239363c21162526b6f2787b686678ba8bd6 Mon Sep 17 00:00:00 2001 From: Nicolas Schneider Date: Sat, 12 Mar 2016 17:41:42 +0100 Subject: [PATCH] enhance test framework to read meson arguments from a file per test A 'test_args.txt' file in the same directory as the test case will be parsed by the test framework and the content will be passed as arguments to meson during configuration. The arguments are put before any 'extra_args' to make them overwritable from the command line. --- run_tests.py | 18 +++++++++++++++++- .../109 testframework options/meson.build | 5 +++++ .../meson_options.txt | 3 +++ .../109 testframework options/test_args.txt | 4 ++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 test cases/common/109 testframework options/meson.build create mode 100644 test cases/common/109 testframework options/meson_options.txt create mode 100644 test cases/common/109 testframework options/test_args.txt diff --git a/run_tests.py b/run_tests.py index 7e799cb70..cbc4e3d19 100755 --- a/run_tests.py +++ b/run_tests.py @@ -17,11 +17,13 @@ from glob import glob import os, subprocess, shutil, sys, signal from io import StringIO +from ast import literal_eval import sys from mesonbuild import environment from mesonbuild import mesonlib from mesonbuild import mlog from mesonbuild import mesonmain +from mesonbuild.mesonlib import stringlistify from mesonbuild.scripts import meson_test, meson_benchmark import argparse import xml.etree.ElementTree as ET @@ -181,6 +183,19 @@ def run_test_inprocess(testdir): os.chdir(old_cwd) return (max(returncode_test, returncode_benchmark), mystdout.getvalue(), mystderr.getvalue()) +def parse_test_args(testdir): + args = [] + try: + with open(os.path.join(testdir, 'test_args.txt'), 'r') as f: + content = f.read() + try: + args = literal_eval(content) + except Exception: + raise Exception('Malformed test_args file.') + args = stringlistify(args) + except FileNotFoundError: + pass + return args def run_test(testdir, extra_args, should_succeed): global compile_commands @@ -190,9 +205,10 @@ def run_test(testdir, extra_args, should_succeed): os.mkdir(test_build_dir) os.mkdir(install_dir) print('Running test: ' + testdir) + test_args = parse_test_args(testdir) gen_start = time.time() gen_command = [meson_command, '--prefix', '/usr', '--libdir', 'lib', testdir, test_build_dir]\ - + unity_flags + backend_flags + extra_args + + unity_flags + backend_flags + test_args + extra_args (returncode, stdo, stde) = run_configure_inprocess(gen_command) gen_time = time.time() - gen_start if not should_succeed: diff --git a/test cases/common/109 testframework options/meson.build b/test cases/common/109 testframework options/meson.build new file mode 100644 index 000000000..277373044 --- /dev/null +++ b/test cases/common/109 testframework options/meson.build @@ -0,0 +1,5 @@ +project('options', 'c') + +assert(get_option('testoption') == 'A string with spaces', 'Incorrect value for testoption option.') +assert(get_option('other_one') == true, 'Incorrect value for other_one option.') +assert(get_option('combo_opt') == 'one', 'Incorrect value for combo_opt option.') diff --git a/test cases/common/109 testframework options/meson_options.txt b/test cases/common/109 testframework options/meson_options.txt new file mode 100644 index 000000000..653dd75f9 --- /dev/null +++ b/test cases/common/109 testframework options/meson_options.txt @@ -0,0 +1,3 @@ +option('testoption', type : 'string', value : 'optval', description : 'An option to do something') +option('other_one', type : 'boolean', value : false) +option('combo_opt', type : 'combo', choices : ['one', 'two', 'combo'], value : 'combo') diff --git a/test cases/common/109 testframework options/test_args.txt b/test cases/common/109 testframework options/test_args.txt new file mode 100644 index 000000000..a667e3a58 --- /dev/null +++ b/test cases/common/109 testframework options/test_args.txt @@ -0,0 +1,4 @@ +# This file is not read by meson itself, but by the test framework. +# It is not possible to pass arguments to meson from a file. +['--werror', '-D', 'testoption=A string with spaces', '-D', 'other_one=true', \ + '-D', 'combo_opt=one']