summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2012-12-12 04:18:50 +0100
committerUlf Magnusson <ulfalizer@gmail.com>2012-12-12 04:22:44 +0100
commit9914968a94481f84ad0d9cfcb1f5e85334626042 (patch)
treeea53ae404b0ef4e9a7a9c34981811f4ba720dbdc
parent72a904f42156729efc0be5b1bba348e41097199a (diff)
Always count non-bool/tristate symbols as 'n' in tristate context.
Previously a string symbol that happened to have the value "y" would count as "y" in tristate context, which is incorrect.
-rw-r--r--kconfiglib.py14
-rw-r--r--kconfigtest.py23
-rw-r--r--tests/Keval4
3 files changed, 36 insertions, 5 deletions
diff --git a/kconfiglib.py b/kconfiglib.py
index 88003f9..66e153c 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -1421,10 +1421,15 @@ error, and you should e-mail kconfiglib@gmail.com.
if expr is None:
return "y"
- if isinstance(expr, (str, Symbol)):
- val = self._get_str_value(expr)
- # Expressions always have a tristate value
- return val if val in ("y", "m") else "n"
+ if isinstance(expr, Symbol):
+ # Non-bool/tristate symbols are always "n" in a tristate sense,
+ # regardless of their value
+ if expr.type != BOOL and expr.type != TRISTATE:
+ return "n"
+ return expr.get_value()
+
+ if isinstance(expr, str):
+ return expr if (expr == "y" or expr == "m") else "n"
first_expr = expr[0]
@@ -1484,7 +1489,6 @@ error, and you should e-mail kconfiglib@gmail.com.
def _get_str_value(self, obj):
if isinstance(obj, str):
return obj
-
# obj is a Symbol
return obj.get_value()
diff --git a/kconfigtest.py b/kconfigtest.py
index e9120bd..7927484 100644
--- a/kconfigtest.py
+++ b/kconfigtest.py
@@ -180,15 +180,38 @@ def run_selftests():
verify_val("n", "n")
verify_val("m", "n")
verify_val("y", "y")
+ verify_val("'n'", "n")
+ verify_val("'m'", "n")
+ verify_val("'y'", "y")
verify_val("M", "y")
# Modules
c["MODULES"].set_user_value("y")
verify_val("n", "n")
verify_val("m", "m")
verify_val("y", "y")
+ verify_val("'n'", "n")
+ verify_val("'m'", "m")
+ verify_val("'y'", "y")
verify_val("M", "m")
verify_val("(Y || N) && (m && y)", "m")
+ # Non-bool/non-tristate symbols are always "n" in a tristate sense
+ verify_val("Y_STRING", "n")
+ verify_val("Y_STRING || m", "m")
+
+ # As are all constants besides "y" and "m"
+ verify_val('"foo"', "n")
+ verify_val('"foo" || "bar"', "n")
+
+ # Compare some constants...
+ verify_val('"foo" != "bar"', "y")
+ verify_val('"foo" = "bar"', "n")
+ verify_val('"foo" = "foo"', "y")
+ # As a quirk, undefined values get their name as their value
+ c.set_print_warnings(False)
+ verify_val("'not_defined' = not_defined", "y")
+ verify_val("not_defined_2 = not_defined_2", "y")
+
#
# Text queries
#
diff --git a/tests/Keval b/tests/Keval
index 3541649..b7fe394 100644
--- a/tests/Keval
+++ b/tests/Keval
@@ -10,3 +10,7 @@ config M
menuconfig Y
def_tristate y
+
+config Y_STRING
+ string
+ default "y"