2014-12-01 21:46:34 +01:00
|
|
|
# Copyright (c) 2012 Ecma International. All rights reserved.
|
2015-07-17 17:42:45 +02:00
|
|
|
# This code is governed by the BSD license found in the LICENSE file.
|
2011-09-24 19:35:50 +02:00
|
|
|
|
|
|
|
#--Imports---------------------------------------------------------------------
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import stat
|
2011-09-26 00:37:56 +02:00
|
|
|
import re
|
2011-09-24 19:35:50 +02:00
|
|
|
|
|
|
|
#--Globals---------------------------------------------------------------------
|
|
|
|
MAX_CASES_PER_JSON = 1000
|
|
|
|
|
2011-09-25 20:41:04 +02:00
|
|
|
WEBSITE_SHORT_NAME = "website"
|
2011-09-27 01:12:46 +02:00
|
|
|
CONSOLE_SHORT_NAME = "console"
|
2011-09-24 20:47:48 +02:00
|
|
|
|
2011-11-04 20:04:46 +01:00
|
|
|
DEFAULT_TESTCASE_TEMPLATE="test262"
|
|
|
|
|
|
|
|
ONE_JSON_PER_CHAPTER = False
|
2012-01-20 01:03:21 +01:00
|
|
|
TESTCASELIST_PER_JSON = True
|
2011-11-04 20:04:46 +01:00
|
|
|
|
2011-09-24 19:35:50 +02:00
|
|
|
#Path to the root of the Hg repository (relative to this file's location)
|
2014-12-01 21:46:34 +01:00
|
|
|
TEST262_ROOT = os.path.join(os.path.dirname(os.path.realpath(__file__)),
|
2011-09-30 09:59:50 +02:00
|
|
|
"..", "..")
|
2011-09-24 19:35:50 +02:00
|
|
|
TEST262_ROOT = os.path.abspath(TEST262_ROOT)
|
|
|
|
|
2011-09-30 09:59:50 +02:00
|
|
|
#Directory full of test cases we want to port to the website's test
|
|
|
|
#harness runner
|
2014-12-08 00:42:12 +01:00
|
|
|
TEST262_CASES_DIR = os.path.join(TEST262_ROOT, "test")
|
2011-09-24 19:35:50 +02:00
|
|
|
|
2011-09-30 09:59:50 +02:00
|
|
|
#Directory containing test harness files to be ported over to the
|
|
|
|
#website. Note that only *.js files will be migrated from this dir.
|
2014-12-08 00:42:12 +01:00
|
|
|
TEST262_HARNESS_DIR = os.path.join(TEST262_ROOT, "harness")
|
2011-09-24 19:35:50 +02:00
|
|
|
|
|
|
|
#Directory full of website test cases (ported over from TEST262_CASES_DIR)
|
2011-09-24 20:47:48 +02:00
|
|
|
TEST262_WEB_CASES_DIR = os.path.join(TEST262_ROOT, WEBSITE_SHORT_NAME, "json")
|
2011-09-27 01:12:46 +02:00
|
|
|
TEST262_CONSOLE_CASES_DIR = os.path.join(TEST262_ROOT, CONSOLE_SHORT_NAME)
|
2011-09-24 19:35:50 +02:00
|
|
|
|
2011-09-30 09:59:50 +02:00
|
|
|
#Directory containing the website's test harness (ported over from
|
|
|
|
#TEST262_HARNESS_DIR)
|
2014-12-01 21:46:34 +01:00
|
|
|
TEST262_WEB_HARNESS_DIR = os.path.join(TEST262_ROOT, WEBSITE_SHORT_NAME,
|
2011-09-30 09:59:50 +02:00
|
|
|
"harness")
|
2014-12-01 21:46:34 +01:00
|
|
|
TEST262_CONSOLE_HARNESS_DIR = os.path.join(TEST262_ROOT, CONSOLE_SHORT_NAME,
|
2011-09-30 09:59:50 +02:00
|
|
|
"harness")
|
2011-09-24 19:35:50 +02:00
|
|
|
|
2011-09-30 09:59:50 +02:00
|
|
|
#Path to the ported test case files on the actual website as opposed
|
|
|
|
#to the Hg layout
|
2011-09-24 20:47:48 +02:00
|
|
|
WEBSITE_CASES_PATH = "json/"
|
2011-09-24 19:35:50 +02:00
|
|
|
|
2011-09-30 09:59:50 +02:00
|
|
|
#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.
|
2014-12-09 23:52:12 +01:00
|
|
|
EXCLUDED_FILENAME = os.path.join(TEST262_ROOT, "excludelist.xml")
|
2011-09-24 19:35:50 +02:00
|
|
|
|
2012-01-25 23:04:40 +01:00
|
|
|
WEBSITE_EXCLUDE_RE_LIST = ["bestPractice", "intl402"]
|
2011-09-26 00:37:56 +02:00
|
|
|
WEBSITE_EXCLUDE_RE_LIST = [ re.compile(x) for x in WEBSITE_EXCLUDE_RE_LIST]
|
2011-09-24 20:47:48 +02:00
|
|
|
|
2011-09-24 19:35:50 +02:00
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
TEMPLATE_LINES = None
|
|
|
|
__lastHarnessType = None
|
|
|
|
|
|
|
|
def generateHarness(harnessType, jsonName, title):
|
|
|
|
global TEMPLATE_LINES
|
|
|
|
global __lastHarnessType
|
2014-12-01 21:46:34 +01:00
|
|
|
|
2012-01-25 23:29:00 +01:00
|
|
|
#TODO: temp hack to make experimental internationalization tests work
|
|
|
|
if jsonName=="testcases_intl402.json":
|
|
|
|
harnessType = "intl402"
|
2012-02-29 18:02:11 +01:00
|
|
|
elif jsonName=="testcases_bestPractice.json":
|
|
|
|
harnessType = "bestPractice"
|
2014-12-01 21:46:34 +01:00
|
|
|
|
2011-09-24 19:35:50 +02:00
|
|
|
if TEMPLATE_LINES==None or harnessType!=__lastHarnessType:
|
|
|
|
__lastHarnessType = harnessType
|
|
|
|
TEMPLATE_LINES = []
|
2011-09-30 09:59:50 +02:00
|
|
|
with open(os.path.join(os.getcwd(), "templates",
|
|
|
|
"runner." + harnessType + ".html"), "r") as f:
|
2011-09-24 19:35:50 +02:00
|
|
|
TEMPLATE_LINES = f.readlines()
|
2014-12-01 21:46:34 +01:00
|
|
|
fileName = os.path.join(TEST262_ROOT, WEBSITE_SHORT_NAME,
|
2011-09-30 09:59:50 +02:00
|
|
|
jsonName.replace(".json", ".html"))
|
2011-09-24 19:35:50 +02:00
|
|
|
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:
|
2011-09-30 09:59:50 +02:00
|
|
|
f.write(" var TEST_LIST_PATH = \"json/" + jsonName + \
|
|
|
|
"\";" + os.linesep)
|
2011-09-24 19:35:50 +02:00
|
|
|
#elif "ECMAScript 5" in line:
|
2014-12-01 21:46:34 +01:00
|
|
|
# f.write(line.replace("ECMAScript 5",
|
2011-09-30 09:59:50 +02:00
|
|
|
# "ECMAScript 5: %s" % title))
|
2011-09-24 19:35:50 +02:00
|
|
|
else:
|
|
|
|
f.write(line)
|
|
|
|
if not fileNameExists:
|
|
|
|
SC_HELPER.add(fileName)
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
class SCAbstraction(object):
|
|
|
|
'''
|
2014-12-01 21:46:34 +01:00
|
|
|
A class which abstracts working with source control systems in relation to
|
2011-09-24 19:35:50 +02:00
|
|
|
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)
|
2014-12-01 21:46:34 +01:00
|
|
|
|
2011-09-24 19:35:50 +02:00
|
|
|
def add(self, filename):
|
|
|
|
'''
|
|
|
|
Source control add of a file.
|
|
|
|
'''
|
2014-07-18 09:15:07 +02:00
|
|
|
subprocess.call(["git", "add", filename])
|
2014-12-01 21:46:34 +01:00
|
|
|
|
2011-09-30 09:59:50 +02:00
|
|
|
SC_HELPER = SCAbstraction()
|