[tests] recompute build targets only once
[jhbuild.git] / tests / tests.py
blobf261844777315a69c668edddc1ec18d222e0f548
1 #! /usr/bin/env python
2 # jhbuild - a build script for GNOME 1.x and 2.x
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 subprocess
26 import sys
27 import tempfile
28 import unittest
30 import __builtin__
31 __builtin__.__dict__['_'] = lambda x: x
32 __builtin__.__dict__['N_'] = lambda x: x
34 __builtin__.__dict__['PKGDATADIR'] = None
35 __builtin__.__dict__['DATADIR'] = None
36 __builtin__.__dict__['SRCDIR'] = os.path.join(os.path.dirname(__file__), '..')
38 sys.path.insert(0, SRCDIR)
40 from jhbuild.errors import DependencyCycleError, UsageError, CommandError
41 from jhbuild.modtypes import Package
42 from jhbuild.modtypes.autotools import AutogenModule
43 from jhbuild.modtypes.distutils import DistutilsModule
44 import jhbuild.config
45 import jhbuild.frontends.terminal
46 import jhbuild.moduleset
49 def uencode(s):
50 if type(s) is unicode:
51 return s.encode(_encoding, 'replace')
52 else:
53 return s
55 def uprint(*args):
56 '''Print Unicode string encoded for the terminal'''
57 for s in args[:-1]:
58 print uencode(s),
59 s = args[-1]
60 print uencode(s)
61 __builtin__.__dict__['uprint'] = uprint
62 __builtin__.__dict__['uencode'] = uencode
65 import mock
67 class ModuleOrderingTestCase(unittest.TestCase):
68 '''Module Ordering'''
70 def setUp(self):
71 self.moduleset = jhbuild.moduleset.ModuleSet()
72 self.moduleset.add(Package('foo'))
73 self.moduleset.add(Package('bar'))
74 self.moduleset.add(Package('baz'))
75 self.moduleset.add(Package('qux'))
76 self.moduleset.add(Package('quux'))
77 self.moduleset.add(Package('corge'))
79 def get_module_list(self, seed, skip=[]):
80 return [x.name for x in self.moduleset.get_module_list(seed, skip)]
82 def test_standalone_one(self):
83 '''A standalone module'''
84 self.assertEqual(self.get_module_list(['foo']), ['foo'])
86 def test_standalone_two(self):
87 '''Two standalone modules'''
88 self.assertEqual(self.get_module_list(['foo', 'bar']), ['foo', 'bar'])
90 def test_dependency_chain_straight(self):
91 '''A straight chain of dependencies'''
92 self.moduleset.modules['foo'].dependencies = ['bar']
93 self.moduleset.modules['bar'].dependencies = ['baz']
94 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'foo'])
96 def test_dependency_chain_straight_skip(self):
97 '''A straight chain of dependencies, with a module to skip'''
98 self.moduleset.modules['foo'].dependencies = ['bar']
99 self.moduleset.modules['bar'].dependencies = ['baz']
100 self.assertEqual(self.get_module_list(['foo'], ['bar']), ['foo'])
102 def test_dependency_chain_bi(self):
103 '''A dividing chain of dependencies'''
104 self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
105 self.moduleset.modules['bar'].dependencies = ['baz']
106 self.moduleset.modules['qux'].dependencies = ['quux']
107 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'quux', 'qux', 'foo'])
109 def test_dependency_cycle(self):
110 '''A chain of dependencies with a cycle'''
111 self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
112 self.moduleset.modules['bar'].dependencies = ['baz']
113 self.moduleset.modules['qux'].dependencies = ['quux', 'foo']
114 self.assertRaises(DependencyCycleError, self.get_module_list, ['foo'])
116 def test_dependency_chain_missing_dependencies(self):
117 '''A chain of dependencies with a missing <dependencies> module'''
118 self.moduleset.modules['foo'].dependencies = ['bar', 'plop']
119 self.moduleset.modules['bar'].dependencies = ['baz']
120 self.assertRaises(UsageError, self.get_module_list, ['foo'])
122 def test_dependency_chain_missing_after(self):
123 '''A chain of dependencies with a missing <after> module'''
124 self.moduleset.modules['foo'].dependencies = ['bar']
125 self.moduleset.modules['foo'].after = ['plop']
126 self.moduleset.modules['bar'].dependencies = ['baz']
127 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'foo'])
129 def test_dependency_chain_missing_suggests(self):
130 '''A chain of dependencies with a missing <suggests> module'''
131 self.moduleset.modules['foo'].dependencies = ['bar']
132 self.moduleset.modules['foo'].suggests = ['plop']
133 self.moduleset.modules['bar'].dependencies = ['baz']
134 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'foo'])
136 def test_dependency_chain_after(self):
137 '''A dividing chain of dependencies with an <after> module'''
138 self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
139 self.moduleset.modules['bar'].dependencies = ['baz']
140 self.moduleset.modules['baz'].after = ['qux']
141 self.moduleset.modules['qux'].dependencies = ['quux']
142 self.assertEqual(self.get_module_list(['foo']), ['quux', 'qux', 'baz', 'bar', 'foo'])
144 def test_dependency_chain_suggests(self):
145 '''A dividing chain of dependencies with an <suggests> module'''
146 self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
147 self.moduleset.modules['bar'].dependencies = ['baz']
148 self.moduleset.modules['baz'].suggests = ['qux']
149 self.moduleset.modules['qux'].dependencies = ['quux']
150 self.assertEqual(self.get_module_list(['foo']), ['quux', 'qux', 'baz', 'bar', 'foo'])
152 def test_dependency_cycle_after(self):
153 '''A chain of dependencies with a cycle caused by an <after> module'''
154 self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
155 self.moduleset.modules['bar'].dependencies = ['baz']
156 self.moduleset.modules['qux'].dependencies = ['quux']
157 self.moduleset.modules['qux'].after = ['foo']
158 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'quux', 'qux', 'foo'])
160 def test_dependency_cycle_suggests(self):
161 '''A chain of dependencies with a cycle caused by an <suggests> module'''
162 self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
163 self.moduleset.modules['bar'].dependencies = ['baz']
164 self.moduleset.modules['qux'].dependencies = ['quux']
165 self.moduleset.modules['qux'].suggests = ['foo']
166 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'quux', 'qux', 'foo'])
168 def test_dependency_chain_recursive_after(self):
169 '''A chain of dependencies with a recursively defined <after> module'''
170 # see http://bugzilla.gnome.org/show_bug.cgi?id=546640
171 self.moduleset.modules['foo'] # gtk-doc
172 self.moduleset.modules['bar'].dependencies = ['foo'] # meta-bootstrap
173 self.moduleset.modules['bar'].type = 'meta'
174 self.moduleset.modules['baz'].after = ['bar'] # cairo
175 self.moduleset.modules['qux'].dependencies = ['baz'] # meta-stuff
176 self.assertEqual(self.get_module_list(['qux', 'foo']), ['foo', 'baz', 'qux'])
178 def test_dependency_chain_recursive_after_dependencies(self):
179 '''A chain dependency with an <after> module depending on an inversed relation'''
180 # see http://bugzilla.gnome.org/show_bug.cgi?id=546640
181 self.moduleset.modules['foo'] # nautilus
182 self.moduleset.modules['bar'] # nautilus-cd-burner
183 self.moduleset.modules['baz'] # tracker
184 self.moduleset.modules['foo'].after = ['baz']
185 self.moduleset.modules['bar'].dependencies = ['foo']
186 self.moduleset.modules['baz'].dependencies = ['bar']
187 self.assertEqual(self.get_module_list(['foo', 'bar']), ['foo', 'bar'])
190 class BuildTestCase(unittest.TestCase):
191 def setUp(self):
192 self.config = mock.Config()
193 self.branch = mock.Branch()
194 self.branch.config = self.config
195 self.buildscript = None
197 def build(self, packagedb_params = {}, **kwargs):
198 self.config.build_targets = ['install']
199 for k in kwargs:
200 setattr(self.config, k, kwargs[k])
202 if self.config.makecheck and not 'check' in self.config.build_targets:
203 self.config.build_targets.insert(0, 'check')
204 if self.config.makeclean and not 'clean' in self.config.build_targets:
205 self.config.build_targets.insert(0, 'clean')
206 if self.config.nobuild:
207 self.config.build_targets.remove('install')
208 if len(self.config.build_targets) == 0:
209 self.config.build_targets = ['checkout']
210 if self.config.makedist and not 'dist' in self.config.build_targets:
211 self.config.build_targets.append('dist')
212 if self.config.makedistcheck and not 'distcheck' in self.config.build_targets:
213 self.config.build_targets.append('distcheck')
215 if not self.buildscript or packagedb_params:
216 self.buildscript = mock.BuildScript(self.config, self.modules)
217 self.buildscript.packagedb = mock.PackageDB(**packagedb_params)
218 else:
219 packagedb = self.buildscript.packagedb
220 self.buildscript = mock.BuildScript(self.config, self.modules)
221 self.buildscript.packagedb = packagedb
223 self.buildscript.build()
224 return self.buildscript.actions
226 def tearDown(self):
227 self.buildscript = None
230 class AutotoolsModTypeTestCase(BuildTestCase):
231 '''Autotools steps'''
233 def setUp(self):
234 BuildTestCase.setUp(self)
235 self.modules = [AutogenModule('foo', self.branch)]
236 self.modules[0].config = self.config
237 # replace clean method as it checks for Makefile existence
238 self.modules[0].skip_clean = lambda x,y: False
240 def test_build(self):
241 '''Building a autotools module'''
242 self.assertEqual(self.build(),
243 ['foo:Checking out', 'foo:Configuring', 'foo:Building',
244 'foo:Installing'])
246 def test_build_no_network(self):
247 '''Building a autotools module, without network'''
248 self.assertEqual(self.build(nonetwork = True),
249 ['foo:Configuring', 'foo:Building', 'foo:Installing'])
251 def test_update(self):
252 '''Updating a autotools module'''
253 self.assertEqual(self.build(nobuild = True), ['foo:Checking out'])
255 def test_build_check(self):
256 '''Building a autotools module, with checks'''
257 self.assertEqual(self.build(makecheck = True),
258 ['foo:Checking out', 'foo:Configuring', 'foo:Building',
259 'foo:Checking', 'foo:Installing'])
261 def test_build_clean_and_check(self):
262 '''Building a autotools module, with cleaning and checks'''
263 self.assertEqual(self.build(makecheck = True, makeclean = True),
264 ['foo:Checking out', 'foo:Configuring', 'foo:Cleaning',
265 'foo:Building', 'foo:Checking', 'foo:Installing'])
267 def test_build_check_error(self):
268 '''Building a autotools module, with an error in make check'''
270 def make_check_error(buildscript, *args):
271 self.modules[0].do_check_orig(buildscript, *args)
272 raise CommandError('Mock Command Error Exception')
273 make_check_error.depends = self.modules[0].do_check.depends
274 make_check_error.error_phases = self.modules[0].do_check.error_phases
275 self.modules[0].do_check_orig = self.modules[0].do_check
276 self.modules[0].do_check = make_check_error
278 self.assertEqual(self.build(makecheck = True),
279 ['foo:Checking out', 'foo:Configuring', 'foo:Building',
280 'foo:Checking [error]'])
283 class WafModTypeTestCase(BuildTestCase):
284 '''Waf steps'''
286 def setUp(self):
287 BuildTestCase.setUp(self)
288 from jhbuild.modtypes.waf import WafModule
289 self.modules = [WafModule('foo', self.branch)]
290 self.modules[0].waf_cmd = 'true' # set a command for waf that always exist
292 def test_build(self):
293 '''Building a waf module'''
294 self.assertEqual(self.build(),
295 ['foo:Checking out', 'foo:Configuring', 'foo:Building',
296 'foo:Installing'])
298 def test_build_no_network(self):
299 '''Building a waf module, without network'''
300 self.assertEqual(self.build(nonetwork = True),
301 ['foo:Configuring', 'foo:Building', 'foo:Installing'])
303 def test_update(self):
304 '''Updating a waf module'''
305 self.assertEqual(self.build(nobuild = True), ['foo:Checking out'])
307 def test_build_check(self):
308 '''Building a waf module, with checks'''
309 self.assertEqual(self.build(makecheck = True),
310 ['foo:Checking out', 'foo:Configuring', 'foo:Building',
311 'foo:Checking', 'foo:Installing'])
313 def test_build_clean_and_check(self):
314 '''Building a waf module, with cleaning and checks'''
315 self.assertEqual(self.build(makecheck = True, makeclean = True),
316 ['foo:Checking out', 'foo:Configuring', 'foo:Cleaning',
317 'foo:Building', 'foo:Checking', 'foo:Installing'])
319 def test_build_check_error(self):
320 '''Building a waf module, with an error in make check'''
322 def make_check_error(buildscript, *args):
323 self.modules[0].do_check_orig(buildscript, *args)
324 raise CommandError('Mock Command Error Exception')
325 make_check_error.depends = self.modules[0].do_check.depends
326 make_check_error.error_phases = self.modules[0].do_check.error_phases
327 self.modules[0].do_check_orig = self.modules[0].do_check
328 self.modules[0].do_check = make_check_error
330 self.assertEqual(self.build(makecheck = True),
331 ['foo:Checking out', 'foo:Configuring', 'foo:Building',
332 'foo:Checking [error]'])
334 def test_build_missing_waf_command(self):
335 '''Building a waf module, on a system missing the waf command'''
336 self.modules[0].waf_cmd = 'foo bar'
337 self.assertEqual(self.build(),
338 ['foo:Checking out', 'foo:Configuring [error]'])
344 class BuildPolicyTestCase(BuildTestCase):
345 '''Build Policy'''
347 def setUp(self):
348 BuildTestCase.setUp(self)
349 self.modules = [AutogenModule('foo', self.branch)]
350 self.modules[0].config = self.config
352 def test_policy_all(self):
353 '''Building an uptodate module with build policy set to "all"'''
354 self.config.build_policy = 'all'
355 self.assertEqual(self.build(packagedb_params = {'uptodate': True}),
356 ['foo:Checking out', 'foo:Configuring', 'foo:Building',
357 'foo:Installing'])
359 def test_policy_updated(self):
360 '''Building an uptodate module with build policy set to "updated"'''
361 self.config.build_policy = 'updated'
362 self.assertEqual(self.build(packagedb_params = {'uptodate': True}),
363 ['foo:Checking out'])
365 def test_policy_all_with_no_network(self):
366 '''Building an uptodate module with "all" policy, without network'''
367 self.config.build_policy = 'all'
368 self.assertEqual(self.build(
369 packagedb_params = {'uptodate': True},
370 nonetwork = True),
371 ['foo:Configuring', 'foo:Building', 'foo:Installing'])
373 def test_policy_updated_with_no_network(self):
374 '''Building an uptodate module with "updated" policy, without network'''
375 self.config.build_policy = 'updated'
376 self.assertEqual(self.build(
377 packagedb_params = {'uptodate': True},
378 nonetwork = True), [])
381 class TestModTypeTestCase(BuildTestCase):
382 '''Tests Module Steps'''
384 def setUp(self):
385 BuildTestCase.setUp(self)
386 from jhbuild.modtypes.testmodule import TestModule
387 self.modules = [TestModule('foo', self.branch, 'dogtail')]
389 def test_run(self):
390 '''Running a test module'''
391 self.assertEqual(self.build(), ['foo:Checking out', 'foo:Testing'])
393 def test_build_no_network(self):
394 '''Running a test module, without network'''
395 self.assertEqual(self.build(nonetwork = True), ['foo:Testing'])
398 class TwoModulesTestCase(BuildTestCase):
399 '''Building two dependent modules'''
401 def setUp(self):
402 BuildTestCase.setUp(self)
403 self.foo_branch = mock.Branch()
404 self.modules = [AutogenModule('foo', self.foo_branch),
405 AutogenModule('bar', self.branch)]
406 self.modules[0].config = self.config
407 self.modules[1].config = self.config
409 def test_build(self):
410 '''Building two autotools module'''
411 self.assertEqual(self.build(),
412 ['foo:Checking out', 'foo:Configuring',
413 'foo:Building', 'foo:Installing',
414 'bar:Checking out', 'bar:Configuring',
415 'bar:Building', 'bar:Installing',
418 def test_build_failure_independent_modules(self):
419 '''Building two independent autotools modules, with failure in first'''
421 def build_error(buildscript, *args):
422 self.modules[0].do_build_orig(buildscript, *args)
423 raise CommandError('Mock Command Error Exception')
424 build_error.depends = self.modules[0].do_build.depends
425 build_error.error_phases = self.modules[0].do_build.error_phases
426 self.modules[0].do_build_orig = self.modules[0].do_build
427 self.modules[0].do_build = build_error
429 self.assertEqual(self.build(),
430 ['foo:Checking out', 'foo:Configuring', 'foo:Building [error]',
431 'bar:Checking out', 'bar:Configuring',
432 'bar:Building', 'bar:Installing',
435 def test_build_failure_dependent_modules(self):
436 '''Building two dependent autotools modules, with failure in first'''
437 self.modules[1].dependencies = ['foo']
439 def build_error(buildscript, *args):
440 self.modules[0].do_build_orig(buildscript, *args)
441 raise CommandError('Mock Command Error Exception')
442 build_error.depends = self.modules[0].do_build.depends
443 build_error.error_phases = self.modules[0].do_build.error_phases
444 self.modules[0].do_build_orig = self.modules[0].do_build
445 self.modules[0].do_build = build_error
447 self.assertEqual(self.build(),
448 ['foo:Checking out', 'foo:Configuring', 'foo:Building [error]'])
450 def test_build_failure_dependent_modules_nopoison(self):
451 '''Building two dependent autotools modules, with failure, but nopoison'''
452 self.modules[1].dependencies = ['foo']
454 def build_error(buildscript, *args):
455 self.modules[0].do_build_orig(buildscript, *args)
456 raise CommandError('Mock Command Error Exception')
457 build_error.depends = self.modules[0].do_build.depends
458 build_error.error_phases = self.modules[0].do_build.error_phases
459 self.modules[0].do_build_orig = self.modules[0].do_build
460 self.modules[0].do_build = build_error
462 self.assertEqual(self.build(nopoison = True),
463 ['foo:Checking out', 'foo:Configuring', 'foo:Building [error]',
464 'bar:Checking out', 'bar:Configuring',
465 'bar:Building', 'bar:Installing',
468 def test_build_no_update(self):
469 '''Building two uptodate, autotools module'''
470 self.build() # will feed PackageDB
471 self.assertEqual(self.build(),
472 ['foo:Checking out', 'foo:Configuring',
473 'foo:Building', 'foo:Installing',
474 'bar:Checking out', 'bar:Configuring',
475 'bar:Building', 'bar:Installing',
478 def test_build_no_update_updated_policy(self):
479 '''Building two uptodate, autotools module, with 'updated' policy'''
480 self.build() # will feed PackageDB
481 self.assertEqual(self.build(build_policy = 'updated'),
482 ['foo:Checking out', 'bar:Checking out'])
484 def test_build_no_update_updated_deps_policy(self):
485 '''Building two autotools module, (changed and not), with 'updated-deps' policy'''
486 self.modules[1].dependencies = ['foo']
487 self.build() # will feed PackageDB
488 self.buildscript.packagedb.remove('foo')
489 self.buildscript.packagedb.time_delta = 5
490 self.assertEqual(self.build(build_policy = 'updated-deps'),
491 ['foo:Checking out', 'foo:Configuring',
492 'foo:Building', 'foo:Installing',
493 'bar:Checking out', 'bar:Configuring',
494 'bar:Building', 'bar:Installing',
497 def test_build_no_update_updated_deps_policy(self):
498 '''Building two independent autotools module, (changed and not), with 'updated-deps' policy'''
499 self.build() # will feed PackageDB
500 self.buildscript.packagedb.remove('foo')
501 self.buildscript.packagedb.time_delta = 5
502 self.assertEqual(self.build(build_policy = 'updated-deps'),
503 ['foo:Checking out', 'foo:Configuring',
504 'foo:Building', 'foo:Installing',
505 'bar:Checking out',])
507 def test_make_check_failure_dependent_modules(self):
508 '''Building two dependent autotools modules, with failure in make check'''
509 self.modules[1].dependencies = ['foo']
511 def check_error(buildscript, *args):
512 self.modules[0].do_check_orig(buildscript, *args)
513 raise CommandError('Mock Command Error Exception')
514 check_error.depends = self.modules[0].do_check.depends
515 check_error.error_phases = self.modules[0].do_check.error_phases
516 self.modules[0].do_check_orig = self.modules[0].do_check
517 self.modules[0].do_check = check_error
519 self.assertEqual(self.build(makecheck = True),
520 ['foo:Checking out', 'foo:Configuring',
521 'foo:Building', 'foo:Checking [error]'])
523 def test_make_check_failure_dependent_modules_makecheck_advisory(self):
524 '''Building two dependent autotools modules, with *advisory* failure in make check'''
525 self.modules[1].dependencies = ['foo']
527 def check_error(buildscript, *args):
528 buildscript.execute_is_failure = True
529 try:
530 self.modules[0].do_check_orig(buildscript, *args)
531 finally:
532 buildscript.execute_is_failure = False
533 check_error.depends = self.modules[0].do_check.depends
534 check_error.error_phases = self.modules[0].do_check.error_phases
535 self.modules[0].do_check_orig = self.modules[0].do_check
536 self.modules[0].do_check = check_error
538 self.assertEqual(self.build(makecheck = True, makecheck_advisory = True),
539 ['foo:Checking out', 'foo:Configuring',
540 'foo:Building', 'foo:Checking', 'foo:Installing',
541 'bar:Checking out', 'bar:Configuring',
542 'bar:Building', 'bar:Checking', 'bar:Installing'])
545 class TestConfig(jhbuild.config.Config):
547 # The Config base class calls setup_env() in the constructor, but
548 # we need to override some attributes before calling it.
549 def setup_env(self):
550 pass
552 def real_setup_env(self):
553 jhbuild.config.Config.setup_env(self)
556 class SimpleBranch(object):
558 def __init__(self, name, dir_path):
559 self.branchname = name
560 self.srcdir = dir_path
562 def checkout(self, buildscript):
563 pass
565 def tree_id(self):
566 return 'made-up-tree-id'
569 def restore_environ(env):
570 # os.environ.clear() doesn't appear to change underlying environment.
571 for key in os.environ.keys():
572 del os.environ[key]
573 for key, value in env.iteritems():
574 os.environ[key] = value
577 STDOUT_FILENO = 1
579 def with_stdout_hidden(func):
580 old_fd = os.dup(STDOUT_FILENO)
581 new_fd = os.open('/dev/null', os.O_WRONLY)
582 os.dup2(new_fd, STDOUT_FILENO)
583 os.close(new_fd)
584 try:
585 return func()
586 finally:
587 os.dup2(old_fd, STDOUT_FILENO)
588 os.close(old_fd)
591 class EndToEndTest(unittest.TestCase):
593 def setUp(self):
594 self.config = mock.Config()
595 self._old_env = os.environ.copy()
596 self._temp_dirs = []
598 def tearDown(self):
599 restore_environ(self._old_env)
600 for temp_dir in self._temp_dirs:
601 shutil.rmtree(temp_dir)
603 def make_temp_dir(self):
604 temp_dir = tempfile.mkdtemp(prefix='unittest-')
605 self._temp_dirs.append(temp_dir)
606 return temp_dir
608 def make_config(self):
609 temp_dir = self.make_temp_dir()
610 config = TestConfig()
611 config.checkoutroot = os.path.abspath(os.path.join(temp_dir, 'checkout'))
612 config.prefix = os.path.abspath(os.path.join(temp_dir, 'prefix'))
613 os.makedirs(config.checkoutroot)
614 os.makedirs(config.prefix)
615 config.interact = False
616 config.quiet_mode = True # Not enough to disable output entirely
617 config.progress_bar = False
618 config.real_setup_env()
619 return config
621 def make_branch(self, config, src_name):
622 branch_dir = os.path.join(config.checkoutroot, src_name)
623 shutil.copytree(os.path.join(os.path.dirname(__file__), src_name),
624 branch_dir)
625 return SimpleBranch(src_name, branch_dir)
627 def test_distutils(self):
628 config = self.make_config()
629 module_list = [DistutilsModule('hello',
630 self.make_branch(config, 'distutils'))]
631 module_list[0].config = self.config
632 build = jhbuild.frontends.terminal.TerminalBuildScript(
633 config, module_list)
634 with_stdout_hidden(build.build)
635 proc = subprocess.Popen(['hello'], stdout=subprocess.PIPE)
636 stdout, stderr = proc.communicate()
637 self.assertEquals(stdout, 'Hello world (distutils)\n')
638 self.assertEquals(proc.wait(), 0)
640 def test_autotools(self):
641 config = self.make_config()
642 module_list = [AutogenModule('hello',
643 self.make_branch(config, 'autotools'))]
644 module_list[0].config = self.config
645 build = jhbuild.frontends.terminal.TerminalBuildScript(
646 config, module_list)
647 with_stdout_hidden(build.build)
648 proc = subprocess.Popen(['hello'], stdout=subprocess.PIPE)
649 stdout, stderr = proc.communicate()
650 self.assertEquals(stdout, 'Hello world (autotools)\n')
651 self.assertEquals(proc.wait(), 0)
653 def test_autotools_with_libtool(self):
654 config = self.make_config()
655 module_list = [
656 AutogenModule('libhello', self.make_branch(config, 'libhello')),
657 AutogenModule('hello', self.make_branch(config, 'hello'))]
658 module_list[0].config = self.config
659 module_list[1].config = self.config
660 build = jhbuild.frontends.terminal.TerminalBuildScript(
661 config, module_list)
662 with_stdout_hidden(build.build)
663 proc = subprocess.Popen(['hello'], stdout=subprocess.PIPE)
664 stdout, stderr = proc.communicate()
665 self.assertEquals(stdout, 'Hello world (library test)\n')
666 self.assertEquals(proc.wait(), 0)
669 if __name__ == '__main__':
670 unittest.main()