diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2018-10-21 16:09:24 +0200 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2018-10-21 17:28:31 +0200 |
| commit | 9a4127a1d5eeac122cb478b0e03d42c9698c41be (patch) | |
| tree | f31f04aba7944545ac288c10012c3cda5aec6b42 /testsuite.py | |
| parent | d23accda70935ddbf6d01f3c0043f17bffad3706 (diff) | |
Allow programmatically expanding preprocessor functions with args
Add a Variable.expanded_value_w_args() function for expanding a
preprocessor function with particular arguments. This is what
expanded_value should have been, because expanded_value_w_args() is more
general (expanded_value corresponds to zero arguments). Keep
expanded_value for backwards compatibility though.
Also add a simple __repr__() to Variable. It could show the expanded
value, but that might mean calling shell functions or user-defined
functions as a side effect (possibly with missing arguments). Not sure
that's a good idea, so just show the unexpanded value.
Diffstat (limited to 'testsuite.py')
| -rw-r--r-- | testsuite.py | 32 |
1 files changed, 28 insertions, 4 deletions
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 |
