diff mbox series

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

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

Commit Message

Yoann Congal Jan. 10, 2025, 10:56 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>
Reviewed-by: Ghislain Mangé <ghislain.mange@smile.fr>
---
v1->v2:
* More comprehensive test cases with =, ?= and ??= combinations
---
 lib/bb/tests/parse.py | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

Comments

Peter Kjellerstedt Jan. 11, 2025, 11:06 a.m. UTC | #1
> -----Original Message-----
> From: bitbake-devel@lists.openembedded.org <bitbake-devel@lists.openembedded.org> On Behalf Of Yoann Congal via lists.openembedded.org
> Sent: den 10 januari 2025 23:57
> To: bitbake-devel@lists.openembedded.org
> Cc: Yoann Congal <yoann.congal@smile.fr>; Ghislain Mangé <ghislain.mange@smile.fr>
> Subject: [bitbake-devel] [PATCH v2 1/2] tests/parse: add test for ?= and ??= operators for variable flags
> 
> 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>
> Reviewed-by: Ghislain Mangé <ghislain.mange@smile.fr>
> ---
> v1->v2:
> * More comprehensive test cases with =, ?= and ??= combinations
> ---
>  lib/bb/tests/parse.py | 41 +++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 41 insertions(+)
> 
> diff --git a/lib/bb/tests/parse.py b/lib/bb/tests/parse.py
> index 56eb66be9..38c3e3253 100644
> --- a/lib/bb/tests/parse.py
> +++ b/lib/bb/tests/parse.py
> @@ -75,6 +75,47 @@ 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"
> +
> +A[flag_question_vs_default] ?= "question flag"
> +A[flag_question_vs_default] ??= "default flag"
> +
> +A[flag_default_vs_question] ??= "default flag"
> +A[flag_default_vs_question] ?= "question flag"
> +
> +A[flag_set_question_default] = "set flag"
> +A[flag_set_question_default] ?= "question flag"
> +A[flag_set_question_default] ??= "default flag"
> +
> +A[flag_set_default_question] = "set flag"
> +A[flag_set_default_question] ??= "default flag"
> +A[flag_set_default_question] ?= "question flag"

I would like to suggest that you add tests that verifies the behavior when 
the same operator is used twice, e.g.:

A[flag_set_twice] = "set flag first"
A[flag_set_twice] = "set flag second"

A[flag_question_twice] ?= "question flag first"
A[flag_question_twice] ?= "question flag second"

A[flag_default_twice] ??= "default flag first"
A[flag_default_twice] ??= "default flag second"

//Peter

> +"""
> +    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")
> +        self.assertEqual(d.getVarFlag("A","flag_question_vs_default"), "question flag")
> +        self.assertEqual(d.getVarFlag("A","flag_default_vs_question"), "question flag")
> +        self.assertEqual(d.getVarFlag("A","flag_set_question_default"), "set flag")
> +        self.assertEqual(d.getVarFlag("A","flag_set_default_question"), "set flag")
> +
>      exporttest = """
>  A = "a"
>  export B = "b"
Yoann Congal Jan. 11, 2025, 2:09 p.m. UTC | #2
Le sam. 11 janv. 2025 à 12:06, Peter Kjellerstedt <
peter.kjellerstedt@axis.com> a écrit :

