Bug 1296530 - Get help text out of TestConfigure.get_config when given --help. r?chmanchester draft
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 12 Oct 2016 11:11:56 +0900
changeset 425034 e4e0ec46b30ed1a8fe8c7812de6551bd4d22bfc7
parent 425033 e8c8ddfb166ecf0f080be3896d7975e210a2cb27
child 425035 370840715b43ecba02afe2162a678e1a70385c00
push id32321
push userbmo:mh+mozilla@glandium.org
push dateFri, 14 Oct 2016 02:53:47 +0000
reviewerschmanchester
bugs1296530
milestone52.0a1
Bug 1296530 - Get help text out of TestConfigure.get_config when given --help. r?chmanchester
python/mozbuild/mozbuild/test/configure/test_configure.py
--- a/python/mozbuild/mozbuild/test/configure/test_configure.py
+++ b/python/mozbuild/mozbuild/test/configure/test_configure.py
@@ -36,18 +36,19 @@ class TestConfigure(unittest.TestCase):
     def get_config(self, options=[], env={}, configure='moz.configure',
                    prog='/bin/configure'):
         config = {}
         out = StringIO()
         sandbox = ConfigureSandbox(config, env, [prog] + options, out, out)
 
         sandbox.run(mozpath.join(test_data_path, configure))
 
-        if '--help' not in options:
-            self.assertEquals('', out.getvalue())
+        if '--help' in options:
+            return out.getvalue(), config
+        self.assertEquals('', out.getvalue())
         return config
 
     def moz_configure(self, source):
         return MockedOpen({
             os.path.join(test_data_path,
                          'moz.configure'): textwrap.dedent(source)
         })
 
@@ -63,21 +64,17 @@ class TestConfigure(unittest.TestCase):
             'SIMPLE': NegativeOptionValue(),
             'VALUES': NegativeOptionValue(),
             'VALUES2': NegativeOptionValue(),
             'VALUES3': NegativeOptionValue(),
             'WITH_ENV': NegativeOptionValue(),
         }, config)
 
     def test_help(self):
-        config = {}
-        out = StringIO()
-        sandbox = ConfigureSandbox(config, {}, ['configure', '--help'],
-                                   out, out)
-        sandbox.run(mozpath.join(test_data_path, 'moz.configure'))
+        help, config = self.get_config(['--help'], prog='configure')
 
         self.assertEquals({}, config)
         self.maxDiff = None
         self.assertEquals(
             'Usage: configure [options]\n'
             '\n'
             'Options: [defaults in brackets after descriptions]\n'
             '  --help                    print this message\n'
@@ -91,17 +88,17 @@ class TestConfigure(unittest.TestCase):
             '  --returned-choices        Choices\n'
             '  --enable-imports-in-template\n'
             '                            Imports in template\n'
             '  --enable-include          Include\n'
             '  --with-imports            Imports\n'
             '\n'
             'Environment variables:\n'
             '  CC                        C Compiler\n',
-            out.getvalue()
+            help
         )
 
     def test_unknown(self):
         with self.assertRaises(InvalidOptionError):
             self.get_config(['--unknown'])
 
     def test_simple(self):
         for config in (
@@ -403,17 +400,17 @@ class TestConfigure(unittest.TestCase):
         self.assertNotIn('FOO', sandbox)
         self.assertNotIn('BAR', sandbox)
         self.assertNotIn('QUX', sandbox)
 
     def test_set_config(self):
         def get_config(*args):
             return self.get_config(*args, configure='set_config.configure')
 
-        config = get_config(['--help'])
+        help, config = get_config(['--help'])
         self.assertEquals(config, {})
 
         config = get_config(['--set-foo'])
         self.assertIn('FOO', config)
         self.assertEquals(config['FOO'], True)
 
         config = get_config(['--set-bar'])
         self.assertNotIn('FOO', config)
@@ -435,17 +432,17 @@ class TestConfigure(unittest.TestCase):
             # Both --set-foo and --set-name=FOO are going to try to
             # set_config('FOO'...)
             get_config(['--set-foo', '--set-name=FOO'])
 
     def test_set_define(self):
         def get_config(*args):
             return self.get_config(*args, configure='set_define.configure')
 
-        config = get_config(['--help'])
+        help, config = get_config(['--help'])
         self.assertEquals(config, {'DEFINES': {}})
 
         config = get_config(['--set-foo'])
         self.assertIn('FOO', config['DEFINES'])
         self.assertEquals(config['DEFINES']['FOO'], True)
 
         config = get_config(['--set-bar'])
         self.assertNotIn('FOO', config['DEFINES'])
@@ -468,17 +465,17 @@ class TestConfigure(unittest.TestCase):
             # set_define('FOO'...)
             get_config(['--set-foo', '--set-name=FOO'])
 
     def test_imply_option_simple(self):
         def get_config(*args):
             return self.get_config(
                 *args, configure='imply_option/simple.configure')
 
-        config = get_config(['--help'])
+        help, config = get_config(['--help'])
         self.assertEquals(config, {})
 
         config = get_config([])
         self.assertEquals(config, {})
 
         config = get_config(['--enable-foo'])
         self.assertIn('BAR', config)
         self.assertEquals(config['BAR'], PositiveOptionValue())
@@ -491,17 +488,17 @@ class TestConfigure(unittest.TestCase):
             "'--enable-bar' implied by '--enable-foo' conflicts with "
             "'--disable-bar' from the command-line")
 
     def test_imply_option_negative(self):
         def get_config(*args):
             return self.get_config(
                 *args, configure='imply_option/negative.configure')
 
