diff options
| -rw-r--r-- | kconfiglib.py | 23 | ||||
| -rw-r--r-- | testsuite.py | 32 |
2 files changed, 49 insertions, 6 deletions
diff --git a/kconfiglib.py b/kconfiglib.py index 670b312..a93ca0d 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -5112,7 +5112,11 @@ class Variable(object): expanded_value: The expanded value of the variable. For simple variables (those defined with :=), this will equal 'value'. Accessing this property will raise a - KconfigError if any variable in the expansion expands to itself. + KconfigError if the expansion seems to be stuck in a loop. + + Note: Accessing this field is the same as calling expanded_value_w_args() + with no arguments. I hadn't considered function arguments when adding it. + It is retained for backwards compatibility though. is_recursive: True if the variable is recursive (defined with =). @@ -5130,7 +5134,22 @@ class Variable(object): """ See the class documentation. """ - return self.kconfig._expand_whole(self.value, ()) + return self.expanded_value_w_args() + + def expanded_value_w_args(self, *args): + """ + Returns the expanded value of the variable/function. Any arguments + passed will be substituted for $(1), $(2), etc. + + Raises a KconfigError if the expansion seems to be stuck in a loop. + """ + return self.kconfig._fn_val((self.name,) + args) + + def __repr__(self): + return "<variable {}, {}, value '{}'>" \ + .format(self.name, + "recursive" if self.is_recursive else "immediate", + self.value) class KconfigError(Exception): """ diff --git a/testsuite.py b/testsuite.py index 782f3ed..644c151 100644 --- a/testsuite.py +++ b/testsuite.py @@ -2352,16 +2352,21 @@ config J # We verify warnings manually c = Kconfig("Kconfiglib/tests/Kpreprocess", warn_to_stderr=False) - def verify_variable(name, unexp_value, exp_value, recursive): + def verify_variable(name, unexp_value, exp_value, recursive, *args): var = c.variables[name] verify(var.value == unexp_value, "expected variable '{}' to have the unexpanded value '{}', had " "the value '{}'".format(name, unexp_value, var.value)) - verify(var.expanded_value == exp_value, - "expected variable '{}' to have the expanded value '{}', had " - "the value '{}'".format(name, exp_value, var.expanded_value)) + if not args: + verify(var.expanded_value == exp_value, + "expected expanded_value for {} to be '{}', was '{}'" + .format(name, exp_value, var.expanded_value)) + + verify(var.expanded_value_w_args(*args) == exp_value, + "expected expanded_value_w_args() for '{}' to be '{}', was '{}'" + .format(name, exp_value, var.expanded_value_w_args(*args))) verify(var.is_recursive == recursive, "{} was {}, shouldn't be" @@ -2393,6 +2398,14 @@ config J '",$(foo)"', True) + verify_variable("quote", '"$(1)" "$(2)"', '"" ""', True) + verify_variable("quote", '"$(1)" "$(2)"', '"one" ""', True, + "one") + verify_variable("quote", '"$(1)" "$(2)"', '"one" "two"', True, + "one", "two") + verify_variable("quote", '"$(1)" "$(2)"', '"one" "two"', True, + "one", "two", "three") + verify_str(c.syms["PRINT_ME"], r""" config PRINT_ME string @@ -2407,6 +2420,17 @@ config PRINT_ME_TOO default FOOBARBAZQAZ if QAZ && QAZFOO && xxx """) + def verify_repr(name, s): + verify_equal(repr(c.variables[name]), s) + + verify_repr( + "simple-immediate", + "<variable simple-immediate, immediate, value 'bar'>") + + verify_repr( + "messy-fn-res", + "<variable messy-fn-res, recursive, value '$($(fn-indir)-unused-arg, a b , c d )'>") + def verify_recursive(name): try: c.variables[name].expanded_value |
