Skip to content

Commit a0c71d9

Browse files
committed
Add dual-prompt visibility tests
Bool-guarded dual prompts (if BAR / if !BAR) yield strict exclusivity. Tristate guards with m-state correctly show both prompts per C Kconfig NOT(m)=m semantics -- this is not a bug but inherent tristate logic.
1 parent 7266e63 commit a0c71d9

2 files changed

Lines changed: 100 additions & 1 deletion

File tree

‎tests/Kdual_prompt‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
config MODULES
2+
bool
3+
default y
4+
5+
config BAR
6+
bool "BAR"
7+
default y
8+
9+
config FOO
10+
bool "Foo" if BAR
11+
12+
config FOO
13+
bool "Foo (EXPERIMENTAL)" if !BAR
14+
15+
config TBAR
16+
tristate "TBAR"
17+
default m
18+
19+
config TFOO
20+
tristate "TFoo" if TBAR
21+
22+
config TFOO
23+
tristate "TFoo (EXPERIMENTAL)" if !TBAR

‎tests/test_properties.py‎

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import pytest
1111

12-
from kconfiglib import Kconfig, KconfigError, MenuNode, Symbol
12+
from kconfiglib import Kconfig, KconfigError, MenuNode, Symbol, expr_value
1313

1414
# -- helpers -----------------------------------------------------------------
1515

@@ -389,3 +389,79 @@ def test_item_lists():
389389
_verify_prompts(c.choices, "choice 1", "choice 2", "choice 3", "choice 2")
390390
_verify_prompts(c.menus, "menu 1", "menu 2", "menu 3", "menu 4", "menu 5")
391391
_verify_prompts(c.comments, "comment 1", "comment 2", "comment 3")
392+
393+
394+
# -- dual-prompt visibility (ulfalizer#117) ---------------------------------
395+
396+
397+
def _prompt_cond_values(sym):
398+
"""Return list of expr_value(node.prompt[1]) for each node of *sym*."""
399+
return [expr_value(node.prompt[1]) for node in sym.nodes if node.prompt]
400+
401+
402+
class TestDualPromptVisibility:
403+
"""When a symbol is defined twice with different prompts gated on mutually
404+
exclusive conditions, only the active prompt should be visible.
405+
406+
Bool guards (BAR / !BAR) yield strict exclusivity: one evaluates to 2 (y),
407+
the other to 0 (n).
408+
409+
Tristate guards (TBAR / !TBAR) follow standard tristate NOT semantics:
410+
NOT(m) = m, so when the guard is m both prompts evaluate to 1 (m). This
411+
matches C Kconfig behavior and is not a bug.
412+
"""
413+
414+
@pytest.fixture(autouse=True)
415+
def _load(self):
416+
self.c = Kconfig("tests/Kdual_prompt", warn=False)
417+
418+
# -- structure ----------------------------------------------------------
419+
420+
def test_foo_has_two_nodes(self):
421+
assert len(self.c.syms["FOO"].nodes) == 2
422+
423+
def test_tfoo_has_two_nodes(self):
424+
assert len(self.c.syms["TFOO"].nodes) == 2
425+
426+
def test_foo_prompts(self):
427+
prompts = [n.prompt[0] for n in self.c.syms["FOO"].nodes]
428+
assert prompts == ["Foo", "Foo (EXPERIMENTAL)"]
429+
430+
def test_tfoo_prompts(self):
431+
prompts = [n.prompt[0] for n in self.c.syms["TFOO"].nodes]
432+
assert prompts == ["TFoo", "TFoo (EXPERIMENTAL)"]
433+
434+
# -- bool guard: strict exclusivity -------------------------------------
435+
436+
def test_bool_bar_y_exclusive(self):
437+
"""BAR=y: first prompt visible (2), second hidden (0)."""
438+
self.c.syms["BAR"].set_value(2)
439+
vals = _prompt_cond_values(self.c.syms["FOO"])
440+
assert vals == [2, 0]
441+
442+
def test_bool_bar_n_exclusive(self):
443+
"""BAR=n: first prompt hidden (0), second visible (2)."""
444+
self.c.syms["BAR"].set_value(0)
445+
vals = _prompt_cond_values(self.c.syms["FOO"])
446+
assert vals == [0, 2]
447+
448+
# -- tristate guard: m-state both visible (correct per C Kconfig) -------
449+
450+
def test_tristate_tbar_m_both_visible(self):
451+
"""TBAR=m: NOT(m) = m, so both prompts evaluate to 1 (m).
452+
This is correct tristate logic, not a bug."""
453+
self.c.syms["TBAR"].set_value(1)
454+
vals = _prompt_cond_values(self.c.syms["TFOO"])
455+
assert vals == [1, 1]
456+
457+
def test_tristate_tbar_y_exclusive(self):
458+
"""TBAR=y: first prompt visible (2), second hidden (0)."""
459+
self.c.syms["TBAR"].set_value(2)
460+
vals = _prompt_cond_values(self.c.syms["TFOO"])
461+
assert vals == [2, 0]
462+
463+
def test_tristate_tbar_n_exclusive(self):
464+
"""TBAR=n: first prompt hidden (0), second visible (2)."""
465+
self.c.syms["TBAR"].set_value(0)
466+
vals = _prompt_cond_values(self.c.syms["TFOO"])
467+
assert vals == [0, 2]

0 commit comments

Comments
 (0)