summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb
diff options
context:
space:
mode:
authorSavvas Etairidis <falital@hotmail.com>2024-09-25 07:43:34 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-01-28 14:34:36 +0000
commit934828e9638c2ac727618dbe0801ca073668c3a7 (patch)
treecce774d20eb140077f8a481c409494b03d53d57f /bitbake/lib/bb
parent2960300ba09a56cb8d838607b3bbecb5cf90e07a (diff)
downloadpoky-934828e9638c2ac727618dbe0801ca073668c3a7.tar.gz
bitbake: tests/parse: Add test for unclosed functions
This test covers the handling of unclosed functions. It tests that both whitespace and tabs generate the correct exception if added before a closing bracket. Additionally that a residue blocks generates a error is tested as well. [YOCTO #15470] (Bitbake rev: 29e67acb87ae76879efe9688a69c961a96df10f1) Signed-off-by: Savvas Etairidis <falital@hotmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb')
-rw-r--r--bitbake/lib/bb/tests/parse.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/bitbake/lib/bb/tests/parse.py b/bitbake/lib/bb/tests/parse.py
index 935c85ac7c..cb60af3641 100644
--- a/bitbake/lib/bb/tests/parse.py
+++ b/bitbake/lib/bb/tests/parse.py
@@ -401,3 +401,45 @@ EXPORT_FUNCTIONS do_compile do_compilepython
401 self.assertIn("else", d.getVar("do_compilepython")) 401 self.assertIn("else", d.getVar("do_compilepython"))
402 check_function_flags(d) 402 check_function_flags(d)
403 403
404 export_function_unclosed_tab = """
405do_compile () {
406 bb.note("Something")
407\t}
408"""
409 export_function_unclosed_space = """
410do_compile () {
411 bb.note("Something")
412 }
413"""
414 export_function_residue = """
415do_compile () {
416 bb.note("Something")
417}
418
419include \\
420"""
421
422 def test_unclosed_functions(self):
423 def test_helper(content, expected_error):
424 with tempfile.TemporaryDirectory() as tempdir:
425 recipename = tempdir + "/recipe_unclosed.bb"
426 with open(recipename, "w") as f:
427 f.write(content)
428 f.flush()
429 os.chdir(tempdir)
430 with self.assertRaises(bb.parse.ParseError) as error:
431 bb.parse.handle(recipename, bb.data.createCopy(self.d))
432 self.assertIn(expected_error, str(error.exception))
433
434 with tempfile.TemporaryDirectory() as tempdir:
435 test_helper(self.export_function_unclosed_tab, "Unparsed lines from unclosed function")
436 test_helper(self.export_function_unclosed_space, "Unparsed lines from unclosed function")
437 test_helper(self.export_function_residue, "Unparsed lines")
438
439 recipename_closed = tempdir + "/recipe_closed.bb"
440 with open(recipename_closed, "w") as in_file:
441 lines = self.export_function_unclosed_tab.split("\n")
442 lines[3] = "}"
443 in_file.write("\n".join(lines))
444 in_file.flush()
445 bb.parse.handle(recipename_closed, bb.data.createCopy(self.d))