зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1266343 - Create a base class for configure tests, and use it for TestMozConfigure. r=chmanchester
This commit is contained in:
Родитель
44b5cc5dc5
Коммит
589f651a98
|
@ -7,11 +7,14 @@ from __future__ import absolute_import, print_function, unicode_literals
|
|||
import errno
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from mozbuild.configure import ConfigureSandbox
|
||||
from mozbuild.util import ReadOnlyNamespace
|
||||
from mozpack import path as mozpath
|
||||
|
||||
from StringIO import StringIO
|
||||
from which import WhichError
|
||||
|
||||
from buildconfig import (
|
||||
|
@ -144,3 +147,49 @@ class ConfigureTestSandbox(ConfigureSandbox):
|
|||
if script in self._subprocess_paths:
|
||||
return self._subprocess_paths[script](stdin, args[1:])
|
||||
return 127, '', 'File not found'
|
||||
|
||||
|
||||
class BaseConfigureTest(unittest.TestCase):
|
||||
HOST = 'x86_64-pc-linux-gnu'
|
||||
|
||||
def setUp(self):
|
||||
self._cwd = os.getcwd()
|
||||
os.chdir(topobjdir)
|
||||
|
||||
def tearDown(self):
|
||||
os.chdir(self._cwd)
|
||||
|
||||
def config_guess(self, stdin, args):
|
||||
return 0, self.HOST, ''
|
||||
|
||||
def config_sub(self, stdin, args):
|
||||
return 0, args[0], ''
|
||||
|
||||
def get_sandbox(self, paths, config, args=[], environ={}, mozconfig='',
|
||||
out=None):
|
||||
if not out:
|
||||
out = StringIO()
|
||||
|
||||
fh, mozconfig_path = tempfile.mkstemp()
|
||||
os.write(fh, mozconfig)
|
||||
os.close(fh)
|
||||
|
||||
try:
|
||||
environ = dict(
|
||||
environ,
|
||||
OLD_CONFIGURE=os.path.join(topsrcdir, 'old-configure'),
|
||||
MOZCONFIG=mozconfig_path)
|
||||
|
||||
paths = dict(paths)
|
||||
autoconf_dir = mozpath.join(topsrcdir, 'build', 'autoconf')
|
||||
paths[mozpath.join(autoconf_dir,
|
||||
'config.guess')] = self.config_guess
|
||||
paths[mozpath.join(autoconf_dir, 'config.sub')] = self.config_sub
|
||||
|
||||
sandbox = ConfigureTestSandbox(paths, config, environ,
|
||||
['configure'] + args, out, out)
|
||||
sandbox.include_file(os.path.join(topsrcdir, 'moz.configure'))
|
||||
|
||||
return sandbox
|
||||
finally:
|
||||
os.remove(mozconfig_path)
|
||||
|
|
|
@ -4,60 +4,24 @@
|
|||
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
from StringIO import StringIO
|
||||
import os
|
||||
import tempfile
|
||||
import textwrap
|
||||
import unittest
|
||||
|
||||
from mozunit import main
|
||||
from mozpack import path as mozpath
|
||||
|
||||
from mozbuild.configure import ConfigureSandbox
|
||||
|
||||
from buildconfig import (
|
||||
topobjdir,
|
||||
topsrcdir,
|
||||
)
|
||||
from common import BaseConfigureTest
|
||||
|
||||
|
||||
class TestMozConfigure(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self._cwd = os.getcwd()
|
||||
|
||||
def tearDown(self):
|
||||
os.chdir(self._cwd)
|
||||
|
||||
def get_value_for(self, key, args=[], environ={}, mozconfig=''):
|
||||
os.chdir(topobjdir)
|
||||
|
||||
config = {}
|
||||
out = StringIO()
|
||||
|
||||
fh, mozconfig_path = tempfile.mkstemp()
|
||||
os.write(fh, mozconfig)
|
||||
os.close(fh)
|
||||
|
||||
try:
|
||||
environ = dict(environ,
|
||||
OLD_CONFIGURE=os.path.join(topsrcdir, 'configure'),
|
||||
MOZCONFIG=mozconfig_path)
|
||||
|
||||
sandbox = ConfigureSandbox(config, environ, ['configure'] + args,
|
||||
out, out)
|
||||
sandbox.include_file(os.path.join(topsrcdir, 'moz.configure'))
|
||||
class TestMozConfigure(BaseConfigureTest):
|
||||
def test_moz_configure_options(self):
|
||||
def get_value_for(args=[], environ={}, mozconfig=''):
|
||||
sandbox = self.get_sandbox({}, {}, args, environ, mozconfig)
|
||||
|
||||
# Add a fake old-configure option
|
||||
sandbox.option_impl('--with-foo', nargs='*',
|
||||
help='Help missing for old configure options')
|
||||
|
||||
return sandbox._value_for(sandbox[key])
|
||||
finally:
|
||||
os.remove(mozconfig_path)
|
||||
|
||||
def test_moz_configure_options(self):
|
||||
def get_value_for(args=[], environ={}, mozconfig=''):
|
||||
return self.get_value_for('all_configure_options', args, environ,
|
||||
mozconfig)
|
||||
result = sandbox._value_for(sandbox['all_configure_options'])
|
||||
shell = mozpath.abspath('/bin/sh')
|
||||
return result.replace('CONFIG_SHELL=%s ' % shell, '')
|
||||
|
||||
self.assertEquals('--enable-application=browser',
|
||||
get_value_for(['--enable-application=browser']))
|
||||
|
|
Загрузка…
Ссылка в новой задаче