summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/Kvisibility261
-rw-r--r--testsuite.py145
2 files changed, 406 insertions, 0 deletions
diff --git a/tests/Kvisibility b/tests/Kvisibility
new file mode 100644
index 0000000..5521863
--- /dev/null
+++ b/tests/Kvisibility
@@ -0,0 +1,261 @@
+config MODULES
+ bool "MODULES"
+
+#
+# Symbol visibility
+#
+
+config NO_PROMPT
+ bool
+
+# Not rewritten, so MOD will have the value 'y' when running without modules
+config MOD
+ def_tristate m
+
+config BOOL_n
+ bool "bool n" if n
+
+# Rewritten to m && MODULES
+config BOOL_m
+ bool "bool m" if m
+
+# Not rewritten
+config BOOL_MOD
+ bool "bool MOD"
+ depends on MOD
+
+# Rewritten to m && MODULES
+config BOOL_y
+ bool "bool y"
+ depends on y || m
+
+config TRISTATE_n
+ tristate "tristate n" if n
+
+# Rewritten to m && MODULES
+config TRISTATE_m
+ tristate "tristate m" if m
+
+# Not rewritten
+config TRISTATE_MOD
+ tristate "tristate MOD"
+ depends on MOD
+
+# Rewritten to m && MODULES
+config TRISTATE_y
+ bool "tristate y"
+ depends on y || m
+
+# Symbols nested in 'if'
+
+if n
+config BOOL_if_n
+ bool "bool if n"
+config TRISTATE_if_n
+ tristate "tristate if n"
+endif
+
+if m
+config BOOL_if_m
+ bool "bool if m"
+config TRISTATE_if_m
+ tristate "tristate if n"
+endif
+
+if y
+config BOOL_if_y
+ bool "bool if y"
+config TRISTATE_if_y
+ tristate "tristate if y"
+endif
+
+# Symbols nested in 'menu'
+
+menu "menu 1"
+ depends on n
+config BOOL_menu_n
+ bool "bool menu n"
+config TRISTATE_menu_n
+ tristate "tristate menu n"
+endmenu
+
+menu "menu 2"
+ depends on m
+config BOOL_menu_m
+ bool "bool menu m"
+config TRISTATE_menu_m
+ tristate "tristate menu n"
+endmenu
+
+menu "menu 3"
+ depends on y
+config BOOL_menu_y
+ bool "bool menu y"
+config TRISTATE_menu_y
+ tristate "tristate menu y"
+endmenu
+
+# Symbols nested in choices
+
+choice C1
+ tristate "choice n" if n
+config BOOL_choice_n
+ bool "bool choice n"
+config TRISTATE_choice_n
+ tristate "tristate choice n"
+endchoice
+
+choice C2
+ tristate "choice m" if m
+config BOOL_choice_m
+ bool "bool choice m"
+config TRISTATE_choice_m
+ tristate "tristate choice n"
+endchoice
+
+choice C3
+ tristate "choice y" if y
+config BOOL_choice_y
+ bool "bool choice y"
+config TRISTATE_choice_y
+ tristate "tristate choice y"
+endchoice
+
+#
+# Choice visibility
+#
+
+choice BOOL_CHOICE_n
+ bool "bool choice n" if n
+config A
+ bool "A"
+config B
+ bool "B"
+endchoice
+
+choice BOOL_CHOICE_m
+ bool "bool choice m" if m
+config C
+ bool "C"
+config D
+ bool "D"
+endchoice
+
+choice BOOL_CHOICE_y
+ bool "bool choice y" if y
+config E
+ bool "E"
+config F
+ bool "F"
+endchoice
+
+choice TRISTATE_CHOICE_n
+ tristate "tristate choice n" if n
+config G
+ tristate "G"
+config H
+ tristate "H"
+endchoice
+
+choice TRISTATE_CHOICE_m
+ tristate "tristate choice m" if m
+config I
+ tristate "I"
+config J
+ tristate "J"
+endchoice
+
+choice TRISTATE_CHOICE_y
+ tristate "tristate choice y" if y
+config K
+ tristate "K"
+config L
+ tristate "L"
+endchoice
+
+if m
+choice TRISTATE_CHOICE_IF_m_and_y
+ tristate "tristate choice if m and y" if y
+config M
+ bool "M"
+config N
+ bool "N"
+endchoice
+endif
+
+menu "choice-containing menu"
+ depends on n && y
+choice TRISTATE_CHOICE_MENU_n_and_y
+ tristate "tristate choice if n and y"
+config O
+ tristate "O"
+config P
+ tristate "P"
+endchoice
+endmenu
+
+#
+# Menu visibility
+#
+
+menu "menu n"
+ depends on n
+endmenu
+
+menu "menu m"
+ depends on m
+endmenu
+
+menu "menu y"
+ depends on y
+endmenu
+
+if n
+menu "menu if n"
+endmenu
+endif
+
+if m
+menu "menu if m"
+endmenu
+endif
+
+if y
+menu "menu if y"
+endmenu
+endif
+
+if m
+menu "menu if m and y"
+ depends on y
+endmenu
+endif
+
+#
+# Comment visibility
+#
+
+comment "comment n"
+ depends on n
+comment "comment m"
+ depends on m
+comment "comment y"
+ depends on y
+
+if n
+comment "comment if n"
+endif
+if m
+comment "comment if m"
+endif
+if y
+comment "comment if y"
+endif
+
+if "y"
+menu "comment-containing menu"
+ depends on m
+comment "double-nested m comment"
+ depends on y
+endmenu
+endif
diff --git a/testsuite.py b/testsuite.py
index 6fd78d9..0f359a5 100644
--- a/testsuite.py
+++ b/testsuite.py
@@ -418,6 +418,151 @@ def run_selftests():
verify_location(comment_2, ("Kconfiglib/tests/Klocation_included", 34))
#
+ # Visibility queries
+ #
+
+ print "Testing visibility queries..."
+
+ c = kconfiglib.Config("Kconfiglib/tests/Kvisibility")
+
+ def verify_sym_visibility(sym_name, no_module_vis, module_vis):
+ sym = c[sym_name]
+
+ c["MODULES"].set_user_value("n")
+ sym_vis = sym.get_visibility()
+ verify(sym_vis == no_module_vis,
+ "{0} should have visibility '{1}' without modules, had "
+ "visibility '{2}'".
+ format(sym.get_name(), no_module_vis, sym_vis))
+
+ c["MODULES"].set_user_value("y")
+ sym_vis = sym.get_visibility()
+ verify(sym_vis == module_vis,
+ "{0} should have visibility '{1}' with modules, had "
+ "visibility '{2}'".
+ format(sym.get_name(), module_vis, sym_vis))
+
+ # Symbol visibility
+
+ verify_sym_visibility("NO_PROMPT", "n", "n")
+ verify_sym_visibility("BOOL_n", "n", "n")
+ verify_sym_visibility("BOOL_m", "n", "y") # Promoted
+ verify_sym_visibility("BOOL_MOD", "y", "y") # Promoted
+ verify_sym_visibility("BOOL_y", "y", "y")
+ verify_sym_visibility("TRISTATE_m", "n", "m")
+ verify_sym_visibility("TRISTATE_MOD", "y", "m") # Promoted
+ verify_sym_visibility("TRISTATE_y", "y", "y")
+ verify_sym_visibility("BOOL_if_n", "n", "n")
+ verify_sym_visibility("BOOL_if_m", "n", "y") # Promoted
+ verify_sym_visibility("BOOL_if_y", "y", "y")
+ verify_sym_visibility("BOOL_menu_n", "n", "n")
+ verify_sym_visibility("BOOL_menu_m", "n", "y") # Promoted
+ verify_sym_visibility("BOOL_menu_y", "y", "y")
+ verify_sym_visibility("BOOL_choice_n", "n", "n")
+ verify_sym_visibility("BOOL_choice_m", "n", "y") # Promoted
+ verify_sym_visibility("BOOL_choice_y", "y", "y")
+ verify_sym_visibility("TRISTATE_if_n", "n", "n")
+ verify_sym_visibility("TRISTATE_if_m", "n", "m") # Promoted
+ verify_sym_visibility("TRISTATE_if_y", "y", "y")
+ verify_sym_visibility("TRISTATE_menu_n", "n", "n")
+ verify_sym_visibility("TRISTATE_menu_m", "n", "m") # Promoted
+ verify_sym_visibility("TRISTATE_menu_y", "y", "y")
+ verify_sym_visibility("TRISTATE_choice_n", "n", "n")
+ verify_sym_visibility("TRISTATE_choice_m", "n", "m") # Promoted
+ verify_sym_visibility("TRISTATE_choice_y", "y", "y")
+
+ # Choice visibility
+
+ def verify_choice_visibility(choice, no_module_vis, module_vis):
+ c["MODULES"].set_user_value("n")
+ choice_vis = choice.get_visibility()
+ verify(choice_vis == no_module_vis,
+ "choice {0} should have visibility '{1}' without modules, "
+ "has visibility '{2}'".
+ format(choice.get_name(), no_module_vis, choice_vis))
+
+ c["MODULES"].set_user_value("y")
+ choice_vis = choice.get_visibility()
+ verify(choice_vis == module_vis,
+ "choice {0} should have visibility '{1}' with modules, "
+ "has visibility '{2}'".
+ format(choice.get_name(), module_vis, choice_vis))
+
+ choice_bool_n, choice_bool_m, choice_bool_y, choice_tristate_n, \
+ choice_tristate_m, choice_tristate_y, choice_tristate_if_m_and_y, \
+ choice_tristate_menu_n_and_y \
+ = c.get_choices()[3:]
+
+ verify(choice_bool_n.get_name() == "BOOL_CHOICE_n", "Ops - testing the wrong choices")
+
+ verify_choice_visibility(choice_bool_n, "n", "n")
+ verify_choice_visibility(choice_bool_m, "n", "y") # Promoted
+ verify_choice_visibility(choice_bool_y, "y", "y")
+ verify_choice_visibility(choice_tristate_n, "n", "n")
+ verify_choice_visibility(choice_tristate_m, "n", "m")
+ verify_choice_visibility(choice_tristate_y, "y", "y")
+
+ verify_choice_visibility(choice_tristate_if_m_and_y, "n", "m")
+ verify_choice_visibility(choice_tristate_menu_n_and_y, "n", "n")
+
+ # Menu visibility
+
+ def verify_menu_visibility(menu, no_module_vis, module_vis):
+ c["MODULES"].set_user_value("n")
+ menu_vis = menu.get_visibility()
+ verify(menu_vis == no_module_vis,
+ "menu \"{0}\" should have visibility '{1}' without modules, "
+ "has visibility '{2}'".
+ format(menu.get_title(), no_module_vis, menu_vis))
+
+ c["MODULES"].set_user_value("y")
+ menu_vis = menu.get_visibility()
+ verify(menu_vis == module_vis,
+ "menu \"{0}\" should have visibility '{1}' with modules, "
+ "has visibility '{2}'".
+ format(menu.get_title(), module_vis, menu_vis))
+
+ menu_n, menu_m, menu_y, menu_if_n, menu_if_m, menu_if_y, \
+ menu_if_m_and_y = c.get_menus()[4:-1]
+ verify(menu_n.get_title() == "menu n", "Ops - testing the wrong menus")
+
+ verify_menu_visibility(menu_n, "n", "n")
+ verify_menu_visibility(menu_m, "n", "m")
+ verify_menu_visibility(menu_y, "y", "y")
+ verify_menu_visibility(menu_if_n, "n", "n")
+ verify_menu_visibility(menu_if_m, "n", "m")
+ verify_menu_visibility(menu_if_y, "y", "y")
+ verify_menu_visibility(menu_if_m_and_y, "n", "m")
+
+ # Comment visibility
+
+ def verify_comment_visibility(comment, no_module_vis, module_vis):
+ c["MODULES"].set_user_value("n")
+ comment_vis = comment.get_visibility()
+ verify(comment_vis == no_module_vis,
+ "comment \"{0}\" should have visibility '{1}' without "
+ "modules, has visibility '{2}'".
+ format(comment.get_text(), no_module_vis, comment_vis))
+
+ c["MODULES"].set_user_value("y")
+ comment_vis = comment.get_visibility()
+ verify(comment_vis == module_vis,
+ "comment \"{0}\" should have visibility '{1}' with "
+ "modules, has visibility '{2}'".
+ format(comment.get_text(), module_vis, comment_vis))
+
+ comment_n, comment_m, comment_y, comment_if_n, comment_if_m, \
+ comment_if_y, comment_m_nested = c.get_comments()
+
+ verify_comment_visibility(comment_n, "n", "n")
+ verify_comment_visibility(comment_m, "n", "m")
+ verify_comment_visibility(comment_y, "y", "y")
+ verify_comment_visibility(comment_if_n, "n", "n")
+ verify_comment_visibility(comment_if_m, "n", "m")
+ verify_comment_visibility(comment_if_y, "y", "y")
+ verify_comment_visibility(comment_m_nested, "n", "m")
+
+ #
# Object relations
#