Just reformatting to 80 columns

This commit is contained in:
Mark Miller 2011-09-30 03:59:50 -04:00
parent a8625046d2
commit 64db10aa2d
3 changed files with 124 additions and 64 deletions

View File

@ -1,14 +1,14 @@
/// Copyright (c) 2011 Microsoft Corporation /// Copyright (c) 2011 Microsoft Corporation
/// ///
/// Redistribution and use in source and binary forms, with or without modification, are permitted provided /// Redistribution and use in source and binary forms, with or without modification, are permitted provided
/// that the following conditions are met: /// that the following conditions are met:
/// * Redistributions of source code must retain the above copyright notice, this list of conditions and /// * Redistributions of source code must retain the above copyright notice, this list of conditions and
/// the following disclaimer. /// the following disclaimer.
/// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and /// * 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. /// 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 /// * 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. /// 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 /// 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 /// 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 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
@ -16,40 +16,68 @@
/// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS /// 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, /// 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 /// 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. /// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//Global Scope Test Case Validator //Global Scope Test Case Validator
//An exception is expected //An exception is expected
if (testDescrip.negative !== undefined) { if (testDescrip.negative !== undefined) {
//TODO - come up with a generic way of catching the error type from this.onerror //TODO - come up with a generic way of catching the error type
//from this.onerror
testDescrip.negative = testDescrip.negative === "NotEarlyError" ? testDescrip.negative = testDescrip.negative === "NotEarlyError" ?
testDescrip.negative : (testDescrip.negative === "^((?!NotEarlyError).)*$" ? testDescrip.negative :
testDescrip.negative : "."); (testDescrip.negative === "^((?!NotEarlyError).)*$" ?
testDescrip.negative : ".");
if (this.iframeError === undefined) { //no exception was thrown if (this.iframeError === undefined) { //no exception was thrown
testRun(testDescrip.id, testDescrip.path, testDescrip.description, testDescrip.code, testRun(testDescrip.id,
'fail', testDescrip.path,
Error('No exception was thrown; expected an error "message" property matching the regular expression "' + testDescrip.negative + '".')); testDescrip.description,
} else if (!(new RegExp(testDescrip.negative, "i").test(this.iframeError))) { //wrong type of exception thrown testDescrip.code,
testRun(testDescrip.id, testDescrip.path, testDescrip.description, testDescrip.code, 'fail',
'fail', Error('No exception was thrown; expected an error "message"' +
Error('Expected an exception with a "message" property matching the regular expression "' + testDescrip.negative +'" to be thrown; actual was "' + this.iframeError + '".')); ' property matching the regular expression "' +
testDescrip.negative + '".'));
} else if (!(new RegExp(testDescrip.negative,
"i").test(this.iframeError))) {
//wrong type of exception thrown
testRun(testDescrip.id,
testDescrip.path,
testDescrip.description,
testDescrip.code,
'fail',
Error('Expected an exception with a "message"' +
' property matching the regular expression "' +
testDescrip.negative +
'" to be thrown; actual was "' +
this.iframeError + '".'));
} else { } else {
testRun(testDescrip.id, testDescrip.path, testDescrip.description, testDescrip.code, testRun(testDescrip.id,
'pass', undefined); testDescrip.path,
testDescrip.description,
testDescrip.code,
'pass',
undefined);
} }
} }
//Exception was not expected to be thrown //Exception was not expected to be thrown
else if (this.iframeError !== undefined) { else if (this.iframeError !== undefined) {
testRun(testDescrip.id, testDescrip.path, testDescrip.description, testDescrip.code, testRun(testDescrip.id,
'fail', testDescrip.path,
Error('Unexpected exception, "' + this.iframeError + '" was thrown.')); testDescrip.description,
} testDescrip.code,
'fail',
Error('Unexpected exception, "' +
this.iframeError + '" was thrown.'));
}
else { else {
testRun(testDescrip.id, testDescrip.path, testDescrip.description, testDescrip.code, testRun(testDescrip.id,
'pass', undefined); testDescrip.path,
testDescrip.description,
testDescrip.code,
'pass',
undefined);
} }
testFinished(); testFinished();

