2016-12-19 10:13:48 +00:00
|
|
|
# Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
2016-12-20 09:33:55 +00:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2016-12-19 10:13:48 +00:00
|
|
|
import unittest
|
|
|
|
|
2016-12-20 09:33:55 +00:00
|
|
|
import v8_foozzie
|
2016-12-19 10:13:48 +00:00
|
|
|
import v8_suppressions
|
|
|
|
|
2016-12-20 09:33:55 +00:00
|
|
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
FOOZZIE = os.path.join(BASE_DIR, 'v8_foozzie.py')
|
|
|
|
TEST_DATA = os.path.join(BASE_DIR, 'testdata')
|
|
|
|
|
|
|
|
class UnitTest(unittest.TestCase):
|
2016-12-19 10:13:48 +00:00
|
|
|
def testDiff(self):
|
|
|
|
# TODO(machenbach): Mock out suppression configuration.
|
|
|
|
suppress = v8_suppressions.get_suppression(
|
2017-04-27 14:44:36 +00:00
|
|
|
'x64', 'ignition', 'x64', 'ignition_turbo')
|
2016-12-19 10:13:48 +00:00
|
|
|
one = ''
|
|
|
|
two = ''
|
2017-01-16 19:53:35 +00:00
|
|
|
diff = None, None
|
2016-12-19 10:13:48 +00:00
|
|
|
self.assertEquals(diff, suppress.diff(one, two))
|
|
|
|
|
|
|
|
one = 'a \n b\nc();'
|
|
|
|
two = 'a \n b\nc();'
|
2017-01-16 19:53:35 +00:00
|
|
|
diff = None, None
|
2016-12-19 10:13:48 +00:00
|
|
|
self.assertEquals(diff, suppress.diff(one, two))
|
|
|
|
|
2017-04-27 14:44:36 +00:00
|
|
|
# Ignore line before caret, caret position and error message.
|
2016-12-19 10:13:48 +00:00
|
|
|
one = """
|
|
|
|
undefined
|
|
|
|
weird stuff
|
|
|
|
^
|
|
|
|
somefile.js: TypeError: undefined is not a function
|
|
|
|
undefined
|
|
|
|
"""
|
|
|
|
two = """
|
|
|
|
undefined
|
|
|
|
other weird stuff
|
|
|
|
^
|
|
|
|
somefile.js: TypeError: baz is not a function
|
|
|
|
undefined
|
|
|
|
"""
|
2017-01-16 19:53:35 +00:00
|
|
|
diff = None, None
|
2016-12-19 10:13:48 +00:00
|
|
|
self.assertEquals(diff, suppress.diff(one, two))
|
|
|
|
|
|
|
|
one = """
|
|
|
|
Still equal
|
|
|
|
Extra line
|
|
|
|
"""
|
|
|
|
two = """
|
|
|
|
Still equal
|
|
|
|
"""
|
2017-01-16 19:53:35 +00:00
|
|
|
diff = '- Extra line', None
|
2016-12-19 10:13:48 +00:00
|
|
|
self.assertEquals(diff, suppress.diff(one, two))
|
|
|
|
|
|
|
|
one = """
|
|
|
|
Still equal
|
|
|
|
"""
|
|
|
|
two = """
|
|
|
|
Still equal
|
|
|
|
Extra line
|
|
|
|
"""
|
2017-01-16 19:53:35 +00:00
|
|
|
diff = '+ Extra line', None
|
2016-12-19 10:13:48 +00:00
|
|
|
self.assertEquals(diff, suppress.diff(one, two))
|
|
|
|
|
|
|
|
one = """
|
|
|
|
undefined
|
|
|
|
somefile.js: TypeError: undefined is not a constructor
|
|
|
|
"""
|
|
|
|
two = """
|
|
|
|
undefined
|
|
|
|
otherfile.js: TypeError: undefined is not a constructor
|
|
|
|
"""
|
|
|
|
diff = """- somefile.js: TypeError: undefined is not a constructor
|
2017-01-16 19:53:35 +00:00
|
|
|
+ otherfile.js: TypeError: undefined is not a constructor""", None
|
2016-12-19 10:13:48 +00:00
|
|
|
self.assertEquals(diff, suppress.diff(one, two))
|
2016-12-20 09:33:55 +00:00
|
|
|
|
|
|
|
|
2017-02-03 14:34:56 +00:00
|
|
|
def cut_verbose_output(stdout):
|
|
|
|
return '\n'.join(stdout.split('\n')[2:])
|
|
|
|
|
|
|
|
|
2016-12-20 09:33:55 +00:00
|
|
|
def run_foozzie(first_d8, second_d8):
|
|
|
|
return subprocess.check_output([
|
|
|
|
sys.executable, FOOZZIE,
|
|
|
|
'--random-seed', '12345',
|
|
|
|
'--first-d8', os.path.join(TEST_DATA, first_d8),
|
|
|
|
'--second-d8', os.path.join(TEST_DATA, second_d8),
|
2017-01-18 15:23:53 +00:00
|
|
|
'--first-config', 'ignition',
|
2017-03-14 22:10:56 +00:00
|
|
|
'--second-config', 'ignition_turbo',
|
2017-01-09 18:19:40 +00:00
|
|
|
os.path.join(TEST_DATA, 'fuzz-123.js'),
|
2016-12-20 09:33:55 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
class SystemTest(unittest.TestCase):
|
|
|
|
def testSyntaxErrorDiffPass(self):
|
|
|
|
stdout = run_foozzie('test_d8_1.py', 'test_d8_2.py')
|
2017-02-03 14:34:56 +00:00
|
|
|
self.assertEquals('# V8 correctness - pass\n', cut_verbose_output(stdout))
|
2016-12-20 09:33:55 +00:00
|
|
|
|
|
|
|
def testDifferentOutputFail(self):
|
|
|
|
with open(os.path.join(TEST_DATA, 'failure_output.txt')) as f:
|
|
|
|
expected_output = f.read()
|
|
|
|
with self.assertRaises(subprocess.CalledProcessError) as ctx:
|
|
|
|
run_foozzie('test_d8_1.py', 'test_d8_3.py')
|
|
|
|
e = ctx.exception
|
|
|
|
self.assertEquals(v8_foozzie.RETURN_FAIL, e.returncode)
|
2017-02-03 14:34:56 +00:00
|
|
|
self.assertEquals(expected_output, cut_verbose_output(e.output))
|