summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2012-05-04 16:18:55 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-05-04 16:58:35 +0100
commit12ebec4c940f37b17bc565299347dddf44cd1b90 (patch)
tree6c75ca9ddda98353378e2b77c95738917a96e39c
parent2ee0d3f05405602ab0ec73aef150e9643fff04c2 (diff)
downloadpoky-12ebec4c940f37b17bc565299347dddf44cd1b90.tar.gz
bitbake: Add start of bitbake regression/self testing
This adds some basic unit testing for the codeparser and data store code. Many of the actual test cases were taken from work by Chris Larson's OE-Signatures work but with changes to adapt to the current bitbake APIs we need to test. I also imported CoW tests written by Holger Freyther from the original bitbake-test codebase: http://svn.berlios.de/wsvn/bitbake/trunk/bitbake-tests/tests/ and some tests from the doctests that were removed in commit: http://git.openembedded.org/bitbake/commit?id=3a11c2807972bbbddffde2fa67fc380d159da467 (Bitbake rev: ae4a95780e3e08cf73c854efa8cd93379e00c4e5) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/bin/bitbake-selftest38
-rw-r--r--bitbake/lib/bb/tests/codeparser.py369
-rw-r--r--bitbake/lib/bb/tests/cow.py134
-rw-r--r--bitbake/lib/bb/tests/data.py252
-rw-r--r--bitbake/lib/bb/tests/fetch.py42
-rw-r--r--bitbake/lib/bb/tests/utils.py36
6 files changed, 871 insertions, 0 deletions
diff --git a/bitbake/bin/bitbake-selftest b/bitbake/bin/bitbake-selftest
new file mode 100644
index 0000000000..48a58fef67
--- /dev/null
+++ b/bitbake/bin/bitbake-selftest
@@ -0,0 +1,38 @@
1#!/usr/bin/env python
2#
3# Copyright (C) 2012 Richard Purdie
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 2 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program; if not, write to the Free Software Foundation, Inc.,
16# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18import os
19import sys, logging
20sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), 'lib'))
21
22import unittest
23try:
24 import bb
25except RuntimeError as exc:
26 sys.exit(str(exc))
27
28tests = ["bb.tests.codeparser",
29 "bb.tests.cow",
30 "bb.tests.data",
31 "bb.tests.fetch",
32 "bb.tests.utils"]
33
34for t in tests:
35 __import__(t)
36
37unittest.main(argv=["bitbake-selftest"] + tests)
38
diff --git a/bitbake/lib/bb/tests/codeparser.py b/bitbake/lib/bb/tests/codeparser.py
new file mode 100644
index 0000000000..9b2d5886c0
--- /dev/null
+++ b/bitbake/lib/bb/tests/codeparser.py
@@ -0,0 +1,369 @@
1#
2# BitBake Test for codeparser.py
3#
4# Copyright (C) 2010 Chris Larson
5# Copyright (C) 2012 Richard Purdie
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License version 2 as
9# published by the Free Software Foundation.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License along
17# with this program; if not, write to the Free Software Foundation, Inc.,
18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19#
20
21import unittest
22import logging
23import bb
24
25logger = logging.getLogger('BitBake.TestCodeParser')
26
27import bb.data
28
29class ReferenceTest(unittest.TestCase):
30 def setUp(self):
31 self.d = bb.data.init()
32
33 def setEmptyVars(self, varlist):
34 for k in varlist:
35 self.d.setVar(k, "")
36
37 def setValues(self, values):
38 for k, v in values.items():
39 self.d.setVar(k, v)
40
41 def assertReferences(self, refs):
42 self.assertEqual(self.references, refs)
43
44 def assertExecs(self, execs):
45 self.assertEqual(self.execs, execs)
46
47class VariableReferenceTest(ReferenceTest):
48
49 def parseExpression(self, exp):
50 parsedvar = self.d.expandWithRefs(exp, None)
51 self.references = parsedvar.references
52
53 def test_simple_reference(self):
54 self.setEmptyVars(["FOO"])
55 self.parseExpression("${FOO}")
56 self.assertReferences(set(["FOO"]))
57
58 def test_nested_reference(self):
59 self.setEmptyVars(["BAR"])
60 self.d.setVar("FOO", "BAR")
61 self.parseExpression("${${FOO}}")
62 self.assertReferences(set(["FOO", "BAR"]))
63
64 def test_python_reference(self):
65 self.setEmptyVars(["BAR"])
66 self.parseExpression("${@bb.data.getVar('BAR', d, True) + 'foo'}")
67 self.assertReferences(set(["BAR"]))
68
69class ShellReferenceTest(ReferenceTest):
70
71 def parseExpression(self, exp):
72 parsedvar = self.d.expandWithRefs(exp, None)
73 parser = bb.codeparser.ShellParser("ParserTest", logger)
74 parser.parse_shell(parsedvar.value)
75
76 self.references = parsedvar.references
77 self.execs = parser.execs
78
79 def test_quotes_inside_assign(self):
80 self.parseExpression('foo=foo"bar"baz')
81 self.assertReferences(set([]))
82
83 def test_quotes_inside_arg(self):
84 self.parseExpression('sed s#"bar baz"#"alpha beta"#g')
85 self.assertExecs(set(["sed"]))
86
87 def test_arg_continuation(self):
88 self.parseExpression("sed -i -e s,foo,bar,g \\\n *.pc")
89 self.assertExecs(set(["sed"]))
90
91 def test_dollar_in_quoted(self):
92 self.parseExpression('sed -i -e "foo$" *.pc')
93 self.assertExecs(set(["sed"]))
94
95 def test_quotes_inside_arg_continuation(self):
96 self.setEmptyVars(["bindir", "D", "libdir"])
97 self.parseExpression("""
98sed -i -e s#"moc_location=.*$"#"moc_location=${bindir}/moc4"# \\
99-e s#"uic_location=.*$"#"uic_location=${bindir}/uic4"# \\
100${D}${libdir}/pkgconfig/*.pc
101""")
102 self.assertReferences(set(["bindir", "D", "libdir"]))
103
104 def test_assign_subshell_expansion(self):
105 self.parseExpression("foo=$(echo bar)")
106 self.assertExecs(set(["echo"]))
107
108 def test_shell_unexpanded(self):
109 self.setEmptyVars(["QT_BASE_NAME"])
110 self.parseExpression('echo "${QT_BASE_NAME}"')
111 self.assertExecs(set(["echo"]))
112 self.assertReferences(set(["QT_BASE_NAME"]))
113
114 def test_incomplete_varexp_single_quotes(self):
115 self.parseExpression("sed -i -e 's:IP{:I${:g' $pc")
116 self.assertExecs(set(["sed"]))
117
118
119 def test_until(self):
120 self.parseExpression("until false; do echo true; done")
121 self.assertExecs(set(["false", "echo"]))
122 self.assertReferences(set())
123
124 def test_case(self):
125 self.parseExpression("""
126case $foo in
127*)
128bar
129;;
130esac
131""")
132 self.assertExecs(set(["bar"]))
133 self.assertReferences(set())
134
135 def test_assign_exec(self):
136 self.parseExpression("a=b c='foo bar' alpha 1 2 3")
137 self.assertExecs(set(["alpha"]))
138
139 def test_redirect_to_file(self):
140 self.setEmptyVars(["foo"])
141 self.parseExpression("echo foo >${foo}/bar")
142 self.assertExecs(set(["echo"]))
143 self.assertReferences(set(["foo"]))
144
145 def test_heredoc(self):
146 self.setEmptyVars(["theta"])
147 self.parseExpression("""
148cat <<END
149alpha
150beta
151${theta}
152END
153""")
154 self.assertReferences(set(["theta"]))
155
156 def test_redirect_from_heredoc(self):
157 v = ["B", "SHADOW_MAILDIR", "SHADOW_MAILFILE", "SHADOW_UTMPDIR", "SHADOW_LOGDIR", "bindir"]
158 self.setEmptyVars(v)
159 self.parseExpression("""
160cat <<END >${B}/cachedpaths
161shadow_cv_maildir=${SHADOW_MAILDIR}
162shadow_cv_mailfile=${SHADOW_MAILFILE}
163shadow_cv_utmpdir=${SHADOW_UTMPDIR}
164shadow_cv_logdir=${SHADOW_LOGDIR}
165shadow_cv_passwd_dir=${bindir}
166END
167""")
168 self.assertReferences(set(v))
169 self.assertExecs(set(["cat"]))
170
171# def test_incomplete_command_expansion(self):
172# self.assertRaises(reftracker.ShellSyntaxError, reftracker.execs,
173# bbvalue.shparse("cp foo`", self.d), self.d)
174
175# def test_rogue_dollarsign(self):
176# self.setValues({"D" : "/tmp"})
177# self.parseExpression("install -d ${D}$")
178# self.assertReferences(set(["D"]))
179# self.assertExecs(set(["install"]))
180
181
182class PythonReferenceTest(ReferenceTest):
183
184 def setUp(self):
185 self.d = bb.data.init()
186 if hasattr(bb.utils, "_context"):
187 self.context = bb.utils._context
188 else:
189 import __builtin__
190 self.context = __builtin__.__dict__
191
192 def parseExpression(self, exp):
193 parsedvar = self.d.expandWithRefs(exp, None)
194 parser = bb.codeparser.PythonParser("ParserTest", logger)
195 parser.parse_python(parsedvar.value)
196
197 self.references = parsedvar.references | parser.references
198 self.execs = parser.execs
199
200 @staticmethod
201 def indent(value):
202 """Python Snippets have to be indented, python values don't have to
203be. These unit tests are testing snippets."""
204 return " " + value
205
206 def test_getvar_reference(self):
207 self.parseExpression("bb.data.getVar('foo', d, True)")
208 self.assertReferences(set(["foo"]))
209 self.assertExecs(set())
210
211 def test_getvar_computed_reference(self):
212 self.parseExpression("bb.data.getVar('f' + 'o' + 'o', d, True)")
213 self.assertReferences(set())
214 self.assertExecs(set())
215
216 def test_getvar_exec_reference(self):
217 self.parseExpression("eval('bb.data.getVar(\"foo\", d, True)')")
218 self.assertReferences(set())
219 self.assertExecs(set(["eval"]))
220
221 def test_var_reference(self):
222 self.context["foo"] = lambda x: x
223 self.setEmptyVars(["FOO"])
224 self.parseExpression("foo('${FOO}')")
225 self.assertReferences(set(["FOO"]))
226 self.assertExecs(set(["foo"]))
227 del self.context["foo"]
228
229 def test_var_exec(self):
230 for etype in ("func", "task"):
231 self.d.setVar("do_something", "echo 'hi mom! ${FOO}'")
232 self.d.setVarFlag("do_something", etype, True)
233 self.parseExpression("bb.build.exec_func('do_something', d)")
234 self.assertReferences(set(["do_something"]))
235
236 def test_function_reference(self):
237 self.context["testfunc"] = lambda msg: bb.msg.note(1, None, msg)
238 self.d.setVar("FOO", "Hello, World!")
239 self.parseExpression("testfunc('${FOO}')")
240 self.assertReferences(set(["FOO"]))
241 self.assertExecs(set(["testfunc"]))
242 del self.context["testfunc"]
243
244 def test_qualified_function_reference(self):
245 self.parseExpression("time.time()")
246 self.assertExecs(set(["time.time"]))
247
248 def test_qualified_function_reference_2(self):
249 self.parseExpression("os.path.dirname('/foo/bar')")
250 self.assertExecs(set(["os.path.dirname"]))
251
252 def test_qualified_function_reference_nested(self):
253 self.parseExpression("time.strftime('%Y%m%d',time.gmtime())")
254 self.assertExecs(set(["time.strftime", "time.gmtime"]))
255
256 def test_function_reference_chained(self):
257 self.context["testget"] = lambda: "\tstrip me "
258 self.parseExpression("testget().strip()")
259 self.assertExecs(set(["testget"]))
260 del self.context["testget"]
261
262
263class DependencyReferenceTest(ReferenceTest):
264
265 pydata = """
266bb.data.getVar('somevar', d, True)
267def test(d):
268 foo = 'bar %s' % 'foo'
269def test2(d):
270 d.getVar(foo, True)
271 d.getVar('bar', False)
272 test2(d)
273
274def a():
275 \"\"\"some
276 stuff
277 \"\"\"
278 return "heh"
279
280test(d)
281
282bb.data.expand(bb.data.getVar("something", False, d), d)
283bb.data.expand("${inexpand} somethingelse", d)
284bb.data.getVar(a(), d, False)
285"""
286
287 def test_python(self):
288 self.d.setVar("FOO", self.pydata)
289 self.setEmptyVars(["inexpand", "a", "test2", "test"])
290 self.d.setVarFlags("FOO", {"func": True, "python": True})
291
292 deps, values = bb.data.build_dependencies("FOO", set(self.d.keys()), set(), set(), self.d)
293
294 self.assertEquals(deps, set(["somevar", "bar", "something", "inexpand", "test", "test2", "a"]))
295
296
297 shelldata = """
298foo () {
299bar
300}
301{
302echo baz
303$(heh)
304eval `moo`
305}
306a=b
307c=d
308(
309true && false
310test -f foo
311testval=something
312$testval
313) || aiee
314! inverted
315echo ${somevar}
316
317case foo in
318bar)
319echo bar
320;;
321baz)
322echo baz
323;;
324foo*)
325echo foo
326;;
327esac
328"""
329
330 def test_shell(self):
331 execs = ["bar", "echo", "heh", "moo", "true", "aiee"]
332 self.d.setVar("somevar", "heh")
333 self.d.setVar("inverted", "echo inverted...")
334 self.d.setVarFlag("inverted", "func", True)
335 self.d.setVar("FOO", self.shelldata)
336 self.d.setVarFlags("FOO", {"func": True})
337 self.setEmptyVars(execs)
338
339 deps, values = bb.data.build_dependencies("FOO", set(self.d.keys()), set(), set(), self.d)
340
341 self.assertEquals(deps, set(["somevar", "inverted"] + execs))
342
343
344 def test_vardeps(self):
345 self.d.setVar("oe_libinstall", "echo test")
346 self.d.setVar("FOO", "foo=oe_libinstall; eval $foo")
347 self.d.setVarFlag("FOO", "vardeps", "oe_libinstall")
348
349 deps, values = bb.data.build_dependencies("FOO", set(self.d.keys()), set(), set(), self.d)
350
351 self.assertEquals(deps, set(["oe_libinstall"]))
352
353 def test_vardeps_expand(self):
354 self.d.setVar("oe_libinstall", "echo test")
355 self.d.setVar("FOO", "foo=oe_libinstall; eval $foo")
356 self.d.setVarFlag("FOO", "vardeps", "${@'oe_libinstall'}")
357
358 deps, values = bb.data.build_dependencies("FOO", set(self.d.keys()), set(), set(), self.d)
359
360 self.assertEquals(deps, set(["oe_libinstall"]))
361
362 #Currently no wildcard support
363 #def test_vardeps_wildcards(self):
364 # self.d.setVar("oe_libinstall", "echo test")
365 # self.d.setVar("FOO", "foo=oe_libinstall; eval $foo")
366 # self.d.setVarFlag("FOO", "vardeps", "oe_*")
367 # self.assertEquals(deps, set(["oe_libinstall"]))
368
369
diff --git a/bitbake/lib/bb/tests/cow.py b/bitbake/lib/bb/tests/cow.py
new file mode 100644
index 0000000000..599b2aabaf
--- /dev/null
+++ b/bitbake/lib/bb/tests/cow.py
@@ -0,0 +1,134 @@
1#
2# BitBake Tests for Copy-on-Write (cow.py)
3#
4# Copyright 2006 Holger Freyther <freyther@handhelds.org>
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License version 2 as
8# published by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18#
19
20import unittest
21import os
22
23class COWTestCase(unittest.TestCase):
24 """
25 Test case for the COW module from mithro
26 """
27
28 def testGetSet(self):
29 """
30 Test and set
31 """
32 from bb.COW import COWDictBase
33 a = COWDictBase.copy()
34
35 self.assertEquals(False, a.has_key('a'))
36
37 a['a'] = 'a'
38 a['b'] = 'b'
39 self.assertEquals(True, a.has_key('a'))
40 self.assertEquals(True, a.has_key('b'))
41 self.assertEquals('a', a['a'] )
42 self.assertEquals('b', a['b'] )
43
44 def testCopyCopy(self):
45 """
46 Test the copy of copies
47 """
48
49 from bb.COW import COWDictBase
50
51 # create two COW dict 'instances'
52 b = COWDictBase.copy()
53 c = COWDictBase.copy()
54
55 # assign some keys to one instance, some keys to another
56 b['a'] = 10
57 b['c'] = 20
58 c['a'] = 30
59
60 # test separation of the two instances
61 self.assertEquals(False, c.has_key('c'))
62 self.assertEquals(30, c['a'])
63 self.assertEquals(10, b['a'])
64
65 # test copy
66 b_2 = b.copy()
67 c_2 = c.copy()
68
69 self.assertEquals(False, c_2.has_key('c'))
70 self.assertEquals(10, b_2['a'])
71
72 b_2['d'] = 40
73 self.assertEquals(False, c_2.has_key('d'))
74 self.assertEquals(True, b_2.has_key('d'))
75 self.assertEquals(40, b_2['d'])
76 self.assertEquals(False, b.has_key('d'))
77 self.assertEquals(False, c.has_key('d'))
78
79 c_2['d'] = 30
80 self.assertEquals(True, c_2.has_key('d'))
81 self.assertEquals(True, b_2.has_key('d'))
82 self.assertEquals(30, c_2['d'])
83 self.assertEquals(40, b_2['d'])
84 self.assertEquals(False, b.has_key('d'))
85 self.assertEquals(False, c.has_key('d'))
86
87 # test copy of the copy
88 c_3 = c_2.copy()
89 b_3 = b_2.copy()
90 b_3_2 = b_2.copy()
91
92 c_3['e'] = 4711
93 self.assertEquals(4711, c_3['e'])
94 self.assertEquals(False, c_2.has_key('e'))
95 self.assertEquals(False, b_3.has_key('e'))
96 self.assertEquals(False, b_3_2.has_key('e'))
97 self.assertEquals(False, b_2.has_key('e'))
98
99 b_3['e'] = 'viel'
100 self.assertEquals('viel', b_3['e'])
101 self.assertEquals(4711, c_3['e'])
102 self.assertEquals(False, c_2.has_key('e'))
103 self.assertEquals(True, b_3.has_key('e'))
104 self.assertEquals(False, b_3_2.has_key('e'))
105 self.assertEquals(False, b_2.has_key('e'))
106
107 def testCow(self):
108 from bb.COW import COWDictBase
109 c = COWDictBase.copy()
110 c['123'] = 1027
111 c['other'] = 4711
112 c['d'] = { 'abc' : 10, 'bcd' : 20 }
113
114 copy = c.copy()
115
116 self.assertEquals(1027, c['123'])
117 self.assertEquals(4711, c['other'])
118 self.assertEquals({'abc':10, 'bcd':20}, c['d'])
119 self.assertEquals(1027, copy['123'])
120 self.assertEquals(4711, copy['other'])
121 self.assertEquals({'abc':10, 'bcd':20}, copy['d'])
122
123 # cow it now
124 copy['123'] = 1028
125 copy['other'] = 4712
126 copy['d']['abc'] = 20
127
128
129 self.assertEquals(1027, c['123'])
130 self.assertEquals(4711, c['other'])
131 self.assertEquals({'abc':10, 'bcd':20}, c['d'])
132 self.assertEquals(1028, copy['123'])
133 self.assertEquals(4712, copy['other'])
134 self.assertEquals({'abc':20, 'bcd':20}, copy['d'])
diff --git a/bitbake/lib/bb/tests/data.py b/bitbake/lib/bb/tests/data.py
new file mode 100644
index 0000000000..b2ab8eeeb8
--- /dev/null
+++ b/bitbake/lib/bb/tests/data.py
@@ -0,0 +1,252 @@
1#
2# BitBake Tests for the Data Store (data.py/data_smart.py)
3#
4# Copyright (C) 2010 Chris Larson
5# Copyright (C) 2012 Richard Purdie
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License version 2 as
9# published by the Free Software Foundation.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License along
17# with this program; if not, write to the Free Software Foundation, Inc.,
18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19#
20
21import unittest
22import bb
23import bb.data
24
25class DataExpansions(unittest.TestCase):
26 def setUp(self):
27 self.d = bb.data.init()
28 self.d["foo"] = "value of foo"
29 self.d["bar"] = "value of bar"
30 self.d["value of foo"] = "value of 'value of foo'"
31
32 def test_one_var(self):
33 val = self.d.expand("${foo}")
34 self.assertEqual(str(val), "value of foo")
35
36 def test_indirect_one_var(self):
37 val = self.d.expand("${${foo}}")
38 self.assertEqual(str(val), "value of 'value of foo'")
39
40 def test_indirect_and_another(self):
41 val = self.d.expand("${${foo}} ${bar}")
42 self.assertEqual(str(val), "value of 'value of foo' value of bar")
43
44 def test_python_snippet(self):
45 val = self.d.expand("${@5*12}")
46 self.assertEqual(str(val), "60")
47
48 def test_expand_in_python_snippet(self):
49 val = self.d.expand("${@'boo ' + '${foo}'}")
50 self.assertEqual(str(val), "boo value of foo")
51
52 def test_python_snippet_getvar(self):
53 val = self.d.expand("${@d.getVar('foo', True) + ' ${bar}'}")
54 self.assertEqual(str(val), "value of foo value of bar")
55
56 def test_python_snippet_syntax_error(self):
57 self.d.setVar("FOO", "${@foo = 5}")
58 self.assertRaises(bb.data_smart.ExpansionError, self.d.getVar, "FOO", True)
59
60 def test_python_snippet_runtime_error(self):
61 self.d.setVar("FOO", "${@int('test')}")
62 self.assertRaises(bb.data_smart.ExpansionError, self.d.getVar, "FOO", True)
63
64 def test_python_snippet_error_path(self):
65 self.d.setVar("FOO", "foo value ${BAR}")
66 self.d.setVar("BAR", "bar value ${@int('test')}")
67 self.assertRaises(bb.data_smart.ExpansionError, self.d.getVar, "FOO", True)
68
69 def test_value_containing_value(self):
70 val = self.d.expand("${@d.getVar('foo', True) + ' ${bar}'}")
71 self.assertEqual(str(val), "value of foo value of bar")
72
73 def test_reference_undefined_var(self):
74 val = self.d.expand("${undefinedvar} meh")
75 self.assertEqual(str(val), "${undefinedvar} meh")
76
77 def test_double_reference(self):
78 self.d.setVar("BAR", "bar value")
79 self.d.setVar("FOO", "${BAR} foo ${BAR}")
80 val = self.d.getVar("FOO", True)
81 self.assertEqual(str(val), "bar value foo bar value")
82
83 def test_direct_recursion(self):
84 self.d.setVar("FOO", "${FOO}")
85 self.assertRaises(bb.data_smart.ExpansionError, self.d.getVar, "FOO", True)
86
87 def test_indirect_recursion(self):
88 self.d.setVar("FOO", "${BAR}")
89 self.d.setVar("BAR", "${BAZ}")
90 self.d.setVar("BAZ", "${FOO}")
91 self.assertRaises(bb.data_smart.ExpansionError, self.d.getVar, "FOO", True)
92
93 def test_recursion_exception(self):
94 self.d.setVar("FOO", "${BAR}")
95 self.d.setVar("BAR", "${${@'FOO'}}")
96 self.assertRaises(bb.data_smart.ExpansionError, self.d.getVar, "FOO", True)
97
98 def test_incomplete_varexp_single_quotes(self):
99 self.d.setVar("FOO", "sed -i -e 's:IP{:I${:g' $pc")
100 val = self.d.getVar("FOO", True)
101 self.assertEqual(str(val), "sed -i -e 's:IP{:I${:g' $pc")
102
103 def test_nonstring(self):
104 self.d.setVar("TEST", 5)
105 val = self.d.getVar("TEST", True)
106 self.assertEqual(str(val), "5")
107
108 def test_rename(self):
109 self.d.renameVar("foo", "newfoo")
110 self.assertEqual(self.d.getVar("newfoo"), "value of foo")
111 self.assertEqual(self.d.getVar("foo"), None)
112
113 def test_deletion(self):
114 self.d.delVar("foo")
115 self.assertEqual(self.d.getVar("foo"), None)
116
117 def test_keys(self):
118 keys = self.d.keys()
119 self.assertEqual(keys, ['value of foo', 'foo', 'bar'])
120
121class TestNestedExpansions(unittest.TestCase):
122 def setUp(self):
123 self.d = bb.data.init()
124 self.d["foo"] = "foo"
125 self.d["bar"] = "bar"
126 self.d["value of foobar"] = "187"
127
128 def test_refs(self):
129 val = self.d.expand("${value of ${foo}${bar}}")
130 self.assertEqual(str(val), "187")
131
132 #def test_python_refs(self):
133 # val = self.d.expand("${@${@3}**2 + ${@4}**2}")
134 # self.assertEqual(str(val), "25")
135
136 def test_ref_in_python_ref(self):
137 val = self.d.expand("${@'${foo}' + 'bar'}")
138 self.assertEqual(str(val), "foobar")
139
140 def test_python_ref_in_ref(self):
141 val = self.d.expand("${${@'f'+'o'+'o'}}")
142 self.assertEqual(str(val), "foo")
143
144 def test_deep_nesting(self):
145 depth = 100
146 val = self.d.expand("${" * depth + "foo" + "}" * depth)
147 self.assertEqual(str(val), "foo")
148
149 #def test_deep_python_nesting(self):
150 # depth = 50
151 # val = self.d.expand("${@" * depth + "1" + "+1}" * depth)
152 # self.assertEqual(str(val), str(depth + 1))
153
154 def test_mixed(self):
155 val = self.d.expand("${value of ${@('${foo}'+'bar')[0:3]}${${@'BAR'.lower()}}}")
156 self.assertEqual(str(val), "187")
157
158 def test_runtime(self):
159 val = self.d.expand("${${@'value of' + ' f'+'o'+'o'+'b'+'a'+'r'}}")
160 self.assertEqual(str(val), "187")
161
162class TestMemoize(unittest.TestCase):
163 def test_memoized(self):
164 d = bb.data.init()
165 d.setVar("FOO", "bar")
166 self.assertTrue(d.getVar("FOO") is d.getVar("FOO"))
167
168 def test_not_memoized(self):
169 d1 = bb.data.init()
170 d2 = bb.data.init()
171 d1.setVar("FOO", "bar")
172 d2.setVar("FOO", "bar2")
173 self.assertTrue(d1.getVar("FOO") is not d2.getVar("FOO"))
174
175 def test_changed_after_memoized(self):
176 d = bb.data.init()
177 d.setVar("foo", "value of foo")
178 self.assertEqual(str(d.getVar("foo")), "value of foo")
179 d.setVar("foo", "second value of foo")
180 self.assertEqual(str(d.getVar("foo")), "second value of foo")
181
182 def test_same_value(self):
183 d = bb.data.init()
184 d.setVar("foo", "value of")
185 d.setVar("bar", "value of")
186 self.assertEqual(d.getVar("foo"),
187 d.getVar("bar"))
188
189class TestConcat(unittest.TestCase):
190 def setUp(self):
191 self.d = bb.data.init()
192 self.d.setVar("FOO", "foo")
193 self.d.setVar("VAL", "val")
194 self.d.setVar("BAR", "bar")
195
196 def test_prepend(self):
197 self.d.setVar("TEST", "${VAL}")
198 self.d.prependVar("TEST", "${FOO}:")
199 self.assertEqual(self.d.getVar("TEST", True), "foo:val")
200
201 def test_append(self):
202 self.d.setVar("TEST", "${VAL}")
203 self.d.appendVar("TEST", ":${BAR}")
204 self.assertEqual(self.d.getVar("TEST", True), "val:bar")
205
206 def test_multiple_append(self):
207 self.d.setVar("TEST", "${VAL}")
208 self.d.prependVar("TEST", "${FOO}:")
209 self.d.appendVar("TEST", ":val2")
210 self.d.appendVar("TEST", ":${BAR}")
211 self.assertEqual(self.d.getVar("TEST", True), "foo:val:val2:bar")
212
213class TestOverrides(unittest.TestCase):
214 def setUp(self):
215 self.d = bb.data.init()
216 self.d.setVar("OVERRIDES", "foo:bar:local")
217 self.d.setVar("TEST", "testvalue")
218
219 def test_no_override(self):
220 bb.data.update_data(self.d)
221 self.assertEqual(self.d.getVar("TEST", True), "testvalue")
222
223 def test_one_override(self):
224 self.d.setVar("TEST_bar", "testvalue2")
225 bb.data.update_data(self.d)
226 self.assertEqual(self.d.getVar("TEST", True), "testvalue2")
227
228 def test_multiple_override(self):
229 self.d.setVar("TEST_bar", "testvalue2")
230 self.d.setVar("TEST_local", "testvalue3")
231 self.d.setVar("TEST_foo", "testvalue4")
232 bb.data.update_data(self.d)
233 self.assertEqual(self.d.getVar("TEST", True), "testvalue3")
234
235
236class TestFlags(unittest.TestCase):
237 def setUp(self):
238 self.d = bb.data.init()
239 self.d.setVar("foo", "value of foo")
240 self.d.setVarFlag("foo", "flag1", "value of flag1")
241 self.d.setVarFlag("foo", "flag2", "value of flag2")
242
243 def test_setflag(self):
244 self.assertEqual(self.d.getVarFlag("foo", "flag1"), "value of flag1")
245 self.assertEqual(self.d.getVarFlag("foo", "flag2"), "value of flag2")
246
247 def test_delflag(self):
248 self.d.delVarFlag("foo", "flag2")
249 self.assertEqual(self.d.getVarFlag("foo", "flag1"), "value of flag1")
250 self.assertEqual(self.d.getVarFlag("foo", "flag2"), None)
251
252
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
new file mode 100644
index 0000000000..8bd3e89520
--- /dev/null
+++ b/bitbake/lib/bb/tests/fetch.py
@@ -0,0 +1,42 @@
1#
2# BitBake Tests for the Fetcher (fetch2/)
3#
4# Copyright (C) 2012 Richard Purdie
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License version 2 as
8# published by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18#
19
20import unittest
21import bb
22
23class URLHandle(unittest.TestCase):
24
25 datatable = {
26 "http://www.google.com/index.html" : ('http', 'www.google.com', '/index.html', '', '', {}),
27 "cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg" : ('cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', '', {'module': 'familiar/dist/ipkg'}),
28 "cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg" : ('cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', 'anonymous', {'tag': 'V0-99-81', 'module': 'familiar/dist/ipkg'})
29 }
30
31 def test_decodeurl(self):
32 for k, v in self.datatable.items():
33 result = bb.fetch.decodeurl(k)
34 self.assertEqual(result, v)
35
36 def test_encodeurl(self):
37 for k, v in self.datatable.items():
38 result = bb.fetch.encodeurl(v)
39 self.assertEqual(result, k)
40
41
42
diff --git a/bitbake/lib/bb/tests/utils.py b/bitbake/lib/bb/tests/utils.py
new file mode 100644
index 0000000000..04e8d5d4d2
--- /dev/null
+++ b/bitbake/lib/bb/tests/utils.py
@@ -0,0 +1,36 @@
1#
2# BitBake Tests for utils.py
3#
4# Copyright (C) 2012 Richard Purdie
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License version 2 as
8# published by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18#
19
20import unittest
21import bb
22
23class VerCmpString(unittest.TestCase):
24
25 def test_vercmpstring(self):
26 result = bb.utils.vercmp_string('1', '2')
27 self.assertTrue(result < 0)
28 result = bb.utils.vercmp_string('2', '1')
29 self.assertTrue(result > 0)
30 result = bb.utils.vercmp_string('1', '1.0')
31 self.assertTrue(result < 0)
32 result = bb.utils.vercmp_string('1', '1.1')
33 self.assertTrue(result < 0)
34 result = bb.utils.vercmp_string('1.1', '1_p2')
35 self.assertTrue(result < 0)
36