core-deps-latest: Pull gtkmm-3 from the gtkmm-3-24 branch
[jhbuild.git] / tests / tests.py
blob1745db1421346245d3c8197a3b3d3a676a4a9261
1 #! /usr/bin/env python2
2 # jhbuild - a tool to ease building collections of source packages
3 # Copyright (C) 2001-2006 James Henstridge
4 # Copyright (C) 2007-2008 Frederic Peters
6 # tests.py: unit tests
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 import os
24 import shutil
25 import logging
26 import subprocess
27 import sys
28 import tempfile
29 import unittest
31 import __builtin__
32 __builtin__.__dict__['_'] = lambda x: x
33 __builtin__.__dict__['N_'] = lambda x: x
35 __builtin__.__dict__['PKGDATADIR'] = None
36 __builtin__.__dict__['DATADIR'] = None
37 __builtin__.__dict__['SRCDIR'] = os.path.join(os.path.dirname(__file__), '..')
39 sys.path.insert(0, SRCDIR)
41 # Override jhbuild.utils.systeminstall with this module 'tests'
42 import jhbuild.utils.systeminstall
43 sys.modules['jhbuild.utils.systeminstall'] = sys.modules[__name__]
44 sys.modules['jhbuild.utils'].systeminstall = sys.modules[__name__]
46 from jhbuild.errors import UsageError, CommandError
47 from jhbuild.modtypes import Package
48 from jhbuild.modtypes.autotools import AutogenModule
49 from jhbuild.modtypes.distutils import DistutilsModule
50 import jhbuild.config
51 import jhbuild.frontends.terminal
52 import jhbuild.moduleset
53 import jhbuild.utils.cmds
54 import jhbuild.versioncontrol.tarball
56 def uencode(s):
57 if type(s) is unicode:
58 return s.encode(_encoding, 'replace')
59 else:
60 return s
62 def uprint(*args):
63 '''Print Unicode string encoded for the terminal'''
64 for s in args[:-1]:
65 print uencode(s),
66 s = args[-1]
67 print uencode(s)
68 __builtin__.__dict__['uprint'] = uprint
69 __builtin__.__dict__['uencode'] = uencode
72 import mock
74 if sys.platform.startswith('win'):
75 import jhbuild.utils.subprocess_win32 as subprocess_win32
76 class WindowsTestCase(unittest.TestCase):
77 '''Tests for Windows kludges.'''
78 def testCmdline2List(self):
79 cmdline = 'test "no quotes" != \\"no\\ quotes\\"'
80 cmd_list = subprocess_win32.cmdline2list (cmdline)
81 self.assertEqual (cmd_list, ['test', 'no quotes', '!=', '"no\\ quotes"'])
83 class TestConfig(jhbuild.config.Config):
85 # The Config base class calls setup_env() in the constructor, but
86 # we need to override some attributes before calling it.
87 def setup_env(self):
88 pass
90 def real_setup_env(self):
91 from jhbuild.environment import setup_env
92 setup_env(self.prefix)
94 class JhbuildConfigTestCase(unittest.TestCase):
95 """A test case that creates a mock configuration and temporary directory."""
97 def setUp(self):
98 self.config = mock.Config()
99 self._old_env = os.environ.copy()
100 self._temp_dirs = []
102 def tearDown(self):
103 restore_environ(self._old_env)
104 for temp_dir in self._temp_dirs:
105 shutil.rmtree(temp_dir)
107 def make_temp_dir(self):
108 temp_dir = tempfile.mkdtemp(prefix='unittest-')
109 self._temp_dirs.append(temp_dir)
110 return temp_dir
112 def make_config(self):
113 temp_dir = self.make_temp_dir()
114 config = TestConfig(None, [])
115 config.checkoutroot = os.path.abspath(os.path.join(temp_dir, 'checkout'))
116 config.prefix = os.path.abspath(os.path.join(temp_dir, 'prefix'))
117 config.top_builddir = os.path.join(config.prefix, '_jhbuild')
118 os.makedirs(config.checkoutroot)
119 os.makedirs(config.prefix)
120 config.interact = False
121 config.quiet_mode = True # Not enough to disable output entirely
122 config.progress_bar = False
123 config.real_setup_env()
124 return config
126 def make_branch(self, config, src_name):
127 branch_dir = os.path.join(config.checkoutroot, src_name)
128 shutil.copytree(os.path.join(os.path.dirname(__file__), src_name),
129 branch_dir)
130 return SimpleBranch(src_name, branch_dir)
132 def make_terminal_buildscript(self, config, module_list):
133 module_set = jhbuild.moduleset.load(config)
134 module_set.packagedb = mock.PackageDB()
135 return jhbuild.frontends.terminal.TerminalBuildScript(config, module_list, module_set)
139 class ModuleOrderingTestCase(JhbuildConfigTestCase):
140 '''Module Ordering'''
142 def setUp(self):
143 super(ModuleOrderingTestCase, self).setUp()
144 self.moduleset = jhbuild.moduleset.ModuleSet(config=self.config)
145 self.moduleset.add(Package('foo'))
146 self.moduleset.add(Package('bar'))
147 self.moduleset.add(Package('baz'))
148 self.moduleset.add(Package('qux'))
149 self.moduleset.add(Package('quux'))
150 self.moduleset.add(Package('corge'))
152 def get_module_list(self, seed, skip=[], tags=[], include_suggests=True,
153 include_afters=False):
154 return [x.name for x in self.moduleset.get_module_list \
155 (seed, skip, tags, include_suggests,
156 include_afters)]
158 def test_standalone_one(self):
159 '''A standalone module'''
160 self.assertEqual(self.get_module_list(['foo']), ['foo'])
162 def test_standalone_two(self):
163 '''Two standalone modules'''
164 self.assertEqual(self.get_module_list(['foo', 'bar']), ['foo', 'bar'])
166 def test_dependency_chain_straight(self):
167 '''A straight chain of dependencies'''
168 self.moduleset.modules['foo'].dependencies = ['bar']
169 self.moduleset.modules['bar'].dependencies = ['baz']
170 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'foo'])
172 def test_dependency_chain_straight_skip(self):
173 '''A straight chain of dependencies, with a module to skip'''
174 self.moduleset.modules['foo'].dependencies = ['bar']
175 self.moduleset.modules['bar'].dependencies = ['baz']
176 self.assertEqual(self.get_module_list(['foo'], ['bar']), ['foo'])
178 def test_dependency_chain_bi(self):
179 '''A dividing chain of dependencies'''
180 self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
181 self.moduleset.modules['bar'].dependencies = ['baz']
182 self.moduleset.modules['qux'].dependencies = ['quux']
183 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'quux', 'qux', 'foo'])
185 def test_dependency_cycle(self):
186 '''A chain of dependencies with a cycle'''
187 self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
188 self.moduleset.modules['bar'].dependencies = ['baz']
189 self.moduleset.modules['qux'].dependencies = ['quux', 'foo']
190 self.moduleset.raise_exception_on_warning = True
191 self.assertRaises(UsageError, self.get_module_list, ['foo'])
192 self.moduleset.raise_exception_on_warning = False
194 def test_dependency_chain_missing_dependencies(self):
195 '''A chain of dependencies with a missing <dependencies> module'''
196 self.moduleset.modules['foo'].dependencies = ['bar', 'plop']
197 self.moduleset.modules['bar'].dependencies = ['baz']
198 self.moduleset.raise_exception_on_warning = True
199 self.assertRaises(UsageError, self.get_module_list, ['foo'])
200 self.moduleset.raise_exception_on_warning = False
201 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'foo'])
203 def test_dependency_chain_missing_after(self):
204 '''A chain of dependencies with a missing <after> module'''
205 self.moduleset.modules['foo'].dependencies = ['bar']
206 self.moduleset.modules['foo'].after = ['plop']
207 self.moduleset.modules['bar'].dependencies = ['baz']
208 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'foo'])
210 def test_dependency_chain_missing_suggests(self):
211 '''A chain of dependencies with a missing <suggests> module'''
212 self.moduleset.modules['foo'].dependencies = ['bar']
213 self.moduleset.modules['foo'].suggests = ['plop']
214 self.moduleset.modules['bar'].dependencies = ['baz']
215 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'foo'])
217 def test_dependency_chain_after(self):
218 '''A dividing chain of dependencies with an <after> module'''
219 self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
220 self.moduleset.modules['bar'].dependencies = ['baz']
221 self.moduleset.modules['baz'].after = ['qux']
222 self.moduleset.modules['qux'].dependencies = ['quux']
223 self.assertEqual(self.get_module_list(['foo'], include_afters=True), ['quux', 'qux', 'baz', 'bar', 'foo'])
225 def test_dependency_chain_suggests(self):
226 '''A dividing chain of dependencies with an <suggests> module'''
227 self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
228 self.moduleset.modules['bar'].dependencies = ['baz']
229 self.moduleset.modules['baz'].suggests = ['qux']
230 self.moduleset.modules['qux'].dependencies = ['quux']
231 self.assertEqual(self.get_module_list(['foo']), ['quux', 'qux', 'baz', 'bar', 'foo'])
233 def test_dependency_cycle_after(self):
234 '''A chain of dependencies with a cycle caused by an <after> module'''
235 self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
236 self.moduleset.modules['bar'].dependencies = ['baz']
237 self.moduleset.modules['qux'].dependencies = ['quux']
238 self.moduleset.modules['qux'].after = ['foo']
239 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'quux', 'qux', 'foo'])
241 def test_dependency_cycle_suggests(self):
242 '''A chain of dependencies with a cycle caused by an <suggests> module'''
243 self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
244 self.moduleset.modules['bar'].dependencies = ['baz']
245 self.moduleset.modules['qux'].dependencies = ['quux']
246 self.moduleset.modules['qux'].suggests = ['foo']
247 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'quux', 'qux', 'foo'])
249 def test_dependency_chain_recursive_after(self):
250 '''A chain of dependencies with a recursively defined <after> module'''
251 # see http://bugzilla.gnome.org/show_bug.cgi?id=546640
252 self.moduleset.modules['foo'] # gtk-doc
253 self.moduleset.modules['bar'].dependencies = ['foo'] # meta-bootstrap
254 self.moduleset.modules['bar'].type = 'meta'
255 self.moduleset.modules['baz'].after = ['bar'] # cairo
256 self.moduleset.modules['qux'].dependencies = ['baz'] # meta-stuff
257 self.assertEqual(self.get_module_list(['qux', 'foo']), ['foo', 'baz', 'qux'])
259 def test_dependency_chain_recursive_after_dependencies(self):
260 '''A chain dependency with an <after> module depending on an inversed relation'''
261 # see http://bugzilla.gnome.org/show_bug.cgi?id=546640
262 self.moduleset.modules['foo'] # nautilus
263 self.moduleset.modules['bar'] # nautilus-cd-burner
264 self.moduleset.modules['baz'] # tracker
265 self.moduleset.modules['foo'].after = ['baz']
266 self.moduleset.modules['bar'].dependencies = ['foo']
267 self.moduleset.modules['baz'].dependencies = ['bar']
268 self.moduleset.raise_exception_on_warning = True
269 self.assertRaises(UsageError, self.get_module_list, ['foo', 'bar'])
270 self.moduleset.raise_exception_on_warning = False
272 def test_sys_deps(self):
273 '''deps ommitted because satisfied by system dependencies'''
274 class TestBranch(jhbuild.versioncontrol.tarball.TarballBranch):
275 version = None
276 def __init__(self):
277 pass
279 self.moduleset.add(Package('syspkgalpha'))
280 self.moduleset.modules['foo'].dependencies = ['bar']
281 self.moduleset.modules['bar'].dependencies = ['syspkgalpha']
282 self.moduleset.modules['syspkgalpha'].dependencies = ['baz']
283 self.moduleset.modules['syspkgalpha'].pkg_config = 'syspkgalpha.pc'
284 self.moduleset.modules['syspkgalpha'].branch = TestBranch()
285 self.moduleset.modules['syspkgalpha'].branch.version = '3'
286 self.assertEqual(self.get_module_list(['foo']),
287 ['baz', 'syspkgalpha', 'bar', 'foo'])
288 self.moduleset.modules['syspkgalpha'].branch.version = '3.1'
289 self.assertEqual(self.get_module_list(['foo']),
290 ['baz', 'syspkgalpha', 'bar', 'foo'])
291 self.moduleset.modules['syspkgalpha'].branch.version = '2'
292 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'foo'])
293 self.moduleset.modules['syspkgalpha'].branch.version = '1'
294 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'foo'])
295 self.moduleset.modules['syspkgalpha'].branch.version = '1.1'
296 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'foo'])
298 self.moduleset.add(Package('syspkgbravo'))
299 self.moduleset.modules['foo'].dependencies = ['bar']
300 self.moduleset.modules['bar'].dependencies = ['syspkgbravo']
301 self.moduleset.modules['syspkgbravo'].dependencies = ['baz']
302 self.moduleset.modules['syspkgbravo'].pkg_config = 'syspkgbravo.pc'
303 self.moduleset.modules['syspkgbravo'].branch = TestBranch()
304 self.moduleset.modules['syspkgbravo'].branch.version = '3'
305 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'foo'])
306 self.moduleset.modules['syspkgbravo'].branch.version = '3.3'
307 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'foo'])
308 self.moduleset.modules['syspkgbravo'].branch.version = '3.4'
309 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'foo'])
310 self.moduleset.modules['syspkgbravo'].branch.version = '3.5'
311 self.assertEqual(self.get_module_list(['foo']),
312 ['baz', 'syspkgbravo', 'bar', 'foo'])
313 self.moduleset.modules['syspkgbravo'].branch.version = '4'
314 self.assertEqual(self.get_module_list(['foo']),
315 ['baz', 'syspkgbravo', 'bar', 'foo'])
318 class BuildTestCase(JhbuildConfigTestCase):
319 def setUp(self):
320 super(BuildTestCase, self).setUp()
321 self.branch = mock.Branch(os.path.join(self.config.buildroot, 'nonexistent'))
322 self.branch.config = self.config
323 self.packagedb = None
324 self.buildscript = None
325 self.moduleset = None
326 os.environ['JHBUILD_PREFIX'] = self.config.prefix
328 def tearDown(self):
329 super(BuildTestCase, self).tearDown()
330 self.buildscript = None
332 def build(self, packagedb_params = {}, **kwargs):
333 self.config.build_targets = ['install', 'test']
334 for k in kwargs:
335 setattr(self.config, k, kwargs[k])
336 self.config.update_build_targets()
338 if (self.packagedb is None) or (len(packagedb_params) > 0):
339 self.packagedb = mock.PackageDB(**packagedb_params)
340 self.moduleset = jhbuild.moduleset.ModuleSet(self.config, db=self.packagedb)
341 self.buildscript = mock.BuildScript(self.config, self.modules, self.moduleset)
343 self.buildscript.build()
344 return self.buildscript.actions
346 class AutotoolsModTypeTestCase(BuildTestCase):
347 '''Autotools steps'''
349 def setUp(self):
350 super(AutotoolsModTypeTestCase, self).setUp()
351 module = mock.MockModule('foo', branch=self.branch)
352 self.modules = [module]
353 self.modules[0].config = self.config
354 # replace clean method as it checks for Makefile existence
355 self.modules[0].skip_clean = lambda x,y: False
357 def test_build(self):
358 '''Building a autotools module'''
359 self.assertEqual(self.build(),
360 ['foo:Checking out', 'foo:Configuring', 'foo:Building',
361 'foo:Installing'])
363 def test_build_no_network(self):
364 '''Building a autotools module, without network'''
365 self.assertEqual(self.build(nonetwork = True),
366 ['foo:Configuring', 'foo:Building', 'foo:Installing'])
368 def test_update(self):
369 '''Updating a autotools module'''
370 self.assertEqual(self.build(nobuild = True), ['foo:Checking out'])
372 def test_build_check(self):
373 '''Building a autotools module, with checks'''
374 self.assertEqual(self.build(makecheck = True),
375 ['foo:Checking out', 'foo:Configuring', 'foo:Building',
376 'foo:Checking', 'foo:Installing'])
378 def test_build_clean_and_check(self):
379 '''Building a autotools module, with cleaning and checks'''
380 self.assertEqual(self.build(makecheck = True, makeclean = True),
381 ['foo:Checking out', 'foo:Configuring', 'foo:Cleaning',
382 'foo:Building', 'foo:Checking', 'foo:Installing'])
384 def test_build_check_error(self):
385 '''Building a autotools module, with an error in make check'''
387 def make_check_error(buildscript, *args):
388 self.modules[0].do_check_orig(buildscript, *args)
389 raise CommandError('Mock Command Error Exception')
390 make_check_error.depends = self.modules[0].do_check.depends
391 make_check_error.error_phases = self.modules[0].do_check.error_phases
392 self.modules[0].do_check_orig = self.modules[0].do_check
393 self.modules[0].do_check = make_check_error
395 self.assertEqual(self.build(makecheck = True),
396 ['foo:Checking out', 'foo:Configuring', 'foo:Building',
397 'foo:Checking [error]'])
400 class BuildPolicyTestCase(BuildTestCase):
401 '''Build Policy'''
403 def setUp(self):
404 super(BuildPolicyTestCase, self).setUp()
405 self.modules = [mock.MockModule('foo', branch=self.branch)]
406 self.modules[0].config = self.config
408 def test_policy_all(self):
409 '''Building an uptodate module with build policy set to "all"'''
410 self.config.build_policy = 'all'
411 self.assertEqual(self.build(packagedb_params = {'uptodate': True}),
412 ['foo:Checking out', 'foo:Configuring', 'foo:Building',
413 'foo:Installing'])
415 def test_policy_updated(self):
416 '''Building an uptodate module with build policy set to "updated"'''
417 self.config.build_policy = 'updated'
418 self.assertEqual(self.build(packagedb_params = {'uptodate': True}),
419 ['foo:Checking out'])
421 def test_policy_all_with_no_network(self):
422 '''Building an uptodate module with "all" policy, without network'''
423 self.config.build_policy = 'all'
424 self.assertEqual(self.build(
425 packagedb_params = {'uptodate': True},
426 nonetwork = True),
427 ['foo:Configuring', 'foo:Building', 'foo:Installing'])
429 def test_policy_updated_with_no_network(self):
430 '''Building an uptodate module with "updated" policy, without network'''
431 self.config.build_policy = 'updated'
432 self.assertEqual(self.build(
433 packagedb_params = {'uptodate': True},
434 nonetwork = True), [])
437 class TwoModulesTestCase(BuildTestCase):
438 '''Building two dependent modules'''
440 def setUp(self):
441 super(TwoModulesTestCase, self).setUp()
442 self.foo_branch = mock.Branch(os.path.join(self.config.buildroot, 'nonexistent-foo'))
443 self.modules = [mock.MockModule('foo', branch=self.foo_branch),
444 mock.MockModule('bar', branch=self.branch)]
445 self.modules[0].config = self.config
446 self.modules[1].config = self.config
448 def test_build(self):
449 '''Building two autotools module'''
450 self.assertEqual(self.build(),
451 ['foo:Checking out', 'foo:Configuring',
452 'foo:Building', 'foo:Installing',
453 'bar:Checking out', 'bar:Configuring',
454 'bar:Building', 'bar:Installing',
457 def test_build_failure_independent_modules(self):
458 '''Building two independent autotools modules, with failure in first'''
460 def build_error(buildscript, *args):
461 self.modules[0].do_build_orig(buildscript, *args)
462 raise CommandError('Mock Command Error Exception')
463 build_error.depends = self.modules[0].do_build.depends
464 build_error.error_phases = self.modules[0].do_build.error_phases
465 self.modules[0].do_build_orig = self.modules[0].do_build
466 self.modules[0].do_build = build_error
468 self.assertEqual(self.build(),
469 ['foo:Checking out', 'foo:Configuring', 'foo:Building [error]',
470 'bar:Checking out', 'bar:Configuring',
471 'bar:Building', 'bar:Installing',
474 def test_build_failure_dependent_modules(self):
475 '''Building two dependent autotools modules, with failure in first'''
476 self.modules[1].dependencies = ['foo']
478 def build_error(buildscript, *args):
479 self.modules[0].do_build_orig(buildscript, *args)
480 raise CommandError('Mock Command Error Exception')
481 build_error.depends = self.modules[0].do_build.depends
482 build_error.error_phases = self.modules[0].do_build.error_phases
483 self.modules[0].do_build_orig = self.modules[0].do_build
484 self.modules[0].do_build = build_error
486 self.assertEqual(self.build(),
487 ['foo:Checking out', 'foo:Configuring', 'foo:Building [error]'])
489 def test_build_failure_dependent_modules_nopoison(self):
490 '''Building two dependent autotools modules, with failure, but nopoison'''
491 self.modules[1].dependencies = ['foo']
493 def build_error(buildscript, *args):
494 self.modules[0].do_build_orig(buildscript, *args)
495 raise CommandError('Mock Command Error Exception')
496 build_error.depends = self.modules[0].do_build.depends
497 build_error.error_phases = self.modules[0].do_build.error_phases
498 self.modules[0].do_build_orig = self.modules[0].do_build
499 self.modules[0].do_build = build_error
501 self.assertEqual(self.build(nopoison = True),
502 ['foo:Checking out', 'foo:Configuring', 'foo:Building [error]',
503 'bar:Checking out', 'bar:Configuring',
504 'bar:Building', 'bar:Installing',
507 def test_build_no_update(self):
508 '''Building two uptodate, autotools module'''
509 self.build() # will feed PackageDB
510 self.assertEqual(self.build(),
511 ['foo:Checking out', 'foo:Configuring',
512 'foo:Building', 'foo:Installing',
513 'bar:Checking out', 'bar:Configuring',
514 'bar:Building', 'bar:Installing',
517 def test_build_no_update_updated_policy(self):
518 '''Building two uptodate, autotools module, with 'updated' policy'''
519 self.build() # will feed PackageDB
520 self.assertEqual(self.build(build_policy = 'updated'),
521 ['foo:Checking out', 'bar:Checking out'])
523 def test_build_no_update_updated_deps_policy(self):
524 '''Building two autotools module, (changed and not), with 'updated-deps' policy'''
525 self.modules[1].dependencies = ['foo']
526 self.build() # will feed PackageDB
527 self.buildscript.packagedb.remove('foo')
528 self.buildscript.packagedb.time_delta = 5
529 self.assertEqual(self.build(build_policy = 'updated-deps'),
530 ['foo:Checking out', 'foo:Configuring',
531 'foo:Building', 'foo:Installing',
532 'bar:Checking out', 'bar:Configuring',
533 'bar:Building', 'bar:Installing',
536 def test_make_check_failure_dependent_modules(self):
537 '''Building two dependent autotools modules, with failure in make check'''
538 self.modules[1].dependencies = ['foo']
540 def check_error(buildscript, *args):
541 self.modules[0].do_check_orig(buildscript, *args)
542 raise CommandError('Mock Command Error Exception')
543 check_error.depends = self.modules[0].do_check.depends
544 check_error.error_phases = self.modules[0].do_check.error_phases
545 self.modules[0].do_check_orig = self.modules[0].do_check
546 self.modules[0].do_check = check_error
548 self.assertEqual(self.build(makecheck = True),
549 ['foo:Checking out', 'foo:Configuring',
550 'foo:Building', 'foo:Checking [error]'])
552 def test_make_check_failure_dependent_modules_makecheck_advisory(self):
553 '''Building two dependent autotools modules, with *advisory* failure in make check'''
554 self.modules[1].dependencies = ['foo']
556 def check_error(buildscript, *args):
557 buildscript.execute_is_failure = True
558 try:
559 self.modules[0].do_check_orig(buildscript, *args)
560 finally:
561 buildscript.execute_is_failure = False
562 check_error.depends = self.modules[0].do_check.depends
563 check_error.error_phases = self.modules[0].do_check.error_phases
564 self.modules[0].do_check_orig = self.modules[0].do_check
565 self.modules[0].do_check = check_error
567 self.assertEqual(self.build(makecheck = True, makecheck_advisory = True),
568 ['foo:Checking out', 'foo:Configuring',
569 'foo:Building', 'foo:Checking', 'foo:Installing',
570 'bar:Checking out', 'bar:Configuring',
571 'bar:Building', 'bar:Checking', 'bar:Installing'])
574 class SimpleBranch(object):
576 def __init__(self, name, dir_path):
577 self.branchname = name
578 self.srcdir = dir_path
580 def checkout(self, buildscript):
581 pass
583 def may_checkout(self, buildscript):
584 return True
586 def tree_id(self):
587 return 'made-up-tree-id'
590 def restore_environ(env):
591 # os.environ.clear() doesn't appear to change underlying environment.
592 for key in os.environ.keys():
593 del os.environ[key]
594 for key, value in env.iteritems():
595 os.environ[key] = value
598 STDOUT_FILENO = 1
600 def with_stdout_hidden(func):
601 null_device = '/dev/null'
602 if sys.platform.startswith('win'):
603 null_device = 'NUL'
604 old_fd = os.dup(STDOUT_FILENO)
605 new_fd = os.open(null_device, os.O_WRONLY)
606 os.dup2(new_fd, STDOUT_FILENO)
607 os.close(new_fd)
608 try:
609 return func()
610 finally:
611 os.dup2(old_fd, STDOUT_FILENO)
612 os.close(old_fd)
615 class EndToEndTest(JhbuildConfigTestCase):
617 # FIXME: broken under Win32
618 def test_distutils(self):
619 config = self.make_config()
620 module_list = [DistutilsModule('hello',
621 self.make_branch(config, 'distutils'))]
622 module_list[0].config = self.config
623 build = self.make_terminal_buildscript(config, module_list)
624 with_stdout_hidden(build.build)
625 proc = subprocess.Popen(['hello'], stdout=subprocess.PIPE)
626 stdout, stderr = proc.communicate()
627 self.assertEquals(stdout.strip(), 'Hello world (distutils)')
628 self.assertEquals(proc.wait(), 0)
630 def test_autotools(self):
631 config = self.make_config()
632 module_list = [AutogenModule('hello',
633 branch=self.make_branch(config, 'autotools'))]
634 module_list[0].config = self.config
635 build = self.make_terminal_buildscript(config, module_list)
636 with_stdout_hidden(build.build)
637 proc = subprocess.Popen(['hello'], stdout=subprocess.PIPE)
638 stdout, stderr = proc.communicate()
639 self.assertEquals(stdout.strip(), 'Hello world (autotools)')
640 self.assertEquals(proc.wait(), 0)
642 # Won't pass under stock MSYS because pkgconfig isn't installed in base
643 # path. Will work if you set ACLOCAL_FLAGS, PATH and PKG_CONFIG_PATH to
644 # a prefix where pkg-config is installed.
645 def test_autotools_with_libtool(self):
646 config = self.make_config()
647 module_list = [
648 AutogenModule('libhello', branch=self.make_branch(config, 'libhello')),
649 AutogenModule('hello', branch=self.make_branch(config, 'hello'))]
650 module_list[0].config = self.config
651 module_list[1].config = self.config
652 build = self.make_terminal_buildscript(config, module_list)
653 with_stdout_hidden(build.build)
654 proc = subprocess.Popen(['hello'], stdout=subprocess.PIPE)
655 stdout, stderr = proc.communicate()
656 self.assertEquals(stdout.strip(), 'Hello world (library test)')
657 self.assertEquals(proc.wait(), 0)
659 class UtilsTest(JhbuildConfigTestCase):
661 def test_compare_version(self):
662 self.assertTrue(jhbuild.utils.cmds.compare_version('3.13.1.with.ckbi.1.88', '3'))
663 self.assertTrue(jhbuild.utils.cmds.compare_version('3.13.1.with.ckbi.1.88', '3.12'))
664 self.assertTrue(jhbuild.utils.cmds.compare_version('3.13.1.with.ckbi.1.88', '3.13.1'))
665 self.assertFalse(jhbuild.utils.cmds.compare_version('3.13.1.with.ckbi.1.88', '4'))
666 self.assertFalse(jhbuild.utils.cmds.compare_version('3.13.1.with.ckbi.1.88', '3.14'))
667 self.assertFalse(jhbuild.utils.cmds.compare_version('3.13.1.with.ckbi.1.88', '3.13.2'))
668 self.assertFalse(jhbuild.utils.cmds.compare_version('3with', '3.1'))
669 self.assertTrue(jhbuild.utils.cmds.compare_version('3with', '2'))
670 self.assertFalse(jhbuild.utils.cmds.compare_version('with3', '3.1'))
671 self.assertTrue(jhbuild.utils.cmds.compare_version('with3', '2'))
672 self.assertFalse(jhbuild.utils.cmds.compare_version('3.with', '3.1'))
673 self.assertTrue(jhbuild.utils.cmds.compare_version('3.with', '3'))
674 self.assertFalse(jhbuild.utils.cmds.compare_version('0.5', '0.6'))
675 self.assertTrue(jhbuild.utils.cmds.compare_version('0.5', '0.5'))
676 self.assertFalse(jhbuild.utils.cmds.compare_version('1', '1.2.3.4'))
677 self.assertTrue(jhbuild.utils.cmds.compare_version('1.2.3.4', '1'))
678 self.assertTrue(jhbuild.utils.cmds.compare_version('2', '1.2.3.4'))
679 self.assertFalse(jhbuild.utils.cmds.compare_version('1.2.3.4', '2'))
681 def get_installed_pkgconfigs(config):
682 ''' overload jhbuild.utils.get_installed_pkgconfigs'''
683 return {'syspkgalpha' : '2',
684 'syspkgbravo' : '3.4'}
686 if __name__ == '__main__':
687 logging.basicConfig(level=logging.INFO)
688 unittest.main()