Bug 1354581 - Add unit tests for DEVELOPER_OPTIONS. r?chmanchester
--- a/python/mozbuild/mozbuild/test/configure/common.py
+++ b/python/mozbuild/mozbuild/test/configure/common.py
@@ -214,16 +214,25 @@ class ConfigureTestSandbox(ConfigureSand
script = mozpath.abspath(args[0])
if script in self._subprocess_paths:
return self._subprocess_paths[script](stdin, args[1:])
return 127, '', 'File not found'
def vswhere(self, stdin, args):
return 0, '[]', ''
+ def get_config(self, name):
+ # Like the loop in ConfigureSandbox.run, but only execute the code
+ # associated with the given config item.
+ for func, args in self._execution_queue:
+ if (func == self._resolve_and_set and args[0] is self._config
+ and args[1] == name):
+ func(*args)
+ return self._config.get(name)
+
class BaseConfigureTest(unittest.TestCase):
HOST = 'x86_64-pc-linux-gnu'
def setUp(self):
self._cwd = os.getcwd()
os.chdir(topobjdir)
--- a/python/mozbuild/mozbuild/test/configure/test_toolkit_moz_configure.py
+++ b/python/mozbuild/mozbuild/test/configure/test_toolkit_moz_configure.py
@@ -4,16 +4,17 @@
from __future__ import absolute_import, print_function, unicode_literals
import os
from buildconfig import topsrcdir
from common import BaseConfigureTest
from mozunit import main
+from mozbuild.configure.options import InvalidOptionError
class TestToolkitMozConfigure(BaseConfigureTest):
def test_necko_protocols(self):
def get_value(arg):
sandbox = self.get_sandbox({}, {}, [arg])
return sandbox._value_for(sandbox['necko_protocols'])
@@ -57,11 +58,28 @@ class TestToolkitMozConfigure(BaseConfig
self.assertEqual(
get_value('--enable-necko-protocols=all,-http,-about'),
tuple(p for p in default_protocols if p not in ('http', 'about')))
self.assertEqual(
get_value('--enable-necko-protocols=default,-http,-about'),
tuple(p for p in default_protocols if p not in ('http', 'about')))
+ def test_developer_options(self):
+ def get_value(args=[], environ={}):
+ sandbox = self.get_sandbox({}, {}, args, environ)
+ return sandbox.get_config('DEVELOPER_OPTIONS')
+
+ self.assertEqual(get_value(), True)
+
+ self.assertEqual(get_value(['--enable-release']), None)
+
+ self.assertEqual(get_value(environ={'MOZILLA_OFFICIAL': 1}), None)
+
+ self.assertEqual(get_value(['--enable-release'],
+ environ={'MOZILLA_OFFICIAL': 1}), None)
+
+ with self.assertRaises(InvalidOptionError):
+ get_value(['--disable-release'], environ={'MOZILLA_OFFICIAL': 1})
+
if __name__ == '__main__':
main()