-        config = get_config(['--help'])
+        help, config = get_config(['--help'])
         self.assertEquals(config, {})
 
         config = get_config([])
         self.assertEquals(config, {})
 
         config = get_config(['--enable-foo'])
         self.assertIn('BAR', config)
         self.assertEquals(config['BAR'], NegativeOptionValue())
@@ -526,17 +523,17 @@ class TestConfigure(unittest.TestCase):
             "'--disable-bar' implied by '--disable-hoge' conflicts with "
             "'--enable-bar' from the command-line")
 
     def test_imply_option_values(self):
         def get_config(*args):
             return self.get_config(
                 *args, configure='imply_option/values.configure')
 
-        config = get_config(['--help'])
+        help, config = get_config(['--help'])
         self.assertEquals(config, {})
 
         config = get_config([])
         self.assertEquals(config, {})
 
         config = get_config(['--enable-foo=a'])
         self.assertIn('BAR', config)
         self.assertEquals(config['BAR'], PositiveOptionValue(('a',)))
@@ -553,17 +550,17 @@ class TestConfigure(unittest.TestCase):
             "'--enable-bar=a,b' implied by '--enable-foo' conflicts with "
             "'--disable-bar' from the command-line")
 
     def test_imply_option_infer(self):
         def get_config(*args):
             return self.get_config(
                 *args, configure='imply_option/infer.configure')
 
-        config = get_config(['--help'])
+        help, config = get_config(['--help'])
         self.assertEquals(config, {})
 
         config = get_config([])
         self.assertEquals(config, {})
 
         with self.assertRaises(InvalidOptionError) as e:
             get_config(['--enable-foo', '--disable-bar'])
 
@@ -580,17 +577,17 @@ class TestConfigure(unittest.TestCase):
             "Cannot infer what implies '--enable-bar'. Please add a `reason` "
             "to the `imply_option` call.")
 
     def test_imply_option_immediate_value(self):
         def get_config(*args):
             return self.get_config(
                 *args, configure='imply_option/imm.configure')
 
-        config = get_config(['--help'])
+        help, config = get_config(['--help'])
         self.assertEquals(config, {})
 
         config = get_config([])
         self.assertEquals(config, {})
 
         config_path = mozpath.abspath(
             mozpath.join(test_data_path, 'imply_option', 'imm.configure'))