View File

@ -42,17 +42,19 @@ from packagerConfig import *
#--Globals--------------------------------------------------------------------- #--Globals---------------------------------------------------------------------
__parser = argparse.ArgumentParser(description='Tool used to generate the test262 website') __parser = argparse.ArgumentParser(description= \
'Tool used to generate the test262 website')
__parser.add_argument('version', action='store', __parser.add_argument('version', action='store',
help='Version of the test suite.') help='Version of the test suite.')
__parser.add_argument('--type', action='store', default='test262', __parser.add_argument('--type', action='store', default='test262',
help='Type of test case runner to generate.') help='Type of test case runner to generate.')
__parser.add_argument('--console', action='store_true', default=False, __parser.add_argument('--console', action='store_true', default=False,
help='Type of test case runner to generate.') help='Type of test case runner to generate.')
ARGS = __parser.parse_args() ARGS = __parser.parse_args()
if not os.path.exists(EXCLUDED_FILENAME): if not os.path.exists(EXCLUDED_FILENAME):
print "Cannot generate (JSON) test262 tests without a file, %s, showing which tests have been disabled!" % EXCLUDED_FILENAME print "Cannot generate (JSON) test262 tests without a file," + \
" %s, showing which tests have been disabled!" % EXCLUDED_FILENAME
sys.exit(1) sys.exit(1)
EXCLUDE_LIST = xml.dom.minidom.parse(EXCLUDED_FILENAME) EXCLUDE_LIST = xml.dom.minidom.parse(EXCLUDED_FILENAME)
EXCLUDE_LIST = EXCLUDE_LIST.getElementsByTagName("test") EXCLUDE_LIST = EXCLUDE_LIST.getElementsByTagName("test")
@ -105,7 +107,8 @@ def createDepDirs(dirName):
os.mkdir(dirName) os.mkdir(dirName)
def test262PathToConsoleFile(path): def test262PathToConsoleFile(path):
stuff = os.path.join(TEST262_CONSOLE_CASES_DIR, path.replace("/", os.path.sep)) stuff = os.path.join(TEST262_CONSOLE_CASES_DIR,
path.replace("/", os.path.sep))
createDepDirs(os.path.dirname(stuff)) createDepDirs(os.path.dirname(stuff))
return stuff return stuff
@ -133,7 +136,8 @@ def dirWalker(dirName):
''' '''
global TEST_SUITE_SECTIONS global TEST_SUITE_SECTIONS
#First check to see if it has test files directly inside it #First check to see if it has test files directly inside it
temp = [os.path.join(dirName, x) for x in os.listdir(dirName) if not os.path.isdir(os.path.join(dirName, x))] temp = [os.path.join(dirName, x) for x in os.listdir(dirName) \
if not os.path.isdir(os.path.join(dirName, x))]
if len(temp)!=0: if len(temp)!=0:
TEST_SUITE_SECTIONS.append(dirName) TEST_SUITE_SECTIONS.append(dirName)
return return
@ -171,7 +175,8 @@ def isTestStarted(line):
elif "/*" in line: #Beginning of a newline comment elif "/*" in line: #Beginning of a newline comment
IS_MULTILINE_COMMENT = True IS_MULTILINE_COMMENT = True
return False return False
elif IS_MULTILINE_COMMENT: #//we're already in a multi-line comment that hasn't ended elif IS_MULTILINE_COMMENT: #//we're already in a multi-line
#comment that hasn't ended
return False return False
elif re.match("^\s*//", line)!=None: #//blah elif re.match("^\s*//", line)!=None: #//blah
return False return False
@ -221,7 +226,8 @@ for chapter in TEST_SUITE_SECTIONS:
testCount = 0 testCount = 0
for test in sourceFiles: for test in sourceFiles:
#TODO - use something other than the hard-coded 'TestCases' below #TODO - use something other than the hard-coded 'TestCases' below
testPath = "TestCases" + test.split(TEST262_CASES_DIR, 1)[1].replace("\\", "/") testPath = "TestCases" + \
test.split(TEST262_CASES_DIR, 1)[1].replace("\\", "/")
testName=test.rsplit(".", 1)[0] testName=test.rsplit(".", 1)[0]
testName=testName.rsplit(os.path.sep, 1)[1] testName=testName.rsplit(os.path.sep, 1)[1]
if EXCLUDE_LIST.count(testName)==0: if EXCLUDE_LIST.count(testName)==0:
@ -233,7 +239,8 @@ for chapter in TEST_SUITE_SECTIONS:
scriptCode = tempFile.readlines() scriptCode = tempFile.readlines()
tempFile.close() tempFile.close()
scriptCodeContent="" scriptCodeContent=""
#Rip out license headers that add unnecessary bytes to the JSON'ized test cases #Rip out license headers that add unnecessary bytes to
#the JSON'ized test cases
inBeginning = True inBeginning = True
IS_MULTILINE_COMMENT = False IS_MULTILINE_COMMENT = False
@ -246,7 +253,8 @@ for chapter in TEST_SUITE_SECTIONS:
scriptCodeContent += line scriptCodeContent += line
if scriptCodeContent=="": if scriptCodeContent=="":
print "WARNING (" + test + "): unable to strip comments/license header/etc." print "WARNING (" + test + \
"): unable to strip comments/license header/etc."
scriptCodeContent = "".join(scriptCode) scriptCodeContent = "".join(scriptCode)
scriptCodeContentB64 = base64.b64encode(scriptCodeContent) scriptCodeContentB64 = base64.b64encode(scriptCodeContent)
@ -265,9 +273,12 @@ for chapter in TEST_SUITE_SECTIONS:
tests.append(testDict) tests.append(testDict)
if ARGS.console: if ARGS.console:
with open(test262PathToConsoleFile(testDict["path"]), "w") as fConsole: with open(test262PathToConsoleFile(testDict["path"]),
"w") as fConsole:
fConsole.write(scriptCodeContent) fConsole.write(scriptCodeContent)
with open(test262PathToConsoleFile(testDict["path"][:-3] + "_metadata.js"), "w") as fConsoleMeta: with open(test262PathToConsoleFile(testDict["path"][:-3] + \
"_metadata.js"),
"w") as fConsoleMeta:
metaDict = testDict.copy() metaDict = testDict.copy()
del metaDict["code"] del metaDict["code"]
fConsoleMeta.write("testDescrip = " + str(metaDict)) fConsoleMeta.write("testDescrip = " + str(metaDict))
@ -283,7 +294,8 @@ for chapter in TEST_SUITE_SECTIONS:
#create a node for the tests and add it to our testsLists #create a node for the tests and add it to our testsLists
testsList["testsCollection"] = sect testsList["testsCollection"] = sect
with open(os.path.join(TEST262_WEB_CASES_DIR, chapterName + ".json"), "w") as f: with open(os.path.join(TEST262_WEB_CASES_DIR, chapterName + ".json"),
"w") as f:
json.dump(testsList, f, separators=(',',':'), sort_keys=True) json.dump(testsList, f, separators=(',',':'), sort_keys=True)
@ -291,11 +303,17 @@ for chapter in TEST_SUITE_SECTIONS:
CHAPTER_TEST_CASES_JSON = {} CHAPTER_TEST_CASES_JSON = {}
CHAPTER_TEST_CASES_JSON["numTests"] = int(sect["numTests"]) CHAPTER_TEST_CASES_JSON["numTests"] = int(sect["numTests"])
CHAPTER_TEST_CASES_JSON["version"] = ARGS.version CHAPTER_TEST_CASES_JSON["version"] = ARGS.version
CHAPTER_TEST_CASES_JSON["date"] = str(datetime.datetime.now().date()) CHAPTER_TEST_CASES_JSON["date"] = \
CHAPTER_TEST_CASES_JSON["testSuite"] = [WEBSITE_CASES_PATH + chapterName + ".json"] str(datetime.datetime.now().date())
with open(os.path.join(TEST262_WEB_CASES_DIR, "testcases_%s.json" % chapterName), "w") as f: CHAPTER_TEST_CASES_JSON["testSuite"] = \
json.dump(CHAPTER_TEST_CASES_JSON, f, separators=(',',':'), sort_keys=True) [WEBSITE_CASES_PATH + chapterName + ".json"]
generateHarness(ARGS.type, "testcases_%s.json" % chapterName, chapterName.replace("chapter", "Chapter ")) with open(os.path.join(TEST262_WEB_CASES_DIR,
"testcases_%s.json" % chapterName),
"w") as f:
json.dump(CHAPTER_TEST_CASES_JSON, f, separators=(',',':'),
sort_keys=True)
generateHarness(ARGS.type, "testcases_%s.json" % chapterName,
chapterName.replace("chapter", "Chapter "))
#add the name of the chapter test to our complete list #add the name of the chapter test to our complete list
SECTIONS_LIST.append(WEBSITE_CASES_PATH + chapterName + ".json") SECTIONS_LIST.append(WEBSITE_CASES_PATH + chapterName + ".json")
@ -317,10 +335,12 @@ generateHarness(ARGS.type, "default.json", "Chapters 1-16")
print "" print ""
print "Deploying test harness files to 'TEST262_WEB_HARNESS_DIR'..." print "Deploying test harness files to 'TEST262_WEB_HARNESS_DIR'..."
if TEST262_HARNESS_DIR!=TEST262_WEB_HARNESS_DIR: if TEST262_HARNESS_DIR!=TEST262_WEB_HARNESS_DIR:
for filename in [x for x in os.listdir(TEST262_HARNESS_DIR) if x.endswith(".js")]: for filename in [x for x in os.listdir(TEST262_HARNESS_DIR) \
if x.endswith(".js")]:
toFilenameList = [ os.path.join(TEST262_WEB_HARNESS_DIR, filename)] toFilenameList = [ os.path.join(TEST262_WEB_HARNESS_DIR, filename)]
if ARGS.console: if ARGS.console:
toFilenameList.append(os.path.join(TEST262_CONSOLE_HARNESS_DIR, filename)) toFilenameList.append(os.path.join(TEST262_CONSOLE_HARNESS_DIR,
filename))
for toFilename in toFilenameList: for toFilename in toFilenameList:
if not os.path.exists(os.path.dirname(toFilename)): if not os.path.exists(os.path.dirname(toFilename)):

