Bug 1266343 - Create a base class for configure tests, and use it for TestMozConfigure. r?chmanchester draft
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 20 Apr 2016 13:49:00 +0900
changeset 354784 93183146ae097d21ace6b1b1392bfa4bb60213c6
parent 354783 463a6f38907284ecaf004aaffb052bef804aa103
child 354785 d5fc3fc9d3437bc96d5a0d57ecede8bc215637a0
push id16148
push userbmo:mh+mozilla@glandium.org
push dateThu, 21 Apr 2016 12:30:02 +0000
reviewerschmanchester
bugs1266343
milestone48.0a1
Bug 1266343 - Create a base class for configure tests, and use it for TestMozConfigure. r?chmanchester
python/mozbuild/mozbuild/test/configure/common.py
python/mozbuild/mozbuild/test/configure/test_moz_configure.py
--- 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']))