Bug 1266343 - Create a base class for configure tests, and use it for TestMozConfigure. r?chmanchester
--- a/python/mozbuild/mozbuild/test/configure/common.py
+++ b/python/mozbuild/mozbuild/test/configure/common.py
@@ -2,21 +2,24 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
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 (
topobjdir,
topsrcdir,
)
@@ -139,8 +142,54 @@ class ConfigureTestSandbox(ConfigureSand
raise subprocess.CalledProcessError(retcode, args, stdout)
return stdout
def shell(self, stdin, args):
script = mozpath.abspath(args[0])
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)
--- a/python/mozbuild/mozbuild/test/configure/test_moz_configure.py
+++ b/python/mozbuild/mozbuild/test/configure/test_moz_configure.py
@@ -1,68 +1,32 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
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 mozunit import main
-
-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']))
self.assertEquals('--enable-application=browser '
'MOZ_PROFILING=1',
get_value_for(['--enable-application=browser',
'MOZ_PROFILING=1']))