View File

@ -31,30 +31,38 @@ WEBSITE_SHORT_NAME = "website"
CONSOLE_SHORT_NAME = "console" CONSOLE_SHORT_NAME = "console"
#Path to the root of the Hg repository (relative to this file's location) #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.join(os.path.dirname(os.path.realpath(__file__)),
"..", "..")
TEST262_ROOT = os.path.abspath(TEST262_ROOT) TEST262_ROOT = os.path.abspath(TEST262_ROOT)
#Directory full of test cases we want to port to the website's test harness runner #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") TEST262_CASES_DIR = os.path.join(TEST262_ROOT, "test", "suite")
#Directory containing test harness files to be ported over to the website. Note that #Directory containing test harness files to be ported over to the
#only *.js files will be migrated from this dir. #website. Note that only *.js files will be migrated from this dir.
TEST262_HARNESS_DIR = os.path.join(TEST262_ROOT, "test", "harness") TEST262_HARNESS_DIR = os.path.join(TEST262_ROOT, "test", "harness")
#Directory full of website test cases (ported over from TEST262_CASES_DIR) #Directory full of website test cases (ported over from TEST262_CASES_DIR)
TEST262_WEB_CASES_DIR = os.path.join(TEST262_ROOT, WEBSITE_SHORT_NAME, "json") TEST262_WEB_CASES_DIR = os.path.join(TEST262_ROOT, WEBSITE_SHORT_NAME, "json")
TEST262_CONSOLE_CASES_DIR = os.path.join(TEST262_ROOT, CONSOLE_SHORT_NAME) TEST262_CONSOLE_CASES_DIR = os.path.join(TEST262_ROOT, CONSOLE_SHORT_NAME)
#Directory containing the website's test harness (ported over from TEST262_HARNESS_DIR) #Directory containing the website's test harness (ported over from
TEST262_WEB_HARNESS_DIR = os.path.join(TEST262_ROOT, WEBSITE_SHORT_NAME, "harness") #TEST262_HARNESS_DIR)
TEST262_CONSOLE_HARNESS_DIR = os.path.join(TEST262_ROOT, CONSOLE_SHORT_NAME, "harness") TEST262_WEB_HARNESS_DIR = os.path.join(TEST262_ROOT, WEBSITE_SHORT_NAME,
"harness")
TEST262_CONSOLE_HARNESS_DIR = os.path.join(TEST262_ROOT, CONSOLE_SHORT_NAME,
"harness")
#Path to the ported test case files on the actual website as opposed to the Hg layout #Path to the ported test case files on the actual website as opposed
#to the Hg layout
WEBSITE_CASES_PATH = "json/" WEBSITE_CASES_PATH = "json/"
#The name of a file which contains a list of tests which should be disabled in test262. #The name of a file which contains a list of tests which should be
#These tests are either invalid as-per ES5 or have issues with the test262 web harness. #disabled in test262. These tests are either invalid as-per ES5 or
EXCLUDED_FILENAME = os.path.join(TEST262_ROOT, "test", "config", "excludelist.xml") #have issues with the test262 web harness.
EXCLUDED_FILENAME = os.path.join(TEST262_ROOT, "test", "config",
"excludelist.xml")
WEBSITE_EXCLUDE_RE_LIST = ["bestPractice"] WEBSITE_EXCLUDE_RE_LIST = ["bestPractice"]
WEBSITE_EXCLUDE_RE_LIST = [ re.compile(x) for x in WEBSITE_EXCLUDE_RE_LIST] WEBSITE_EXCLUDE_RE_LIST = [ re.compile(x) for x in WEBSITE_EXCLUDE_RE_LIST]
@ -70,9 +78,11 @@ def generateHarness(harnessType, jsonName, title):
if TEMPLATE_LINES==None or harnessType!=__lastHarnessType: if TEMPLATE_LINES==None or harnessType!=__lastHarnessType:
__lastHarnessType = harnessType __lastHarnessType = harnessType
TEMPLATE_LINES = [] TEMPLATE_LINES = []
with open(os.path.join(os.getcwd(), "templates","runner." + harnessType + ".html"), "r") as f: with open(os.path.join(os.getcwd(), "templates",
"runner." + harnessType + ".html"), "r") as f:
TEMPLATE_LINES = f.readlines() TEMPLATE_LINES = f.readlines()
fileName = os.path.join(TEST262_ROOT, WEBSITE_SHORT_NAME, jsonName.replace(".json", ".html")) fileName = os.path.join(TEST262_ROOT, WEBSITE_SHORT_NAME,
jsonName.replace(".json", ".html"))
fileNameExists = False fileNameExists = False
if os.path.exists(fileName): if os.path.exists(fileName):
SC_HELPER.edit(fileName) SC_HELPER.edit(fileName)
@ -80,9 +90,11 @@ def generateHarness(harnessType, jsonName, title):
with open(fileName, "w") as f: with open(fileName, "w") as f:
for line in TEMPLATE_LINES: for line in TEMPLATE_LINES:
if "var TEST_LIST_PATH =" in line: if "var TEST_LIST_PATH =" in line:
f.write(" var TEST_LIST_PATH = \"json/" + jsonName + "\";" + os.linesep) f.write(" var TEST_LIST_PATH = \"json/" + jsonName + \
"\";" + os.linesep)
#elif "ECMAScript 5" in line: #elif "ECMAScript 5" in line:
# f.write(line.replace("ECMAScript 5", "ECMAScript 5: %s" % title)) # f.write(line.replace("ECMAScript 5",
# "ECMAScript 5: %s" % title))
else: else:
f.write(line) f.write(line)
if not fileNameExists: if not fileNameExists:
@ -109,4 +121,4 @@ class SCAbstraction(object):
''' '''
subprocess.call(["hg", "add", filename]) subprocess.call(["hg", "add", filename])
SC_HELPER = SCAbstraction() SC_HELPER = SCAbstraction()