blob: 6beb76a48db13cb106b7825cb6b27faec7358834 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3#
4# BitBake Test for lib/bb/parse/
5#
6# Copyright (C) 2015 Richard Purdie
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License version 2 as
10# published by the Free Software Foundation.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License along
18# with this program; if not, write to the Free Software Foundation, Inc.,
19# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20#
21
22import unittest
23import tempfile
24import logging
25import bb
26import os
27
28logger = logging.getLogger('BitBake.TestParse')
29
30import bb.parse
31import bb.data
32import bb.siggen
33
34class ParseTest(unittest.TestCase):
35
36 testfile = """
37A = "1"
38B = "2"
39do_install() {
40 echo "hello"
41}
42
43C = "3"
44"""
45
46 def setUp(self):
47 self.d = bb.data.init()
48 bb.parse.siggen = bb.siggen.init(self.d)
49
50 def parsehelper(self, content, suffix = ".bb"):
51
52 f = tempfile.NamedTemporaryFile(suffix = suffix)
53 f.write(content)
54 f.flush()
55 os.chdir(os.path.dirname(f.name))
56 return f
57
58 def test_parse_simple(self):
59 f = self.parsehelper(self.testfile)
60 d = bb.parse.handle(f.name, self.d)['']
61 self.assertEqual(d.getVar("A", True), "1")
62 self.assertEqual(d.getVar("B", True), "2")
63 self.assertEqual(d.getVar("C", True), "3")
64
65 def test_parse_incomplete_function(self):
66 testfileB = self.testfile.replace("}", "")
67 f = self.parsehelper(testfileB)
68 with self.assertRaises(bb.parse.ParseError):
69 d = bb.parse.handle(f.name, self.d)['']
70
71 overridetest = """
72RRECOMMENDS_${PN} = "a"
73RRECOMMENDS_${PN}_libc = "b"
74OVERRIDES = "libc:${PN}"
75PN = "gtk+"
76"""
77
78 def test_parse_overrides(self):
79 f = self.parsehelper(self.overridetest)
80 d = bb.parse.handle(f.name, self.d)['']
81 self.assertEqual(d.getVar("RRECOMMENDS", True), "b")
82 bb.data.expandKeys(d)
83 self.assertEqual(d.getVar("RRECOMMENDS", True), "b")
84 d.setVar("RRECOMMENDS_gtk+", "c")
85 self.assertEqual(d.getVar("RRECOMMENDS", True), "c")
86
87 overridetest2 = """
88EXTRA_OECONF = ""
89EXTRA_OECONF_class-target = "b"
90EXTRA_OECONF_append = " c"
91"""
92
93 def test_parse_overrides(self):
94 f = self.parsehelper(self.overridetest2)
95 d = bb.parse.handle(f.name, self.d)['']
96 d.appendVar("EXTRA_OECONF", " d")
97 d.setVar("OVERRIDES", "class-target")
98 self.assertEqual(d.getVar("EXTRA_OECONF", True), "b c d")
99
100 overridetest3 = """
101DESCRIPTION = "A"
102DESCRIPTION_${PN}-dev = "${DESCRIPTION} B"
103PN = "bc"
104"""
105
106 def test_parse_combinations(self):
107 f = self.parsehelper(self.overridetest3)
108 d = bb.parse.handle(f.name, self.d)['']
109 bb.data.expandKeys(d)
110 self.assertEqual(d.getVar("DESCRIPTION_bc-dev", True), "A B")
111 d.setVar("DESCRIPTION", "E")
112 d.setVar("DESCRIPTION_bc-dev", "C D")
113 d.setVar("OVERRIDES", "bc-dev")
114 self.assertEqual(d.getVar("DESCRIPTION", True), "C D")
115
116
117 classextend = """
118VAR_var_override1 = "B"
119EXTRA = ":override1"
120OVERRIDES = "nothing${EXTRA}"
121
122BBCLASSEXTEND = "###CLASS###"
123"""
124 classextend_bbclass = """
125EXTRA = ""
126python () {
127 d.renameVar("VAR_var", "VAR_var2")
128}
129"""
130
131 #
132 # Test based upon a real world data corruption issue. One
133 # data store changing a variable poked through into a different data
134 # store. This test case replicates that issue where the value 'B' would
135 # become unset/disappear.
136 #
137 def test_parse_classextend_contamination(self):
138 cls = self.parsehelper(self.classextend_bbclass, suffix=".bbclass")
139 #clsname = os.path.basename(cls.name).replace(".bbclass", "")
140 self.classextend = self.classextend.replace("###CLASS###", cls.name)
141 f = self.parsehelper(self.classextend)
142 alldata = bb.parse.handle(f.name, self.d)
143 d1 = alldata['']
144 d2 = alldata[cls.name]
145 self.assertEqual(d1.getVar("VAR_var", True), "B")
146 self.assertEqual(d2.getVar("VAR_var", True), None)
147