|
9 | 9 |
|
10 | 10 | import pytest |
11 | 11 |
|
12 | | -from kconfiglib import Kconfig, KconfigError, MenuNode, Symbol |
| 12 | +from kconfiglib import Kconfig, KconfigError, MenuNode, Symbol, expr_value |
13 | 13 |
|
14 | 14 | # -- helpers ----------------------------------------------------------------- |
15 | 15 |
|
@@ -389,3 +389,79 @@ def test_item_lists(): |
389 | 389 | _verify_prompts(c.choices, "choice 1", "choice 2", "choice 3", "choice 2") |
390 | 390 | _verify_prompts(c.menus, "menu 1", "menu 2", "menu 3", "menu 4", "menu 5") |
391 | 391 | _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