machine-files: give better error messages about using integers

pull/6597/head
Dylan Baker 5 years ago
parent bbba6a7f36
commit 17c8193615
  1. 12
      mesonbuild/coredata.py
  2. 1
      test cases/failing/106 number in combo/meson.build
  3. 2
      test cases/failing/106 number in combo/nativefile.ini
  4. 5
      test cases/failing/106 number in combo/test.json
  5. 1
      test cases/failing/107 bool in combo/meson.build
  6. 5
      test cases/failing/107 bool in combo/meson_options.txt
  7. 2
      test cases/failing/107 bool in combo/nativefile.ini
  8. 5
      test cases/failing/107 bool in combo/test.json

@ -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]]):

@ -0,0 +1,2 @@
[built-in options]
optimization = 1

@ -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\"." }
]
}

@ -0,0 +1,5 @@
option(
'opt',
type : 'combo',
choices : ['true', 'false']
)

@ -0,0 +1,2 @@
[project options]
opt = true

@ -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\"." }
]
}
Loading…
Cancel
Save