summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2017-04-03 11:19:05 +1200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-04-05 23:19:17 +0100
commit1fe95cfc1261c999389de00e56642252ec2f0c75 (patch)
tree19bb505ff77175ca90188d489127b7900a52143b /bitbake
parent7b7c238b2d6cf8a585afa3a0dfc9bdac111a2a33 (diff)
downloadpoky-1fe95cfc1261c999389de00e56642252ec2f0c75.tar.gz
bitbake: bitbake-selftest: add contains tests
Add some tests to verify that we are extracting "contains" information from python expressions in the code in the bb.data and bb.codeparser modules. (Bitbake rev: 88fda492df875dd79b7aecf1f34b38517fc1eb33) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/bb/tests/codeparser.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/bitbake/lib/bb/tests/codeparser.py b/bitbake/lib/bb/tests/codeparser.py
index a45a582dd9..e30e78c158 100644
--- a/bitbake/lib/bb/tests/codeparser.py
+++ b/bitbake/lib/bb/tests/codeparser.py
@@ -49,6 +49,9 @@ class ReferenceTest(unittest.TestCase):
49 def assertExecs(self, execs): 49 def assertExecs(self, execs):
50 self.assertEqual(self.execs, execs) 50 self.assertEqual(self.execs, execs)
51 51
52 def assertContains(self, contains):
53 self.assertEqual(self.contains, contains)
54
52class VariableReferenceTest(ReferenceTest): 55class VariableReferenceTest(ReferenceTest):
53 56
54 def parseExpression(self, exp): 57 def parseExpression(self, exp):
@@ -201,6 +204,7 @@ class PythonReferenceTest(ReferenceTest):
201 204
202 self.references = parsedvar.references | parser.references 205 self.references = parsedvar.references | parser.references
203 self.execs = parser.execs 206 self.execs = parser.execs
207 self.contains = parser.contains
204 208
205 @staticmethod 209 @staticmethod
206 def indent(value): 210 def indent(value):
@@ -265,6 +269,26 @@ be. These unit tests are testing snippets."""
265 self.assertExecs(set(["testget"])) 269 self.assertExecs(set(["testget"]))
266 del self.context["testget"] 270 del self.context["testget"]
267 271
272 def test_contains(self):
273 self.parseExpression('bb.utils.contains("TESTVAR", "one", "true", "false", d)')
274 self.assertContains({'TESTVAR': {'one'}})
275
276 def test_contains_multi(self):
277 self.parseExpression('bb.utils.contains("TESTVAR", "one two", "true", "false", d)')
278 self.assertContains({'TESTVAR': {'one two'}})
279
280 def test_contains_any(self):
281 self.parseExpression('bb.utils.contains_any("TESTVAR", "hello", "true", "false", d)')
282 self.assertContains({'TESTVAR': {'hello'}})
283
284 def test_contains_any_multi(self):
285 self.parseExpression('bb.utils.contains_any("TESTVAR", "one two three", "true", "false", d)')
286 self.assertContains({'TESTVAR': {'one', 'two', 'three'}})
287
288 def test_contains_filter(self):
289 self.parseExpression('bb.utils.filter("TESTVAR", "hello there world", d)')
290 self.assertContains({'TESTVAR': {'hello', 'there', 'world'}})
291
268 292
269class DependencyReferenceTest(ReferenceTest): 293class DependencyReferenceTest(ReferenceTest):
270 294
@@ -370,6 +394,30 @@ esac
370 394
371 self.assertEqual(deps, set(["oe_libinstall"])) 395 self.assertEqual(deps, set(["oe_libinstall"]))
372 396
397 def test_contains_vardeps(self):
398 expr = '${@bb.utils.filter("TESTVAR", "somevalue anothervalue", d)} \
399 ${@bb.utils.contains("TESTVAR", "testval testval2", "yetanothervalue", "", d)} \
400 ${@bb.utils.contains("TESTVAR", "testval2 testval3", "blah", "", d)} \
401 ${@bb.utils.contains_any("TESTVAR", "testval2 testval3", "lastone", "", d)}'
402 parsedvar = self.d.expandWithRefs(expr, None)
403 # Check contains
404 self.assertEqual(parsedvar.contains, {'TESTVAR': {'testval2 testval3', 'anothervalue', 'somevalue', 'testval testval2', 'testval2', 'testval3'}})
405 # Check dependencies
406 self.d.setVar('ANOTHERVAR', expr)
407 self.d.setVar('TESTVAR', 'anothervalue testval testval2')
408 deps, values = bb.data.build_dependencies("ANOTHERVAR", set(self.d.keys()), set(), set(), self.d)
409 self.assertEqual(sorted(values.splitlines()),
410 sorted([expr,
411 'TESTVAR{anothervalue} = Set',
412 'TESTVAR{somevalue} = Unset',
413 'TESTVAR{testval testval2} = Set',
414 'TESTVAR{testval2 testval3} = Unset',
415 'TESTVAR{testval2} = Set',
416 'TESTVAR{testval3} = Unset'
417 ]))
418 # Check final value
419 self.assertEqual(self.d.getVar('ANOTHERVAR').split(), ['anothervalue', 'yetanothervalue', 'lastone'])
420
373 #Currently no wildcard support 421 #Currently no wildcard support
374 #def test_vardeps_wildcards(self): 422 #def test_vardeps_wildcards(self):
375 # self.d.setVar("oe_libinstall", "echo test") 423 # self.d.setVar("oe_libinstall", "echo test")