aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntonin Godard <antoningodard@pm.me>2024-05-14 01:53:21 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2024-05-21 14:14:21 +0100
commitd98130cb4d500c495bc692c56dde3e019f36320a (patch)
treef6d7713f3173b4cdc640b82298983ba13dd3f9cb
parent89712949de9476e4674864a8dcd6862fefe92eae (diff)
downloadbitbake-contrib-d98130cb4d500c495bc692c56dde3e019f36320a.tar.gz
tests.codeparser: add tests for shell expansions
Tests quotes around `` and $() expansions, nested and multiple expansions, and that escaped quotes are treated as characters by the parser. Signed-off-by: Antonin Godard <antoningodard@pm.me> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--lib/bb/tests/codeparser.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/bb/tests/codeparser.py b/lib/bb/tests/codeparser.py
index f6585fb3a..c0d1362a0 100644
--- a/lib/bb/tests/codeparser.py
+++ b/lib/bb/tests/codeparser.py
@@ -106,6 +106,46 @@ ${D}${libdir}/pkgconfig/*.pc
self.parseExpression("foo=$(echo bar)")
self.assertExecs(set(["echo"]))
+ def test_assign_subshell_expansion_quotes(self):
+ self.parseExpression('foo="$(echo bar)"')
+ self.assertExecs(set(["echo"]))
+
+ def test_assign_subshell_expansion_nested(self):
+ self.parseExpression('foo="$(func1 "$(func2 bar$(func3))")"')
+ self.assertExecs(set(["func1", "func2", "func3"]))
+
+ def test_assign_subshell_expansion_multiple(self):
+ self.parseExpression('foo="$(func1 "$(func2)") $(func3)"')
+ self.assertExecs(set(["func1", "func2", "func3"]))
+
+ def test_assign_subshell_expansion_escaped_quotes(self):
+ self.parseExpression('foo="\\"fo\\"o$(func1)"')
+ self.assertExecs(set(["func1"]))
+
+ def test_assign_subshell_expansion_empty(self):
+ self.parseExpression('foo="bar$()foo"')
+ self.assertExecs(set())
+
+ def test_assign_subshell_backticks(self):
+ self.parseExpression("foo=`echo bar`")
+ self.assertExecs(set(["echo"]))
+
+ def test_assign_subshell_backticks_quotes(self):
+ self.parseExpression('foo="`echo bar`"')
+ self.assertExecs(set(["echo"]))
+
+ def test_assign_subshell_backticks_multiple(self):
+ self.parseExpression('foo="`func1 bar` `func2`"')
+ self.assertExecs(set(["func1", "func2"]))
+
+ def test_assign_subshell_backticks_escaped_quotes(self):
+ self.parseExpression('foo="\\"fo\\"o`func1`"')
+ self.assertExecs(set(["func1"]))
+
+ def test_assign_subshell_backticks_empty(self):
+ self.parseExpression('foo="bar``foo"')
+ self.assertExecs(set())
+
def test_shell_unexpanded(self):
self.setEmptyVars(["QT_BASE_NAME"])
self.parseExpression('echo "${QT_BASE_NAME}"')