From 17c8193615e5fafbbfcf99b1d028f5da36d79cc4 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 16 Jun 2020 11:11:15 -0700 Subject: machine-files: give better error messages about using integers --- mesonbuild/coredata.py | 12 +++++++++--- test cases/failing/106 number in combo/meson.build | 1 + test cases/failing/106 number in combo/nativefile.ini | 2 ++ test cases/failing/106 number in combo/test.json | 5 +++++ test cases/failing/107 bool in combo/meson.build | 1 + test cases/failing/107 bool in combo/meson_options.txt | 5 +++++ test cases/failing/107 bool in combo/nativefile.ini | 2 ++ test cases/failing/107 bool in combo/test.json | 5 +++++ 8 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 test cases/failing/106 number in combo/meson.build create mode 100644 test cases/failing/106 number in combo/nativefile.ini create mode 100644 test cases/failing/106 number in combo/test.json create mode 100644 test cases/failing/107 bool in combo/meson.build create mode 100644 test cases/failing/107 bool in combo/meson_options.txt create mode 100644 test cases/failing/107 bool in combo/nativefile.ini create mode 100644 test cases/failing/107 bool in combo/test.json diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 0cac029..b7efe30 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -161,10 +161,16 @@ class UserComboOption(UserOption[str]): def validate_value(self, value): if value not in self.choices: + if isinstance(value, bool): + _type = 'boolean' + elif isinstance(value, (int, float)): + _type = 'number' + else: + _type = 'string' optionsstring = ', '.join(['"%s"' % (item,) for item in self.choices]) - raise MesonException('Value "{}" for combo option "{}" is not one of the choices.' - ' Possible choices are: {}.'.format( - value, self.description, optionsstring)) + raise MesonException('Value "{}" (of type "{}") for combo option "{}" is not one of the choices.' + ' Possible choices are (as string): {}.'.format( + value, _type, self.description, optionsstring)) return value class UserArrayOption(UserOption[T.List[str]]): diff --git a/test cases/failing/106 number in combo/meson.build b/test cases/failing/106 number in combo/meson.build new file mode 100644 index 0000000..1a647df --- /dev/null +++ b/test cases/failing/106 number in combo/meson.build @@ -0,0 +1 @@ +project('number in combo') diff --git a/test cases/failing/106 number in combo/nativefile.ini b/test cases/failing/106 number in combo/nativefile.ini new file mode 100644 index 0000000..55f10fc --- /dev/null +++ b/test cases/failing/106 number in combo/nativefile.ini @@ -0,0 +1,2 @@ +[built-in options] +optimization = 1 diff --git a/test cases/failing/106 number in combo/test.json b/test cases/failing/106 number in combo/test.json new file mode 100644 index 0000000..a32c358 --- /dev/null +++ b/test cases/failing/106 number in combo/test.json @@ -0,0 +1,5 @@ +{ + "stdout": [ + { "line": "test cases/failing/106 number in combo/meson.build:1:0: ERROR: Value \"1\" (of type \"number\") for combo option \"Optimization level\" is not one of the choices. Possible choices are (as string): \"0\", \"g\", \"1\", \"2\", \"3\", \"s\"." } + ] +} diff --git a/test cases/failing/107 bool in combo/meson.build b/test cases/failing/107 bool in combo/meson.build new file mode 100644 index 0000000..c5efd67 --- /dev/null +++ b/test cases/failing/107 bool in combo/meson.build @@ -0,0 +1 @@ +project('bool in combo') diff --git a/test cases/failing/107 bool in combo/meson_options.txt b/test cases/failing/107 bool in combo/meson_options.txt new file mode 100644 index 0000000..0c8f5de --- /dev/null +++ b/test cases/failing/107 bool in combo/meson_options.txt @@ -0,0 +1,5 @@ +option( + 'opt', + type : 'combo', + choices : ['true', 'false'] +) diff --git a/test cases/failing/107 bool in combo/nativefile.ini b/test cases/failing/107 bool in combo/nativefile.ini new file mode 100644 index 0000000..b423957 --- /dev/null +++ b/test cases/failing/107 bool in combo/nativefile.ini @@ -0,0 +1,2 @@ +[project options] +opt = true diff --git a/test cases/failing/107 bool in combo/test.json b/test cases/failing/107 bool in combo/test.json new file mode 100644 index 0000000..37218e8 --- /dev/null +++ b/test cases/failing/107 bool in combo/test.json @@ -0,0 +1,5 @@ +{ + "stdout": [ + { "line": "test cases/failing/107 bool in combo/meson.build:1:0: ERROR: Value \"True\" (of type \"boolean\") for combo option \"opt\" is not one of the choices. Possible choices are (as string): \"true\", \"false\"." } + ] +} -- cgit v1.1