diff mbox series

[1/2] tests/parse: add test for ?= and ??= operators for variable flags

Message ID 20250110190842.3861684-1-yoann.congal@smile.fr
State Accepted, archived
Commit d12c80125d810df54379cc4f019a95ab9064ad2c
Headers show
Series [1/2] tests/parse: add test for ?= and ??= operators for variable flags | expand

Commit Message

Yoann Congal Jan. 10, 2025, 7:08 p.m. UTC
From: Yoann Congal <yoann.congal@smile.fr>

Run the test with:
 $ bitbake-selftest bb.tests.parse.ParseTest.test_parse_defaulttest
.
----------------------------------------------------------------------
Ran 1 test in 0.001s

OK

This is a test case for [YOCTO #15685]

Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
---
 lib/bb/tests/parse.py | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
diff mbox series

Patch

diff --git a/lib/bb/tests/parse.py b/lib/bb/tests/parse.py
index 56eb66be9..8e04458a0 100644
--- a/lib/bb/tests/parse.py
+++ b/lib/bb/tests/parse.py
@@ -75,6 +75,29 @@  unset B[flag]
         self.assertEqual(d.getVarFlag("A","flag"), None)
         self.assertEqual(d.getVar("B"), "2")
 
+    defaulttest = """
+A = "set value"
+A ??= "default value"
+
+A[flag_set_vs_question] = "set flag"
+A[flag_set_vs_question] ?= "question flag"
+
+A[flag_set_vs_default] = "set flag"
+A[flag_set_vs_default] ??= "default flag"
+
+A[flag_question] ?= "question flag"
+
+A[flag_default] ??= "default flag"
+"""
+    def test_parse_defaulttest(self):
+        f = self.parsehelper(self.defaulttest)
+        d = bb.parse.handle(f.name, self.d)['']
+        self.assertEqual(d.getVar("A"), "set value")
+        self.assertEqual(d.getVarFlag("A","flag_set_vs_question"), "set flag")
+        self.assertEqual(d.getVarFlag("A","flag_set_vs_default"), "set flag")
+        self.assertEqual(d.getVarFlag("A","flag_question"), "question flag")
+        self.assertEqual(d.getVarFlag("A","flag_default"), "default flag")
+
     exporttest = """
 A = "a"
 export B = "b"