Exemple #1
0
 def test_trivial(self):
     feature = dsl.Feature(name='name')
     origSubstitutions = copy.deepcopy(self.config.substitutions)
     self.assertTrue(feature.isSupported(self.config))
     feature.enableIn(self.config)
     self.assertEqual(origSubstitutions, self.config.substitutions)
     self.assertIn('name', self.config.available_features)
Exemple #2
0
 def test_link_flag_can_be_a_callable(self):
     feature = dsl.Feature(name='name',
                           linkFlag=lambda cfg:
                           (self.assertIs(self.config, cfg), '-foo')[1])
     assert feature.isSupported(self.config)
     feature.enableIn(self.config)
     self.assertIn('-foo', self.getSubstitution('%{link_flags}'))
Exemple #3
0
 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)
Exemple #4
0
 def test_actions_can_be_a_callable(self):
     feature = dsl.Feature(name='name',
                           actions=lambda cfg:
                           (self.assertIs(self.config, cfg),
                            [dsl.AddCompileFlag('-std=c++03')])[1])
     for a in feature.getActions(self.config):
         a.applyTo(self.config)
     self.assertIn('-std=c++03', self.getSubstitution('%{compile_flags}'))
Exemple #5
0
 def test_adding_action(self):
     feature = dsl.Feature(name='name', actions=[dsl.AddCompileFlag('-std=c++03')])
     origLinkFlags = copy.deepcopy(self.getSubstitution('%{link_flags}'))
     for a in feature.getActions(self.config):
         a.applyTo(self.config)
     self.assertIn('name', self.config.available_features)
     self.assertIn('-std=c++03', self.getSubstitution('%{compile_flags}'))
     self.assertEqual(origLinkFlags, self.getSubstitution('%{link_flags}'))
Exemple #6
0
 def test_adding_compile_flag(self):
     feature = dsl.Feature(name='name', compileFlag='-foo')
     origLinkFlags = copy.deepcopy(self.getSubstitution('%{link_flags}'))
     assert feature.isSupported(self.config)
     feature.enableIn(self.config)
     self.assertIn('name', self.config.available_features)
     self.assertIn('-foo', self.getSubstitution('%{compile_flags}'))
     self.assertEqual(origLinkFlags, self.getSubstitution('%{link_flags}'))
Exemple #7
0
 def test_trivial(self):
     feature = dsl.Feature(name='name')
     origSubstitutions = copy.deepcopy(self.config.substitutions)
     actions = feature.getActions(self.config)
     self.assertTrue(len(actions) == 1)
     for a in actions:
         a.applyTo(self.config)
     self.assertEqual(origSubstitutions, self.config.substitutions)
     self.assertIn('name', self.config.available_features)
Exemple #8
0
 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)
Exemple #9
0
 def test_value_provided_on_command_line_and_no_default_value(self):
     self.litConfig.params['std'] = 'c++03'
     param = dsl.Parameter(name='std',
                           choices=['c++03'],
                           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)
Exemple #10
0
    def test_adding_both_flags(self):
        feature = dsl.Feature(name='name', compileFlag='-hello', linkFlag='-world')
        assert feature.isSupported(self.config)
        feature.enableIn(self.config)
        self.assertIn('name', self.config.available_features)

        self.assertIn('-hello', self.getSubstitution('%{compile_flags}'))
        self.assertNotIn('-world', self.getSubstitution('%{compile_flags}'))

        self.assertIn('-world', self.getSubstitution('%{link_flags}'))
        self.assertNotIn('-hello', self.getSubstitution('%{link_flags}'))
Exemple #11
0
 def test_boolean_value_from_false_boolean_parameter(self):
     self.litConfig.params['enable_exceptions'] = False
     param = dsl.Parameter(
         name='enable_exceptions',
         choices=[True, False],
         type=bool,
         help='',
         feature=lambda exceptions: None
         if exceptions else dsl.Feature(name="-fno-exceptions"))
     param.getFeature(self.config,
                      self.litConfig.params).enableIn(self.config)
     self.assertIn('-fno-exceptions', self.config.available_features)
Exemple #12
0
 def test_name_is_not_a_string_2(self):
     feature = dsl.Feature(name=lambda cfg: None)
     self.assertRaises(ValueError, lambda: feature.getActions(self.config))
     self.assertRaises(ValueError, lambda: feature.pretty(self.config))
Exemple #13
0
 def test_name_can_be_a_callable(self):
     feature = dsl.Feature(name=lambda cfg: 'name')
     for a in feature.getActions(self.config):
         a.applyTo(self.config)
     self.assertIn('name', self.config.available_features)
Exemple #14
0
 def test_is_supported_gets_passed_the_config(self):
     feature = dsl.Feature(name='name',
                           when=lambda cfg:
                           (self.assertIs(self.config, cfg), True)[1])
     self.assertTrue(feature.isSupported(self.config))
Exemple #15
0
 def test_unsupported_feature(self):
     feature = dsl.Feature(name='name', when=lambda _: False)
     self.assertFalse(feature.isSupported(self.config))
     # Also make sure we assert if we ever try to add it to a config
     self.assertRaises(AssertionError,
                       lambda: feature.enableIn(self.config))
Exemple #16
0
 def test_getName_when_unsupported(self):
     feature = dsl.Feature(name='name', when=lambda _: False)
     assert not feature.isSupported(self.config)
     self.assertRaises(AssertionError, lambda: feature.getName(self.config))
Exemple #17
0
 def test_unsupported_feature(self):
     feature = dsl.Feature(name='name', when=lambda _: False)
     self.assertEqual(feature.getActions(self.config), [])
Exemple #18
0
 def test_name_is_not_a_string_2(self):
     feature = dsl.Feature(name=lambda cfg: None)
     assert feature.isSupported(self.config)
     self.assertRaises(ValueError, lambda: feature.enableIn(self.config))
Exemple #19
0
 def test_name_can_be_a_callable(self):
     feature = dsl.Feature(
         name=lambda cfg: (self.assertIs(self.config, cfg), 'name')[1])
     assert feature.isSupported(self.config)
     feature.enableIn(self.config)
     self.assertIn('name', self.config.available_features)
Exemple #20
0
 def test_is_supported_gets_passed_the_config(self):
     feature = dsl.Feature(name='name',
                           when=lambda cfg:
                           (self.assertIs(self.config, cfg), True)[1])
     self.assertEqual(len(feature.getActions(self.config)), 1)
Exemple #21
0
 def test_name_can_be_a_callable(self):
     feature = dsl.Feature(name=lambda cfg: 'name')
     assert feature.isSupported(self.config)
     self.assertEqual('name', feature.getName(self.config))
     feature.enableIn(self.config)
     self.assertIn('name', self.config.available_features)