blob: 74b2098ae8b06b3e06dd4e9948c87cfcf2f5bb71 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
4
Brad Bishop19323692019-04-05 15:28:33 -04005import bb.tinfoil
6
7from oeqa.selftest.case import OESelftestTestCase
Patrick Williams45852732022-04-02 08:58:32 -05008from oeqa.utils.commands import get_test_layer
Brad Bishop19323692019-04-05 15:28:33 -04009
10
11def setUpModule():
12 global tinfoil
13 global metaselftestpath
14 metaselftestpath = get_test_layer()
15 tinfoil = bb.tinfoil.Tinfoil(tracking=True)
16 tinfoil.prepare(config_only=False, quiet=2)
17
18
19def tearDownModule():
20 tinfoil.shutdown()
21
22
23class RecipeUtilsTests(OESelftestTestCase):
24 """ Tests for the recipeutils module functions """
25
26 def test_patch_recipe_varflag(self):
27 import oe.recipeutils
28 rd = tinfoil.parse_recipe('python3-async-test')
29 vals = {'SRC_URI[md5sum]': 'aaaaaa', 'LICENSE': 'something'}
30 patches = oe.recipeutils.patch_recipe(rd, rd.getVar('FILE'), vals, patch=True, relpath=metaselftestpath)
31
32 expected_patch = """
33--- a/recipes-devtools/python/python-async-test.inc
34+++ b/recipes-devtools/python/python-async-test.inc
35@@ -1,14 +1,14 @@
36 SUMMARY = "Python framework to process interdependent tasks in a pool of workers"
37 HOMEPAGE = "http://github.com/gitpython-developers/async"
38 SECTION = "devel/python"
Andrew Geissler5199d832021-09-24 16:47:35 -050039-LICENSE = "BSD-3-Clause"
Brad Bishop19323692019-04-05 15:28:33 -040040+LICENSE = "something"
41 LIC_FILES_CHKSUM = "file://PKG-INFO;beginline=8;endline=8;md5=88df8e78b9edfd744953862179f2d14e"
42
43 inherit pypi
44
45 PYPI_PACKAGE = "async"
46
47-SRC_URI[md5sum] = "9b06b5997de2154f3bc0273f80bcef6b"
48+SRC_URI[md5sum] = "aaaaaa"
49 SRC_URI[sha256sum] = "ac6894d876e45878faae493b0cf61d0e28ec417334448ac0a6ea2229d8343051"
50
Patrick Williams213cb262021-08-07 19:21:33 -050051 RDEPENDS:${PN} += "${PYTHON_PN}-threading"
Brad Bishop19323692019-04-05 15:28:33 -040052"""
53 patchlines = []
54 for f in patches:
55 for line in f:
56 patchlines.append(line)
57 self.maxDiff = None
58 self.assertEqual(''.join(patchlines).strip(), expected_patch.strip())
59
60
61 def test_patch_recipe_singleappend(self):
62 import oe.recipeutils
63 rd = tinfoil.parse_recipe('recipeutils-test')
64 val = rd.getVar('SRC_URI', False).split()
65 del val[1]
66 val = ' '.join(val)
67 vals = {'SRC_URI': val}
68 patches = oe.recipeutils.patch_recipe(rd, rd.getVar('FILE'), vals, patch=True, relpath=metaselftestpath)
69
70 expected_patch = """
71--- a/recipes-test/recipeutils/recipeutils-test_1.2.bb
72+++ b/recipes-test/recipeutils/recipeutils-test_1.2.bb
73@@ -8,6 +8,4 @@
74
75 BBCLASSEXTEND = "native nativesdk"
76
77-SRC_URI += "file://somefile"
78-
Patrick Williams213cb262021-08-07 19:21:33 -050079 SRC_URI:append = " file://anotherfile"
Brad Bishop19323692019-04-05 15:28:33 -040080"""
81 patchlines = []
82 for f in patches:
83 for line in f:
84 patchlines.append(line)
85 self.assertEqual(''.join(patchlines).strip(), expected_patch.strip())
86
87
88 def test_patch_recipe_appends(self):
89 import oe.recipeutils
90 rd = tinfoil.parse_recipe('recipeutils-test')
91 val = rd.getVar('SRC_URI', False).split()
92 vals = {'SRC_URI': val[0]}
93 patches = oe.recipeutils.patch_recipe(rd, rd.getVar('FILE'), vals, patch=True, relpath=metaselftestpath)
94
95 expected_patch = """
96--- a/recipes-test/recipeutils/recipeutils-test_1.2.bb
97+++ b/recipes-test/recipeutils/recipeutils-test_1.2.bb
98@@ -8,6 +8,3 @@
99
100 BBCLASSEXTEND = "native nativesdk"
101
102-SRC_URI += "file://somefile"
103-
Patrick Williams213cb262021-08-07 19:21:33 -0500104-SRC_URI:append = " file://anotherfile"
Brad Bishop19323692019-04-05 15:28:33 -0400105"""
106 patchlines = []
107 for f in patches:
108 for line in f:
109 patchlines.append(line)
110 self.assertEqual(''.join(patchlines).strip(), expected_patch.strip())
111
112
113 def test_validate_pn(self):
114 import oe.recipeutils
115 expected_results = {
116 'test': '',
117 'glib-2.0': '',
118 'gtk+': '',
119 'forcevariable': 'reserved',
120 'pn-something': 'reserved',
121 'test.bb': 'file',
122 'test_one': 'character',
123 'test!': 'character',
124 }
125
126 for pn, expected in expected_results.items():
127 result = oe.recipeutils.validate_pn(pn)
128 if expected:
129 self.assertIn(expected, result)
130 else:
131 self.assertEqual(result, '')
132
133 def test_split_var_value(self):
134 import oe.recipeutils
135 res = oe.recipeutils.split_var_value('test.1 test.2 ${@call_function("hi there world", false)} test.4')
136 self.assertEqual(res, ['test.1', 'test.2', '${@call_function("hi there world", false)}', 'test.4'])