param = dsl.Parameter(name='std', choices=['c++03'], type=str, help='', feature=lambda _: None)
self.assertEqual(param.name, 'std')
- def test_no_value_provided_on_command_line_and_no_default_value(self):
+ def test_no_value_provided_and_no_default_value(self):
param = dsl.Parameter(name='std', choices=['c++03'], type=str, help='', feature=lambda _: None)
self.assertRaises(ValueError, lambda: param.getFeature(self.config, self.litConfig.params))
- def test_no_value_provided_on_command_line_and_default_value(self):
+ def test_no_value_provided_and_default_value(self):
param = dsl.Parameter(name='std', choices=['c++03'], type=str, help='', default='c++03',
feature=lambda std: dsl.Feature(name=std))
param.getFeature(self.config, self.litConfig.params).enableIn(self.config)
self.assertIn('c++03', self.config.available_features)
def test_value_provided_on_command_line_and_default_value(self):
+ """The value provided on the command line should override the default value"""
self.litConfig.params['std'] = 'c++11'
param = dsl.Parameter(name='std', choices=['c++03', 'c++11'], type=str, default='c++03', help='',
feature=lambda std: dsl.Feature(name=std))
self.assertIn('c++11', self.config.available_features)
self.assertNotIn('c++03', self.config.available_features)
+ def test_value_provided_in_config_and_default_value(self):
+ """The value provided in the config should override the default value"""
+ self.config.std ='c++11'
+ param = dsl.Parameter(name='std', choices=['c++03', 'c++11'], type=str, default='c++03', help='',
+ feature=lambda std: dsl.Feature(name=std))
+ param.getFeature(self.config, self.litConfig.params).enableIn(self.config)
+ self.assertIn('c++11', self.config.available_features)
+ self.assertNotIn('c++03', self.config.available_features)
+
+ def test_value_provided_in_config_and_on_command_line(self):
+ """The value on the command line should override the one in the config"""
+ self.config.std = 'c++11'
+ self.litConfig.params['std'] = 'c++03'
+ param = dsl.Parameter(name='std', choices=['c++03', 'c++11'], type=str, help='',
+ feature=lambda std: dsl.Feature(name=std))
+ param.getFeature(self.config, self.litConfig.params).enableIn(self.config)
+ self.assertIn('c++03', self.config.available_features)
+ self.assertNotIn('c++11', self.config.available_features)
+
def test_feature_is_None(self):
self.litConfig.params['std'] = 'c++03'
param = dsl.Parameter(name='std', choices=['c++03'], type=str, help='',
Represents a parameter of a Lit test suite.
Parameters are used to customize the behavior of test suites in a user
- controllable way, more specifically by passing `--param <KEY>=<VALUE>`
- when running Lit. Parameters have multiple possible values, and they can
- have a default value when left unspecified.
-
- Parameters can have a Feature associated to them, in which case the Feature
- is added to the TestingConfig if the parameter is enabled. It is an error if
- the Parameter is enabled but the Feature associated to it is not supported,
- for example trying to set the compilation standard to C++17 when `-std=c++17`
- is not supported by the compiler.
+ controllable way. There are two ways of setting the value of a Parameter.
+ The first one is to pass `--param <KEY>=<VALUE>` when running Lit (or
+ equivalenlty to set `litConfig.params[KEY] = VALUE` somewhere in the
+ Lit configuration files. This method will set the parameter globally for
+ all test suites being run.
+
+ The second method is to set `config.KEY = VALUE` somewhere in the Lit
+ configuration files, which sets the parameter only for the test suite(s)
+ that use that `config` object.
+
+ Parameters can have multiple possible values, and they can have a default
+ value when left unspecified. They can also have a Feature associated to them,
+ in which case the Feature is added to the TestingConfig if the parameter is
+ enabled. It is an error if the Parameter is enabled but the Feature associated
+ to it is not supported, for example trying to set the compilation standard to
+ C++17 when `-std=c++17` is not supported by the compiler.
One important point is that Parameters customize the behavior of the test
suite in a bounded way, i.e. there should be a finite set of possible choices
return self._name
def getFeature(self, config, litParams):
- param = litParams.get(self.name, None)
+ param = getattr(config, self.name, None)
+ param = litParams.get(self.name, param)
if param is None and self._default is None:
- raise ValueError("Parameter {} doesn't have a default value, but it was not specified in the Lit parameters".format(self.name))
+ raise ValueError("Parameter {} doesn't have a default value, but it was not specified in the Lit parameters or in the Lit config".format(self.name))
getDefault = lambda: self._default(config) if callable(self._default) else self._default
value = self._parse(param) if param is not None else getDefault()
if value not in self._choices: