2011-03-31 08:12:17 +00:00
|
|
|
# Copyright 2011 the V8 project authors. All rights reserved.
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are
|
|
|
|
# met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above
|
|
|
|
# copyright notice, this list of conditions and the following
|
|
|
|
# disclaimer in the documentation and/or other materials provided
|
|
|
|
# with the distribution.
|
|
|
|
# * Neither the name of Google Inc. nor the names of its
|
|
|
|
# contributors may be used to endorse or promote products derived
|
|
|
|
# from this software without specific prior written permission.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2012-09-24 09:38:46 +00:00
|
|
|
|
2011-03-31 08:12:17 +00:00
|
|
|
import os
|
|
|
|
|
2012-09-24 09:38:46 +00:00
|
|
|
from testrunner.local import testsuite
|
|
|
|
from testrunner.objects import testcase
|
|
|
|
|
|
|
|
|
|
|
|
class PreparserTestSuite(testsuite.TestSuite):
|
|
|
|
def __init__(self, name, root):
|
|
|
|
super(PreparserTestSuite, self).__init__(name, root)
|
|
|
|
|
|
|
|
def _ParsePythonTestTemplates(self, result, filename):
|
2013-04-18 11:01:14 +00:00
|
|
|
pathname = os.path.join(self.root, filename + ".pyt")
|
2014-12-10 20:09:32 +00:00
|
|
|
def Test(name, source, expectation, extra_flags=[]):
|
2012-09-24 09:38:46 +00:00
|
|
|
source = source.replace("\n", " ")
|
|
|
|
testname = os.path.join(filename, name)
|
|
|
|
flags = ["-e", source]
|
|
|
|
if expectation:
|
2013-10-04 16:21:23 +00:00
|
|
|
flags += ["--throws"]
|
2014-12-10 20:09:32 +00:00
|
|
|
flags += extra_flags
|
2012-09-24 09:38:46 +00:00
|
|
|
test = testcase.TestCase(self, testname, flags=flags)
|
|
|
|
result.append(test)
|
|
|
|
def Template(name, source):
|
|
|
|
def MkTest(replacement, expectation):
|
|
|
|
testname = name
|
|
|
|
testsource = source
|
|
|
|
for key in replacement.keys():
|
|
|
|
testname = testname.replace("$" + key, replacement[key]);
|
|
|
|
testsource = testsource.replace("$" + key, replacement[key]);
|
|
|
|
Test(testname, testsource, expectation)
|
|
|
|
return MkTest
|
|
|
|
execfile(pathname, {"Test": Test, "Template": Template})
|
|
|
|
|
|
|
|
def ListTests(self, context):
|
|
|
|
result = []
|
|
|
|
|
|
|
|
# Find all .pyt files in this directory.
|
|
|
|
filenames = [f[:-4] for f in os.listdir(self.root) if f.endswith(".pyt")]
|
|
|
|
filenames.sort()
|
|
|
|
for f in filenames:
|
|
|
|
self._ParsePythonTestTemplates(result, f)
|
|
|
|
return result
|
|
|
|
|
2017-10-27 12:55:29 +00:00
|
|
|
def GetParametersForTestCase(self, testcase, context):
|
2017-11-16 14:42:28 +00:00
|
|
|
return [], testcase.flags, {}
|
2012-09-24 09:38:46 +00:00
|
|
|
|
|
|
|
def GetSourceForTest(self, testcase):
|
2016-03-14 17:08:13 +00:00
|
|
|
assert testcase.flags[0] == "-e"
|
|
|
|
return testcase.flags[1]
|
2012-09-24 09:38:46 +00:00
|
|
|
|
2015-07-29 07:14:15 +00:00
|
|
|
def _VariantGeneratorFactory(self):
|
|
|
|
return testsuite.StandardVariantGenerator
|
2012-09-24 09:38:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
def GetSuite(name, root):
|
|
|
|
return PreparserTestSuite(name, root)
|