> > -----Original Message-----
> > From: bitbake-devel@lists.openembedded.org <
> bitbake-devel@lists.openembedded.org> On Behalf Of Yoann Congal via
> lists.openembedded.org
> > Sent: den 10 januari 2025 23:57
> > To: bitbake-devel@lists.openembedded.org
> > Cc: Yoann Congal <yoann.congal@smile.fr>; Ghislain Mangé <
> ghislain.mange@smile.fr>
> > Subject: [bitbake-devel] [PATCH v2 1/2] tests/parse: add test for ?= and
> ??= operators for variable flags
> >
> > 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>
> > Reviewed-by: Ghislain Mangé <ghislain.mange@smile.fr>
> > ---
> > v1->v2:
> > * More comprehensive test cases with =, ?= and ??= combinations
> > ---
> >  lib/bb/tests/parse.py | 41 +++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 41 insertions(+)
> >
> > diff --git a/lib/bb/tests/parse.py b/lib/bb/tests/parse.py
> > index 56eb66be9..38c3e3253 100644
> > --- a/lib/bb/tests/parse.py
> > +++ b/lib/bb/tests/parse.py
> > @@ -75,6 +75,47 @@ 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"
> > +
> > +A[flag_question_vs_default] ?= "question flag"
> > +A[flag_question_vs_default] ??= "default flag"
> > +
> > +A[flag_default_vs_question] ??= "default flag"
> > +A[flag_default_vs_question] ?= "question flag"
> > +
> > +A[flag_set_question_default] = "set flag"
> > +A[flag_set_question_default] ?= "question flag"
> > +A[flag_set_question_default] ??= "default flag"
> > +
> > +A[flag_set_default_question] = "set flag"
> > +A[flag_set_default_question] ??= "default flag"
> > +A[flag_set_default_question] ?= "question flag"
>
> I would like to suggest that you add tests that verifies the behavior when
> the same operator is used twice, e.g.:
>

A[flag_set_twice] = "set flag first"
> A[flag_set_twice] = "set flag second"
>
> A[flag_question_twice] ?= "question flag first"
> A[flag_question_twice] ?= "question flag second"
>
> A[flag_default_twice] ??= "default flag first"
> A[flag_default_twice] ??= "default flag second"
>

I was not sure what the expected behavior was in these cases, but the doc
is clear (kudos!) :
https://docs.yoctoproject.org/bitbake/bitbake-user-manual/bitbake-user-manual-metadata.html#setting-a-default-value
:
A[flag_set_twice] = "set flag second"
A[flag_question_twice] = "question flag first"
A[flag_default_twice] = "default flag second"

I'll add these in V3, thanks!


>
> //Peter
>
> > +"""
> > +    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")
> > +        self.assertEqual(d.getVarFlag("A","flag_question_vs_default"),
> "question flag")
> > +        self.assertEqual(d.getVarFlag("A","flag_default_vs_question"),
> "question flag")
> > +        self.assertEqual(d.getVarFlag("A","flag_set_question_default"),
> "set flag")
> > +        self.assertEqual(d.getVarFlag("A","flag_set_default_question"),
> "set flag")
> > +
> >      exporttest = """
> >  A = "a"
> >  export B = "b"
>
diff mbox series

Patch

diff --git a/lib/bb/tests/parse.py b/lib/bb/tests/parse.py
index 56eb66be9..38c3e3253 100644
--- a/lib/bb/tests/parse.py
+++ b/lib/bb/tests/parse.py
@@ -75,6 +75,47 @@  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"
+
+A[flag_question_vs_default] ?= "question flag"
+A[flag_question_vs_default] ??= "default flag"
+
+A[flag_default_vs_question] ??= "default flag"
+A[flag_default_vs_question] ?= "question flag"
+
+A[flag_set_question_default] = "set flag"
+A[flag_set_question_default] ?= "question flag"
+A[flag_set_question_default] ??= "default flag"
+
+A[flag_set_default_question] = "set flag"
+A[flag_set_default_question] ??= "default flag"
+A[flag_set_default_question] ?= "question 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")
+        self.assertEqual(d.getVarFlag("A","flag_question_vs_default"), "question flag")
+        self.assertEqual(d.getVarFlag("A","flag_default_vs_question"), "question flag")
+        self.assertEqual(d.getVarFlag("A","flag_set_question_default"), "set flag")
+        self.assertEqual(d.getVarFlag("A","flag_set_default_question"), "set flag")
+
     exporttest = """
 A = "a"
 export B = "b"