Bug 1365477 - Ensure all callers of CommandLineHandler() pass a complete argv. r?chmanchester
CommandLineHandler() expects argv to be like sys.argv, containing the
command name in argv[0], but various tests weren't doing that, in some
cases even leading to ignored arguments passed as argv[0].
In turn, that made lint.py only test browser/moz.configure instead of
all the project moz.configures as intended.
--- a/python/mozbuild/mozbuild/configure/options.py
+++ b/python/mozbuild/mozbuild/configure/options.py
@@ -392,16 +392,17 @@ class CommandLineHelper(object):
'''
def __init__(self, environ=os.environ, argv=sys.argv):
self._environ = dict(environ)
self._args = OrderedDict()
self._extra_args = OrderedDict()
self._origins = {}
self._last = 0
+ assert(argv and not argv[0].startswith('--'))
for arg in argv[1:]:
self.add(arg, 'command-line', self._args)
def add(self, arg, origin='command-line', args=None):
assert origin != 'default'
prefix, name, values = Option.split_option(arg)
if args is None:
args = self._extra_args
--- a/python/mozbuild/mozbuild/test/configure/lint.py
+++ b/python/mozbuild/mozbuild/test/configure/lint.py
@@ -49,14 +49,14 @@ class Lint(unittest.TestCase):
def tearDown(self):
os.chdir(self._curdir)
def lint(self, project):
sandbox = LintSandbox({
'OLD_CONFIGURE': os.path.join(topsrcdir, 'old-configure'),
'MOZCONFIG': os.path.join(os.path.dirname(test_path), 'data',
'empty_mozconfig'),
- }, ['--enable-project=%s' % project, '--help'])
+ }, ['configure', '--enable-project=%s' % project, '--help'])
sandbox.run(os.path.join(topsrcdir, 'moz.configure'))
if __name__ == '__main__':
main()
--- a/python/mozbuild/mozbuild/test/configure/test_configure.py
+++ b/python/mozbuild/mozbuild/test/configure/test_configure.py
@@ -234,17 +234,17 @@ class TestConfigure(unittest.TestCase):
self.assertEquals(config['CFLAGS'], ['-Werror=foobar'])
config = self.get_config(env={'CC': 'clang'})
self.assertNotIn('CFLAGS', config)
def test_imports(self):
config = {}
out = StringIO()
- sandbox = ConfigureSandbox(config, {}, [], out, out)
+ sandbox = ConfigureSandbox(config, {}, ['configure'], out, out)
with self.assertRaises(ImportError):
exec_(textwrap.dedent('''
@template
def foo():
import sys
foo()'''),
sandbox
@@ -363,17 +363,17 @@ class TestConfigure(unittest.TestCase):
class CountApplyImportsSandbox(ConfigureSandbox):
def _apply_imports(self, *args, **kwargs):
imports.append((args, kwargs))
super(CountApplyImportsSandbox, self)._apply_imports(
*args, **kwargs)
config = {}
out = StringIO()
- sandbox = CountApplyImportsSandbox(config, {}, [], out, out)
+ sandbox = CountApplyImportsSandbox(config, {}, ['configure'], out, out)
exec_(textwrap.dedent('''
@template
@imports('sys')
def foo():
return sys
foo()
foo()'''),
@@ -401,17 +401,17 @@ class TestConfigure(unittest.TestCase):
def test_template_imports(self):
config = self.get_config(['--enable-imports-in-template'])
self.assertIn('PLATFORM', config)
self.assertEquals(config['PLATFORM'], sys.platform)
def test_decorators(self):
config = {}
out = StringIO()
- sandbox = ConfigureSandbox(config, {}, [], out, out)
+ sandbox = ConfigureSandbox(config, {}, ['configure'], out, out)
sandbox.include_file(mozpath.join(test_data_path, 'decorators.configure'))
self.assertNotIn('FOO', sandbox)
self.assertNotIn('BAR', sandbox)
self.assertNotIn('QUX', sandbox)
def test_set_config(self):
--- a/python/mozbuild/mozbuild/test/configure/test_options.py
+++ b/python/mozbuild/mozbuild/test/configure/test_options.py
@@ -660,16 +660,19 @@ class TestCommandLineHelper(unittest.Tes
self.assertEquals(PositiveOptionValue(), value)
self.assertEquals('--bar', option)
value, option = helper.handle(Option('--baz'))
self.assertEquals(['--foo', '--enable-qux'], list(helper))
self.assertEquals(NegativeOptionValue(), value)
self.assertEquals(None, option)
+ with self.assertRaises(AssertionError):
+ CommandLineHelper({}, ['--foo', '--bar'])
+
def test_precedence(self):
foo = Option('--with-foo', nargs='*')
helper = CommandLineHelper({}, ['cmd', '--with-foo=a,b'])
value, option = helper.handle(foo)
self.assertEquals(PositiveOptionValue(('a', 'b')), value)
self.assertEquals('command-line', value.origin)
self.assertEquals('--with-foo=a,b', option)
--- a/python/mozbuild/mozbuild/test/configure/test_util.py
+++ b/python/mozbuild/mozbuild/test/configure/test_util.py
@@ -416,17 +416,17 @@ class TestLineIO(unittest.TestCase):
self.assertEqual(lines, ['a', 'b', 'c'])
class TestLogSubprocessOutput(unittest.TestCase):
def test_non_ascii_subprocess_output(self):
out = StringIO()
- sandbox = ConfigureSandbox({}, {}, [], out, out)
+ sandbox = ConfigureSandbox({}, {}, ['configure'], out, out)
sandbox.include_file(mozpath.join(topsrcdir, 'build',
'moz.configure', 'util.configure'))
sandbox.include_file(mozpath.join(topsrcdir, 'python', 'mozbuild',
'mozbuild', 'test', 'configure',
'data', 'subprocess.configure'))
status = 0
try: