[2.30] branched anjuta
[jhbuild/xnox.git] / tests / tests.py
blob4a2e28ec578b2855a3e2ccda239f91c68461ad66
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 if sys.platform.startswith('win'):
68 import jhbuild.utils.subprocess_win32 as subprocess_win32
69 class WindowsTestCase(unittest.TestCase):
70 '''Tests for Windows kludges.'''
71 def testCmdline2List(self):
72 cmdline = 'test "no quotes" != \\"no\\ quotes\\"'
73 cmd_list = subprocess_win32.cmdline2list (cmdline)
74 self.assertEqual (cmd_list, ['test', 'no quotes', '!=', '"no\\ quotes"'])
76 class ModuleOrderingTestCase(unittest.TestCase):
77 '''Module Ordering'''
79 def setUp(self):
80 self.moduleset = jhbuild.moduleset.ModuleSet()
81 self.moduleset.add(Package('foo'))
82 self.moduleset.add(Package('bar'))
83 self.moduleset.add(Package('baz'))
84 self.moduleset.add(Package('qux'))
85 self.moduleset.add(Package('quux'))
86 self.moduleset.add(Package('corge'))
88 def get_module_list(self, seed, skip=[]):
89 return [x.name for x in self.moduleset.get_module_list(seed, skip)]
91 def test_standalone_one(self):
92 '''A standalone module'''
93 self.assertEqual(self.get_module_list(['foo']), ['foo'])
95 def test_standalone_two(self):
96 '''Two standalone modules'''
97 self.assertEqual(self.get_module_list(['foo', 'bar']), ['foo', 'bar'])
99 def test_dependency_chain_straight(self):
100 '''A straight chain of dependencies'''
101 self.moduleset.modules['foo'].dependencies = ['bar']
102 self.moduleset.modules['bar'].dependencies = ['baz']
103 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'foo'])
105 def test_dependency_chain_straight_skip(self):
106 '''A straight chain of dependencies, with a module to skip'''
107 self.moduleset.modules['foo'].dependencies = ['bar']
108 self.moduleset.modules['bar'].dependencies = ['baz']
109 self.assertEqual(self.get_module_list(['foo'], ['bar']), ['foo'])
111 def test_dependency_chain_bi(self):
112 '''A dividing chain of dependencies'''
113 self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
114 self.moduleset.modules['bar'].dependencies = ['baz']
115 self.moduleset.modules['qux'].dependencies = ['quux']
116 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'quux', 'qux', 'foo'])
118 def test_dependency_cycle(self):
119 '''A chain of dependencies with a cycle'''
120 self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
121 self.moduleset.modules['bar'].dependencies = ['baz']
122 self.moduleset.modules['qux'].dependencies = ['quux', 'foo']
123 self.assertRaises(DependencyCycleError, self.get_module_list, ['foo'])
125 def test_dependency_chain_missing_dependencies(self):
126 '''A chain of dependencies with a missing <dependencies> module'''
127 self.moduleset.modules['foo'].dependencies = ['bar', 'plop']
128 self.moduleset.modules['bar'].dependencies = ['baz']
129 self.assertRaises(UsageError, self.get_module_list, ['foo'])
131 def test_dependency_chain_missing_after(self):
132 '''A chain of dependencies with a missing <after> module'''
133 self.moduleset.modules['foo'].dependencies = ['bar']
134 self.moduleset.modules['foo'].after = ['plop']
135 self.moduleset.modules['bar'].dependencies = ['baz']
136 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'foo'])
138 def test_dependency_chain_missing_suggests(self):
139 '''A chain of dependencies with a missing <suggests> module'''
140 self.moduleset.modules['foo'].dependencies = ['bar']
141 self.moduleset.modules['foo'].suggests = ['plop']
142 self.moduleset.modules['bar'].dependencies = ['baz']
143 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'foo'])
145 def test_dependency_chain_after(self):
146 '''A dividing chain of dependencies with an <after> module'''
147 self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
148 self.moduleset.modules['bar'].dependencies = ['baz']
149 self.moduleset.modules['baz'].after = ['qux']
150 self.moduleset.modules['qux'].dependencies = ['quux']
151 self.assertEqual(self.get_module_list(['foo']), ['quux', 'qux', 'baz', 'bar', 'foo'])
153 def test_dependency_chain_suggests(self):
154 '''A dividing chain of dependencies with an <suggests> module'''
155 self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
156 self.moduleset.modules['bar'].dependencies = ['baz']
157 self.moduleset.modules['baz'].suggests = ['qux']
158 self.moduleset.modules['qux'].dependencies = ['quux']
159 self.assertEqual(self.get_module_list(['foo']), ['quux', 'qux', 'baz', 'bar', 'foo'])
161 def test_dependency_cycle_after(self):
162 '''A chain of dependencies with a cycle caused by an <after> module'''
163 self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
164 self.moduleset.modules['bar'].dependencies = ['baz']
165 self.moduleset.modules['qux'].dependencies = ['quux']
166 self.moduleset.modules['qux'].after = ['foo']
167 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'quux', 'qux', 'foo'])
169 def test_dependency_cycle_suggests(self):
170 '''A chain of dependencies with a cycle caused by an <suggests> module'''
171 self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
172 self.moduleset.modules['bar'].dependencies = ['baz']
173 self.moduleset.modules['qux'].dependencies = ['quux']
174 self.moduleset.modules['qux'].suggests = ['foo']
175 self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'quux', 'qux', 'foo'])
177 def test_dependency_chain_recursive_after(self):
178 '''A chain of dependencies with a recursively defined <after> module'''
179 # see http://bugzilla.gnome.org/show_bug.cgi?id=546640
180 self.moduleset.modules['foo'] # gtk-doc
181 self.moduleset.modules['bar'].dependencies = ['foo'] # meta-bootstrap
182 self.moduleset.modules['bar'].type = 'meta'
183 self.moduleset.modules['baz'].after = ['bar'] # cairo
184 self.moduleset.modules['qux'].dependencies = ['baz'] # meta-stuff
185 self.assertEqual(self.get_module_list(['qux', 'foo']), ['foo', 'baz', 'qux'])
187 def test_dependency_chain_recursive_after_dependencies(self):
188 '''A chain dependency with an <after> module depending on an inversed relation'''
189 # see http://bugzilla.gnome.org/show_bug.cgi?id=546640
190 self.moduleset.modules['foo'] # nautilus
191 self.moduleset.modules['bar'] # nautilus-cd-burner
192 self.moduleset.modules['baz'] # tracker
193 self.moduleset.modules['foo'].after = ['baz']
194 self.moduleset.modules['bar'].dependencies = ['foo']
195 self.moduleset.modules['baz'].dependencies = ['bar']
196 self.assertEqual(self.get_module_list(['foo', 'bar']), ['foo', 'bar'])
199 class BuildTestCase(unittest.TestCase):
200 def setUp(self):
201 self.config = mock.Config()
202 self.branch = mock.Branch()
203 self.branch.config = self.config
204 self.buildscript = None
206 def build(self, packagedb_params = {}, **kwargs):
207 self.config.build_targets = ['install', 'test']
208 for k in kwargs:
209 setattr(self.config, k, kwargs[k])
210 self.config.update_build_targets()
212 if not self.buildscript or packagedb_params:
213 self.buildscript = mock.BuildScript(self.config, self.modules)
214 self.buildscript.packagedb = mock.PackageDB(**packagedb_params)
215 else:
216 packagedb = self.buildscript.packagedb
217 self.buildscript = mock.BuildScript(self.config, self.modules)
218 self.buildscript.packagedb = packagedb
220 self.buildscript.build()
221 return self.buildscript.actions
223 def tearDown(self):
224 self.buildscript = None
227 class AutotoolsModTypeTestCase(BuildTestCase):
228 '''Autotools steps'''
230 def setUp(self):
231 BuildTestCase.setUp(self)
232 self.modules = [AutogenModule('foo', self.branch)]
233 self.modules[0].config = self.config
234 # replace clean method as it checks for Makefile existence
235 self.modules[0].skip_clean = lambda x,y: False
237 def test_build(self):
238 '''Building a autotools module'''
239 self.assertEqual(self.build(),
240 ['foo:Checking out', 'foo:Configuring', 'foo:Building',
241 'foo:Installing'])
243 def test_build_no_network(self):
244 '''Building a autotools module, without network'''
245 self.assertEqual(self.build(nonetwork = True),
246 ['foo:Configuring', 'foo:Building', 'foo:Installing'])
248 def test_update(self):
249 '''Updating a autotools module'''
250 self.assertEqual(self.build(nobuild = True), ['foo:Checking out'])
252 def test_build_check(self):
253 '''Building a autotools module, with checks'''
254 self.assertEqual(self.build(makecheck = True),
255 ['foo:Checking out', 'foo:Configuring', 'foo:Building',
256 'foo:Checking', 'foo:Installing'])
258 def test_build_clean_and_check(self):
259 '''Building a autotools module, with cleaning and checks'''
260 self.assertEqual(self.build(makecheck = True, makeclean = True),
261 ['foo:Checking out', 'foo:Configuring', 'foo:Cleaning',
262 'foo:Building', 'foo:Checking', 'foo:Installing'])
264 def test_build_check_error(self):
265 '''Building a autotools module, with an error in make check'''
267 def make_check_error(buildscript, *args):
268 self.modules[0].do_check_orig(buildscript, *args)
269 raise CommandError('Mock Command Error Exception')
270 make_check_error.depends = self.modules[0].do_check.depends
271 make_check_error.error_phases = self.modules[0].do_check.error_phases
272 self.modules[0].do_check_orig = self.modules[0].do_check
273 self.modules[0].do_check = make_check_error
275 self.assertEqual(self.build(makecheck = True),
276 ['foo:Checking out', 'foo:Configuring', 'foo:Building',
277 'foo:Checking [error]'])
280 class WafModTypeTestCase(BuildTestCase):
281 '''Waf steps'''
283 def setUp(self):
284 BuildTestCase.setUp(self)
285 from jhbuild.modtypes.waf import WafModule
286 self.modules = [WafModule('foo', self.branch)]
287 self.modules[0].waf_cmd = 'true' # set a command for waf that always exist
289 def test_build(self):
290 '''Building a waf module'''
291 self.assertEqual(self.build(),
292 ['foo:Checking out', 'foo:Configuring', 'foo:Building',
293 'foo:Installing'])
295 def test_build_no_network(self):
296 '''Building a waf module, without network'''
297 self.assertEqual(self.build(nonetwork = True),
298 ['foo:Configuring', 'foo:Building', 'foo:Installing'])
300 def test_update(self):
301 '''Updating a waf module'''
302 self.assertEqual(self.build(nobuild = True), ['foo:Checking out'])
304 def test_build_check(self):
305 '''Building a waf module, with checks'''
306 self.assertEqual(self.build(makecheck = True),
307 ['foo:Checking out', 'foo:Configuring', 'foo:Building',
308 'foo:Checking', 'foo:Installing'])
310 def test_build_clean_and_check(self):
311 '''Building a waf module, with cleaning and checks'''
312 self.assertEqual(self.build(makecheck = True, makeclean = True),
313 ['foo:Checking out', 'foo:Configuring', 'foo:Cleaning',
314 'foo:Building', 'foo:Checking', 'foo:Installing'])
316 def test_build_check_error(self):
317 '''Building a waf module, with an error in make check'''
319 def make_check_error(buildscript, *args):
320 self.modules[0].do_check_orig(buildscript, *args)
321 raise CommandError('Mock Command Error Exception')
322 make_check_error.depends = self.modules[0].do_check.depends
323 make_check_error.error_phases = self.modules[0].do_check.error_phases
324 self.modules[0].do_check_orig = self.modules[0].do_check
325 self.modules[0].do_check = make_check_error
327 self.assertEqual(self.build(makecheck = True),
328 ['foo:Checking out', 'foo:Configuring', 'foo:Building',
329 'foo:Checking [error]'])
331 def test_build_missing_waf_command(self):
332 '''Building a waf module, on a system missing the waf command'''
333 self.modules[0].waf_cmd = 'foo bar'
334 self.assertEqual(self.build(),
335 ['foo:Checking out', 'foo:Configuring [error]'])
341 class BuildPolicyTestCase(BuildTestCase):
342 '''Build Policy'''
344 def setUp(self):
345 BuildTestCase.setUp(self)
346 self.modules = [AutogenModule('foo', self.branch)]
347 self.modules[0].config = self.config
349 def test_policy_all(self):
350 '''Building an uptodate module with build policy set to "all"'''
351 self.config.build_policy = 'all'
352 self.assertEqual(self.build(packagedb_params = {'uptodate': True}),
353 ['foo:Checking out', 'foo:Configuring', 'foo:Building',
354 'foo:Installing'])
356 def test_policy_updated(self):
357 '''Building an uptodate module with build policy set to "updated"'''
358 self.config.build_policy = 'updated'
359 self.assertEqual(self.build(packagedb_params = {'uptodate': True}),
360 ['foo:Checking out'])
362 def test_policy_all_with_no_network(self):
363 '''Building an uptodate module with "all" policy, without network'''
364 self.config.build_policy = 'all'
365 self.assertEqual(self.build(
366 packagedb_params = {'uptodate': True},
367 nonetwork = True),
368 ['foo:Configuring', 'foo:Building', 'foo:Installing'])
370 def test_policy_updated_with_no_network(self):
371 '''Building an uptodate module with "updated" policy, without network'''
372 self.config.build_policy = 'updated'
373 self.assertEqual(self.build(
374 packagedb_params = {'uptodate': True},
375 nonetwork = True), [])
378 class TestModTypeTestCase(BuildTestCase):
379 '''Tests Module Steps'''
381 def setUp(self):
382 BuildTestCase.setUp(self)
383 from jhbuild.modtypes.testmodule import TestModule
384 self.modules = [TestModule('foo', self.branch, 'dogtail')]
386 def test_run(self):
387 '''Running a test module'''
388 self.assertEqual(self.build(), ['foo:Checking out', 'foo:Testing'])
390 def test_build_no_network(self):
391 '''Running a test module, without network'''
392 self.assertEqual(self.build(nonetwork = True), ['foo:Testing'])
395 class TwoModulesTestCase(BuildTestCase):
396 '''Building two dependent modules'''
398 def setUp(self):
399 BuildTestCase.setUp(self)
400 self.foo_branch = mock.Branch()
401 self.modules = [AutogenModule('foo', self.foo_branch),
402 AutogenModule('bar', self.branch)]
403 self.modules[0].config = self.config
404 self.modules[1].config = self.config
406 def test_build(self):
407 '''Building two autotools module'''
408 self.assertEqual(self.build(),
409 ['foo:Checking out', 'foo:Configuring',
410 'foo:Building', 'foo:Installing',
411 'bar:Checking out', 'bar:Configuring',
412 'bar:Building', 'bar:Installing',
415 def test_build_failure_independent_modules(self):
416 '''Building two independent autotools modules, with failure in first'''
418 def build_error(buildscript, *args):
419 self.modules[0].do_build_orig(buildscript, *args)
420 raise CommandError('Mock Command Error Exception')
421 build_error.depends = self.modules[0].do_build.depends
422 build_error.error_phases = self.modules[0].do_build.error_phases
423 self.modules[0].do_build_orig = self.modules[0].do_build
424 self.modules[0].do_build = build_error
426 self.assertEqual(self.build(),
427 ['foo:Checking out', 'foo:Configuring', 'foo:Building [error]',
428 'bar:Checking out', 'bar:Configuring',
429 'bar:Building', 'bar:Installing',
432 def test_build_failure_dependent_modules(self):
433 '''Building two dependent autotools modules, with failure in first'''
434 self.modules[1].dependencies = ['foo']
436 def build_error(buildscript, *args):
437 self.modules[0].do_build_orig(buildscript, *args)
438 raise CommandError('Mock Command Error Exception')
439 build_error.depends = self.modules[0].do_build.depends
440 build_error.error_phases = self.modules[0].do_build.error_phases
441 self.modules[0].do_build_orig = self.modules[0].do_build
442 self.modules[0].do_build = build_error
444 self.assertEqual(self.build(),
445 ['foo:Checking out', 'foo:Configuring', 'foo:Building [error]'])
447 def test_build_failure_dependent_modules_nopoison(self):
448 '''Building two dependent autotools modules, with failure, but nopoison'''
449 self.modules[1].dependencies = ['foo']
451 def build_error(buildscript, *args):
452 self.modules[0].do_build_orig(buildscript, *args)
453 raise CommandError('Mock Command Error Exception')
454 build_error.depends = self.modules[0].do_build.depends
455 build_error.error_phases = self.modules[0].do_build.error_phases
456 self.modules[0].do_build_orig = self.modules[0].do_build
457 self.modules[0].do_build = build_error
459 self.assertEqual(self.build(nopoison = True),
460 ['foo:Checking out', 'foo:Configuring', 'foo:Building [error]',
461 'bar:Checking out', 'bar:Configuring',
462 'bar:Building', 'bar:Installing',
465 def test_build_no_update(self):
466 '''Building two uptodate, autotools module'''
467 self.build() # will feed PackageDB
468 self.assertEqual(self.build(),
469 ['foo:Checking out', 'foo:Configuring',
470 'foo:Building', 'foo:Installing',
471 'bar:Checking out', 'bar:Configuring',
472 'bar:Building', 'bar:Installing',
475 def test_build_no_update_updated_policy(self):
476 '''Building two uptodate, autotools module, with 'updated' policy'''
477 self.build() # will feed PackageDB
478 self.assertEqual(self.build(build_policy = 'updated'),
479 ['foo:Checking out', 'bar:Checking out'])
481 def test_build_no_update_updated_deps_policy(self):
482 '''Building two autotools module, (changed and not), with 'updated-deps' policy'''
483 self.modules[1].dependencies = ['foo']
484 self.build() # will feed PackageDB
485 self.buildscript.packagedb.remove('foo')
486 self.buildscript.packagedb.time_delta = 5
487 self.assertEqual(self.build(build_policy = 'updated-deps'),
488 ['foo:Checking out', 'foo:Configuring',
489 'foo:Building', 'foo:Installing',
490 'bar:Checking out', 'bar:Configuring',
491 'bar:Building', 'bar:Installing',
494 def test_build_no_update_updated_deps_policy(self):
495 '''Building two independent autotools module, (changed and not), with 'updated-deps' policy'''
496 self.build() # will feed PackageDB
497 self.buildscript.packagedb.remove('foo')
498 self.buildscript.packagedb.time_delta = 5
499 self.assertEqual(self.build(build_policy = 'updated-deps'),
500 ['foo:Checking out', 'foo:Configuring',
501 'foo:Building', 'foo:Installing',
502 'bar:Checking out',])
504 def test_make_check_failure_dependent_modules(self):
505 '''Building two dependent autotools modules, with failure in make check'''
506 self.modules[1].dependencies = ['foo']
508 def check_error(buildscript, *args):
509 self.modules[0].do_check_orig(buildscript, *args)
510 raise CommandError('Mock Command Error Exception')
511 check_error.depends = self.modules[0].do_check.depends
512 check_error.error_phases = self.modules[0].do_check.error_phases
513 self.modules[0].do_check_orig = self.modules[0].do_check
514 self.modules[0].do_check = check_error
516 self.assertEqual(self.build(makecheck = True),
517 ['foo:Checking out', 'foo:Configuring',
518 'foo:Building', 'foo:Checking [error]'])
520 def test_make_check_failure_dependent_modules_makecheck_advisory(self):
521 '''Building two dependent autotools modules, with *advisory* failure in make check'''
522 self.modules[1].dependencies = ['foo']
524 def check_error(buildscript, *args):
525 buildscript.execute_is_failure = True
526 try:
527 self.modules[0].do_check_orig(buildscript, *args)
528 finally:
529 buildscript.execute_is_failure = False
530 check_error.depends = self.modules[0].do_check.depends
531 check_error.error_phases = self.modules[0].do_check.error_phases
532 self.modules[0].do_check_orig = self.modules[0].do_check
533 self.modules[0].do_check = check_error
535 self.assertEqual(self.build(makecheck = True, makecheck_advisory = True),
536 ['foo:Checking out', 'foo:Configuring',
537 'foo:Building', 'foo:Checking', 'foo:Installing',
538 'bar:Checking out', 'bar:Configuring',
539 'bar:Building', 'bar:Checking', 'bar:Installing'])
542 class TestConfig(jhbuild.config.Config):
544 # The Config base class calls setup_env() in the constructor, but
545 # we need to override some attributes before calling it.
546 def setup_env(self):
547 pass
549 def real_setup_env(self):
550 jhbuild.config.Config.setup_env(self)
553 class SimpleBranch(object):
555 def __init__(self, name, dir_path):
556 self.branchname = name
557 self.srcdir = dir_path
559 def checkout(self, buildscript):
560 pass
562 def may_checkout(self, buildscript):
563 return True
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 null_device = '/dev/null'
581 if sys.platform.startswith('win'):
582 null_device = 'NUL'
583 old_fd = os.dup(STDOUT_FILENO)
584 new_fd = os.open(null_device, os.O_WRONLY)
585 os.dup2(new_fd, STDOUT_FILENO)
586 os.close(new_fd)
587 try:
588 return func()
589 finally:
590 os.dup2(old_fd, STDOUT_FILENO)
591 os.close(old_fd)
594 class EndToEndTest(unittest.TestCase):
596 def setUp(self):
597 self.config = mock.Config()
598 self._old_env = os.environ.copy()
599 self._temp_dirs = []
601 def tearDown(self):
602 restore_environ(self._old_env)
603 for temp_dir in self._temp_dirs:
604 shutil.rmtree(temp_dir)
606 def make_temp_dir(self):
607 temp_dir = tempfile.mkdtemp(prefix='unittest-')
608 self._temp_dirs.append(temp_dir)
609 return temp_dir
611 def make_config(self):
612 temp_dir = self.make_temp_dir()
613 config = TestConfig()
614 config.checkoutroot = os.path.abspath(os.path.join(temp_dir, 'checkout'))
615 config.prefix = os.path.abspath(os.path.join(temp_dir, 'prefix'))
616 os.makedirs(config.checkoutroot)
617 os.makedirs(config.prefix)
618 config.interact = False
619 config.quiet_mode = True # Not enough to disable output entirely
620 config.progress_bar = False
621 config.real_setup_env()
622 return config
624 def make_branch(self, config, src_name):
625 branch_dir = os.path.join(config.checkoutroot, src_name)
626 shutil.copytree(os.path.join(os.path.dirname(__file__), src_name),
627 branch_dir)
628 return SimpleBranch(src_name, branch_dir)
630 # FIXME: broken under Win32
631 def test_distutils(self):
632 config = self.make_config()
633 module_list = [DistutilsModule('hello',
634 self.make_branch(config, 'distutils'))]
635 module_list[0].config = self.config
636 build = jhbuild.frontends.terminal.TerminalBuildScript(
637 config, module_list)
638 with_stdout_hidden(build.build)
639 proc = subprocess.Popen(['hello'], stdout=subprocess.PIPE)
640 stdout, stderr = proc.communicate()
641 self.assertEquals(stdout.strip(), 'Hello world (distutils)')
642 self.assertEquals(proc.wait(), 0)
644 def test_autotools(self):
645 config = self.make_config()
646 module_list = [AutogenModule('hello',
647 self.make_branch(config, 'autotools'))]
648 module_list[0].config = self.config
649 build = jhbuild.frontends.terminal.TerminalBuildScript(
650 config, module_list)
651 with_stdout_hidden(build.build)
652 proc = subprocess.Popen(['hello'], stdout=subprocess.PIPE)
653 stdout, stderr = proc.communicate()
654 self.assertEquals(stdout.strip(), 'Hello world (autotools)')
655 self.assertEquals(proc.wait(), 0)
657 # Won't pass under stock MSYS because pkgconfig isn't installed in base
658 # path. Will work if you set ACLOCAL_FLAGS, PATH and PKG_CONFIG_PATH to
659 # a prefix where pkg-config is installed.
660 def test_autotools_with_libtool(self):
661 config = self.make_config()
662 module_list = [
663 AutogenModule('libhello', self.make_branch(config, 'libhello')),
664 AutogenModule('hello', self.make_branch(config, 'hello'))]
665 module_list[0].config = self.config
666 module_list[1].config = self.config
667 build = jhbuild.frontends.terminal.TerminalBuildScript(
668 config, module_list)
669 with_stdout_hidden(build.build)
670 proc = subprocess.Popen(['hello'], stdout=subprocess.PIPE)
671 stdout, stderr = proc.communicate()
672 self.assertEquals(stdout.strip(), 'Hello world (library test)')
673 self.assertEquals(proc.wait(), 0)
676 if __name__ == '__main__':
677 unittest.main()