mirror of
https://github.com/tc39/test262.git
synced 2025-06-01 12:40:30 +02:00
- a lot of JS harness code written in strings have been moved out to actual physical files such as ed.js (syntax error detection for globally scoped tests) and gs.js (global scope test case validator). This change makes it far easier to maintain the test harness code - reorganized helper.js providing a clear indication which methods are used by external objects, which are implementation details, and which are unequivocally test262-specific. I've also added, openErrorWindow, which will be used to open a descriptive error message window for each test case failure reported on the 'Run' tab - improved the error message for syntax errors occurring when a test case fails to load - sta.js no longer tries to pickle all helper functions it contains! Instead, we load the file directly from sth.js. The performance of fnGlobalObject has been improved. Finally, the ES5Harness object has been moved from sth.js (in a string) to here - sth.js now has a browser implementer hook, controller.implementerHook, which allows browser implementers to handle test case failures in their own way (e.g., log to the filesystem). The 'run' function was basically re-written Added 37 new test cases from the "IE Test Center" Build release. There were 14 modifications to existing test cases as well. Refactored SputnikGlobalScope.js such that test case paths are now used as indices into the GlobalScopeTests array. TestCasePackager.py had the concept of templated test harnesses introduced - see templates\runner.test262.html. Also added support for one HTML test harness per ES5 chapter. Last but not least, TestCasePackagerConfig.py now has a 'source control' abstraction class which abstracts away source control adds|edits when dynamically generating *.json and *.html test chapters.
110 lines
5.2 KiB
Python
110 lines
5.2 KiB
Python
# Copyright (c) 2009 Microsoft Corporation
|
|
#
|
|
# 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 Microsoft 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.
|
|
|
|
#--Imports---------------------------------------------------------------------
|
|
import os
|
|
import subprocess
|
|
import stat
|
|
|
|
#--Globals---------------------------------------------------------------------
|
|
MAX_CASES_PER_JSON = 1000
|
|
|
|
#Directories under "test\suite\" containing ES5 test chapter directories
|
|
#with *.js tests underneath them
|
|
TEST_CONTRIB_DIRS = ["sputnik_converted", "ietestcenter"]
|
|
|
|
#Global scope source files found directly under "test\suite\".
|
|
GLOBAL_SCOPE_FILES = ["SputnikGlobalScope.js", "IETCGlobalScope.js"]
|
|
|
|
#Path to the root of the Hg repository (relative to this file's location)
|
|
TEST262_ROOT = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..")
|
|
TEST262_ROOT = os.path.abspath(TEST262_ROOT)
|
|
|
|
#Directory full of test cases we want to port to the website's test harness runner
|
|
TEST262_CASES_DIR = os.path.join(TEST262_ROOT, "test", "suite")
|
|
|
|
#Directory containing test harness files to be ported over to the website. Note that
|
|
#only *.js files will be migrated from this dir.
|
|
TEST262_HARNESS_DIR = os.path.join(TEST262_ROOT, "test", "harness")
|
|
|
|
#Directory full of website test cases (ported over from TEST262_CASES_DIR)
|
|
TEST262_WEB_CASES_DIR = os.path.join(TEST262_ROOT, "website", "resources", "scripts", "testcases")
|
|
|
|
#Directory containing the website's test harness (ported over from TEST262_HARNESS_DIR)
|
|
TEST262_WEB_HARNESS_DIR = os.path.join(TEST262_ROOT, "website", "resources", "scripts", "global")
|
|
|
|
#Path to the ported test case files on the actual website as opposed to the Hg layout
|
|
WEBSITE_CASES_PATH = "resources/scripts/testcases/"
|
|
|
|
#The name of a file which contains a list of tests which should be disabled in test262.
|
|
#These tests are either invalid as-per ES5 or have issues with the test262 web harness.
|
|
EXCLUDED_FILENAME = os.path.join(TEST262_ROOT, "test", "config", "excludelist.xml")
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
TEMPLATE_LINES = None
|
|
__lastHarnessType = None
|
|
|
|
def generateHarness(harnessType, jsonName, title):
|
|
global TEMPLATE_LINES
|
|
global __lastHarnessType
|
|
if TEMPLATE_LINES==None or harnessType!=__lastHarnessType:
|
|
__lastHarnessType = harnessType
|
|
TEMPLATE_LINES = []
|
|
with open(os.path.join(os.getcwd(), "templates","runner." + harnessType + ".html"), "r") as f:
|
|
TEMPLATE_LINES = f.readlines()
|
|
fileName = os.path.join(TEST262_ROOT, "website", jsonName.replace(".json", ".html"))
|
|
fileNameExists = False
|
|
if os.path.exists(fileName):
|
|
SC_HELPER.edit(fileName)
|
|
fileNameExists = True
|
|
with open(fileName, "w") as f:
|
|
for line in TEMPLATE_LINES:
|
|
if "var TEST_LIST_PATH =" in line:
|
|
f.write(" var TEST_LIST_PATH = \"resources/scripts/testcases/" + jsonName + "\";" + os.linesep)
|
|
#elif "ECMAScript 5" in line:
|
|
# f.write(line.replace("ECMAScript 5", "ECMAScript 5: %s" % title))
|
|
else:
|
|
f.write(line)
|
|
if not fileNameExists:
|
|
SC_HELPER.add(fileName)
|
|
|
|
#------------------------------------------------------------------------------
|
|
class SCAbstraction(object):
|
|
'''
|
|
A class which abstracts working with source control systems in relation to
|
|
generated test262 files. Useful when test262 is also used internally by
|
|
browser implementors.
|
|
'''
|
|
def edit(self, filename):
|
|
'''
|
|
Source control edit of a file. For Mercurial, just make sure it's
|
|
writable.
|
|
'''
|
|
if not(os.stat(filename).st_mode & stat.S_IWRITE):
|
|
os.chmod(filename, stat.S_IWRITE)
|
|
|
|
def add(self, filename):
|
|
'''
|
|
Source control add of a file.
|
|
'''
|
|
subprocess.call(["hg", "add", filename])
|
|
|
|
SC_HELPER = SCAbstraction() |