Bug 1262087 - Make the @checking callback not alter the behavior for bools. r=chmanchester
This commit is contained in:
@@ -54,14 +54,13 @@ def checking(what, callback=None):
|
|||||||
ret = func(*args, **kwargs)
|
ret = func(*args, **kwargs)
|
||||||
except FatalCheckError as e:
|
except FatalCheckError as e:
|
||||||
error = e.message
|
error = e.message
|
||||||
if callback:
|
display_ret = callback(ret) if callback else ret
|
||||||
log.info(callback(ret))
|
if display_ret is True:
|
||||||
elif ret is True:
|
|
||||||
log.info('yes')
|
log.info('yes')
|
||||||
elif ret is False:
|
elif display_ret is False or display_ret is None:
|
||||||
log.info('no')
|
log.info('no')
|
||||||
else:
|
else:
|
||||||
log.info(ret)
|
log.info(display_ret)
|
||||||
if error:
|
if error:
|
||||||
die(error)
|
die(error)
|
||||||
return ret
|
return ret
|
||||||
|
|||||||
@@ -52,6 +52,106 @@ class FindProgramSandbox(ConfigureSandbox):
|
|||||||
|
|
||||||
|
|
||||||
class TestChecksConfigure(unittest.TestCase):
|
class TestChecksConfigure(unittest.TestCase):
|
||||||
|
def test_checking(self):
|
||||||
|
out = StringIO()
|
||||||
|
sandbox = FindProgramSandbox({}, stdout=out, stderr=out)
|
||||||
|
base_dir = os.path.join(topsrcdir, 'build', 'moz.configure')
|
||||||
|
sandbox.exec_file(os.path.join(base_dir, 'checks.configure'))
|
||||||
|
|
||||||
|
exec(textwrap.dedent('''
|
||||||
|
@checking('for a thing')
|
||||||
|
def foo(value):
|
||||||
|
return value
|
||||||
|
'''), sandbox)
|
||||||
|
|
||||||
|
foo = sandbox['foo']
|
||||||
|
|
||||||
|
foo(True)
|
||||||
|
self.assertEqual(out.getvalue(), 'checking for a thing... yes\n')
|
||||||
|
|
||||||
|
out.truncate(0)
|
||||||
|
foo(False)
|
||||||
|
self.assertEqual(out.getvalue(), 'checking for a thing... no\n')
|
||||||
|
|
||||||
|
out.truncate(0)
|
||||||
|
foo(42)
|
||||||
|
self.assertEqual(out.getvalue(), 'checking for a thing... 42\n')
|
||||||
|
|
||||||
|
out.truncate(0)
|
||||||
|
foo('foo')
|
||||||
|
self.assertEqual(out.getvalue(), 'checking for a thing... foo\n')
|
||||||
|
|
||||||
|
out.truncate(0)
|
||||||
|
data = ['foo', 'bar']
|
||||||
|
foo(data)
|
||||||
|
self.assertEqual(out.getvalue(), 'checking for a thing... %r\n' % data)
|
||||||
|
|
||||||
|
# When the function given to checking does nothing interesting, the
|
||||||
|
# behavior is not altered
|
||||||
|
exec(textwrap.dedent('''
|
||||||
|
@checking('for a thing', lambda x: x)
|
||||||
|
def foo(value):
|
||||||
|
return value
|
||||||
|
'''), sandbox)
|
||||||
|
|
||||||
|
foo = sandbox['foo']
|
||||||
|
|
||||||
|
out.truncate(0)
|
||||||
|
foo(True)
|
||||||
|
self.assertEqual(out.getvalue(), 'checking for a thing... yes\n')
|
||||||
|
|
||||||
|
out.truncate(0)
|
||||||
|
foo(False)
|
||||||
|
self.assertEqual(out.getvalue(), 'checking for a thing... no\n')
|
||||||
|
|
||||||
|
out.truncate(0)
|
||||||
|
foo(42)
|
||||||
|
self.assertEqual(out.getvalue(), 'checking for a thing... 42\n')
|
||||||
|
|
||||||
|
out.truncate(0)
|
||||||
|
foo('foo')
|
||||||
|
self.assertEqual(out.getvalue(), 'checking for a thing... foo\n')
|
||||||
|
|
||||||
|
out.truncate(0)
|
||||||
|
data = ['foo', 'bar']
|
||||||
|
foo(data)
|
||||||
|
self.assertEqual(out.getvalue(), 'checking for a thing... %r\n' % data)
|
||||||
|
|
||||||
|
exec(textwrap.dedent('''
|
||||||
|
def munge(x):
|
||||||
|
if not x:
|
||||||
|
return 'not found'
|
||||||
|
if isinstance(x, (str, bool, int)):
|
||||||
|
return x
|
||||||
|
return ' '.join(x)
|
||||||
|
|
||||||
|
@checking('for a thing', munge)
|
||||||
|
def foo(value):
|
||||||
|
return value
|
||||||
|
'''), sandbox)
|
||||||
|
|
||||||
|
foo = sandbox['foo']
|
||||||
|
|
||||||
|
out.truncate(0)
|
||||||
|
foo(True)
|
||||||
|
self.assertEqual(out.getvalue(), 'checking for a thing... yes\n')
|
||||||
|
|
||||||
|
out.truncate(0)
|
||||||
|
foo(False)
|
||||||
|
self.assertEqual(out.getvalue(), 'checking for a thing... not found\n')
|
||||||
|
|
||||||
|
out.truncate(0)
|
||||||
|
foo(42)
|
||||||
|
self.assertEqual(out.getvalue(), 'checking for a thing... 42\n')
|
||||||
|
|
||||||
|
out.truncate(0)
|
||||||
|
foo('foo')
|
||||||
|
self.assertEqual(out.getvalue(), 'checking for a thing... foo\n')
|
||||||
|
|
||||||
|
out.truncate(0)
|
||||||
|
foo(['foo', 'bar'])
|
||||||
|
self.assertEqual(out.getvalue(), 'checking for a thing... foo bar\n')
|
||||||
|
|
||||||
def get_result(self, command='', args=[], environ={},
|
def get_result(self, command='', args=[], environ={},
|
||||||
prog='/bin/configure'):
|
prog='/bin/configure'):
|
||||||
config = {}
|
config = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user