diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2018-05-13 10:36:58 -0400 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek.chauhan@gmail.com> | 2018-06-06 20:02:37 +0000 |
commit | 7c4736d27f4c5d7844a44addc0305e4354440074 (patch) | |
tree | 19aa2290f1f9b40c4ef543bda84285a96d9db45c /run_unittests.py | |
parent | b38452636cc25ffd38d379645607f1563de59d80 (diff) | |
download | meson-7c4736d27f4c5d7844a44addc0305e4354440074.zip meson-7c4736d27f4c5d7844a44addc0305e4354440074.tar.gz meson-7c4736d27f4c5d7844a44addc0305e4354440074.tar.bz2 |
Convert args.projectoptions into a dict
This simplifies a lot of code, and centralize "key=value" parsing in a
single place.
Unknown command line options becomes an hard error instead of
merely printing warning message. It has been warning it would become an
hard error for a while now. This has exceptions though, any
unknown option starting with "<lang>_" or "b_" are ignored because they
depend on which languages gets added and which compiler gets selected.
Also any option for unknown subproject are ignored because they depend
on which subproject actually gets built.
Also write more command line parsing tests. "19 bad command line
options" is removed because bad cmd line option became hard error and
it's covered with new tests in "30 command line".
Diffstat (limited to 'run_unittests.py')
-rwxr-xr-x | run_unittests.py | 60 |
1 files changed, 41 insertions, 19 deletions
diff --git a/run_unittests.py b/run_unittests.py index 5d60d99..313b07c 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -2072,6 +2072,8 @@ recommended as it can lead to undefined behaviour on some platforms''') obj = mesonbuild.coredata.load(self.builddir) self.assertEqual(obj.builtins['default_library'].value, 'static') self.assertEqual(obj.builtins['warning_level'].value, '1') + self.assertEqual(obj.user_options['set_sub_opt'].value, True) + self.assertEqual(obj.user_options['subp:subp_opt'].value, 'default3') self.wipe() # warning_level is special, it's --warnlevel instead of --warning-level @@ -2114,6 +2116,45 @@ recommended as it can lead to undefined behaviour on some platforms''') self.assertEqual(obj.builtins['default_library'].value, 'shared') self.wipe() + # Should fail on unknown options + with self.assertRaises(subprocess.CalledProcessError) as cm: + self.init(testdir, extra_args=['-Dbad=1', '-Dfoo=2', '-Dwrong_link_args=foo']) + self.assertNotEqual(0, cm.exception.returncode) + self.assertIn('Unknown options: "bad, foo, wrong_link_args"', cm.exception.output) + self.wipe() + + # Should fail on malformed option + with self.assertRaises(subprocess.CalledProcessError) as cm: + self.init(testdir, extra_args=['-Dfoo']) + self.assertNotEqual(0, cm.exception.returncode) + self.assertIn('Option \'foo\' must have a value separated by equals sign.', cm.exception.output) + self.init(testdir) + with self.assertRaises(subprocess.CalledProcessError) as cm: + self.setconf('-Dfoo') + self.assertNotEqual(0, cm.exception.returncode) + self.assertIn('Option \'foo\' must have a value separated by equals sign.', cm.exception.output) + self.wipe() + + # It is not an error to set wrong option for unknown subprojects or + # language because we don't have control on which one will be selected. + self.init(testdir, extra_args=['-Dc_wrong=1', '-Dwrong:bad=1', '-Db_wrong=1']) + self.wipe() + + # Test we can set subproject option + self.init(testdir, extra_args=['-Dsubp:subp_opt=foo']) + obj = mesonbuild.coredata.load(self.builddir) + self.assertEqual(obj.user_options['subp:subp_opt'].value, 'foo') + self.wipe() + + # c_args value should be parsed with shlex + self.init(testdir, extra_args=['-Dc_args=foo bar "one two"']) + obj = mesonbuild.coredata.load(self.builddir) + self.assertEqual(obj.compiler_options['c_args'].value, ['foo', 'bar', 'one two']) + self.setconf('-Dc_args="foo bar" one two') + obj = mesonbuild.coredata.load(self.builddir) + self.assertEqual(obj.compiler_options['c_args'].value, ['foo bar', 'one', 'two']) + self.wipe() + def test_compiler_options_documented(self): ''' Test that C and C++ compiler options and base options are documented in @@ -2271,25 +2312,6 @@ class FailureTests(BasePlatformTests): ''' self.assertMesonRaises(code, "Method.*configtool.*is invalid.*internal") - def test_bad_option(self): - tdir = os.path.join(self.unit_test_dir, '19 bad command line options') - os.environ['MESON_FORCE_BACKTRACE'] = '1' - self.init(tdir, extra_args=['-Dopt=bar', '-Dc_args=-Wall'], inprocess=True) - self.wipe() - out = self.init(tdir, extra_args=['-Dfoo=bar', '-Dbad=true'], inprocess=True) - self.assertRegex( - out, r'Unknown command line options: "bad, foo"') - - def test_bad_option_subproject(self): - tdir = os.path.join(self.unit_test_dir, '19 bad command line options') - os.environ['MESON_FORCE_BACKTRACE'] = '1' - self.init(tdir, extra_args=['-Done:one=bar'], inprocess=True) - self.wipe() - out = self.init(tdir, extra_args=['-Done:two=bar'], inprocess=True) - self.assertRegex( - out, - r'In subproject one: Unknown command line options: "one:two"') - def test_objc_cpp_detection(self): ''' Test that when we can't detect objc or objcpp, we fail gracefully. |