From 58610eb36808d235fa0b6fcb75a07af82d3414a0 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Mon, 15 Jun 2020 12:19:32 -0400 Subject: [PATCH] [libc++] Raise an exception if a Lit feature resolves to an invalid name This allows reporting issues early when creating feature names. --- libcxx/test/libcxx/selftest/dsl/dsl.sh.py | 10 ++++++++++ libcxx/utils/libcxx/test/dsl.py | 2 ++ 2 files changed, 12 insertions(+) diff --git a/libcxx/test/libcxx/selftest/dsl/dsl.sh.py b/libcxx/test/libcxx/selftest/dsl/dsl.sh.py index 5a8ae88..b9437d6 100644 --- a/libcxx/test/libcxx/selftest/dsl/dsl.sh.py +++ b/libcxx/test/libcxx/selftest/dsl/dsl.sh.py @@ -194,6 +194,16 @@ class TestFeature(SetupConfigs): feature.enableIn(self.config) self.assertIn('name', self.config.available_features) + def test_name_is_not_a_string_1(self): + feature = dsl.Feature(name=None) + assert feature.isSupported(self.config) + self.assertRaises(ValueError, lambda: feature.enableIn(self.config)) + + 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)) + def test_adding_compile_flag(self): feature = dsl.Feature(name='name', compileFlag='-foo') origLinkFlags = copy.deepcopy(self.getSubstitution('%{link_flags}')) diff --git a/libcxx/utils/libcxx/test/dsl.py b/libcxx/utils/libcxx/test/dsl.py index bbed2bba..3e2d0ed 100644 --- a/libcxx/utils/libcxx/test/dsl.py +++ b/libcxx/utils/libcxx/test/dsl.py @@ -220,6 +220,8 @@ class Feature(object): config.substitutions = addTo(config.substitutions, '%{link_flags}', linkFlag) name = self._name(config) if callable(self._name) else self._name + if not isinstance(name, str): + raise ValueError("Feature did not resolve to a name that's a string, got {}".format(name)) config.available_features.add(name) -- 2.7.4