Commit d7e6146b authored by Shu-yu Guo's avatar Shu-yu Guo Committed by V8 LUCI CQ

[infra] Fork test262-harness

The external project is effectively abandoned. Fork and move it in-tree
for easier maintenance and Python 3 migration.

Bug: chromium:1296209
Change-Id: I4ff97749acb2895bd8433c08b2a4ff109c90cda2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3475086Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79240}
parent 3d5d99ff
...@@ -55,7 +55,6 @@ ...@@ -55,7 +55,6 @@
!/test/mjsunit/tools/*.log !/test/mjsunit/tools/*.log
/test/mozilla/data /test/mozilla/data
/test/test262/data /test/test262/data
/test/test262/harness
/test/wasm-js/data /test/wasm-js/data
/test/wasm-js/tests /test/wasm-js/tests
/test/wasm-js/tests.tar.gz /test/wasm-js/tests.tar.gz
...@@ -70,6 +69,7 @@ ...@@ -70,6 +69,7 @@
/third_party/colorama/src /third_party/colorama/src
!/third_party/googletest !/third_party/googletest
/third_party/googletest/src /third_party/googletest/src
!/third_party/test262-harness
!/third_party/v8 !/third_party/v8
!/third_party/wasm-api !/third_party/wasm-api
/tools/clang /tools/clang
......
...@@ -140,8 +140,6 @@ deps = { ...@@ -140,8 +140,6 @@ deps = {
Var('chromium_url') + '/v8/deps/third_party/mozilla-tests.git' + '@' + 'f6c578a10ea707b1a8ab0b88943fe5115ce2b9be', Var('chromium_url') + '/v8/deps/third_party/mozilla-tests.git' + '@' + 'f6c578a10ea707b1a8ab0b88943fe5115ce2b9be',
'test/test262/data': 'test/test262/data':
Var('chromium_url') + '/external/github.com/tc39/test262.git' + '@' + 'e87b0048c402479df1d9cb391fb86620cf3200fd', Var('chromium_url') + '/external/github.com/tc39/test262.git' + '@' + 'e87b0048c402479df1d9cb391fb86620cf3200fd',
'test/test262/harness':
Var('chromium_url') + '/external/github.com/test262-utils/test262-harness-py.git' + '@' + '278bcfaed0dcaa13936831fb1769d15e7c1e3b2b',
'third_party/aemu-linux-x64': { 'third_party/aemu-linux-x64': {
'packages': [ 'packages': [
{ {
......
...@@ -13,7 +13,7 @@ group("v8_test262") { ...@@ -13,7 +13,7 @@ group("v8_test262") {
data = [ data = [
"data/", "data/",
"detachArrayBuffer.js", "detachArrayBuffer.js",
"harness/", "../../third_party/test262-harness/",
"harness-adapt.js", "harness-adapt.js",
"harness-adapt-donotevaluate.js", "harness-adapt-donotevaluate.js",
"harness-agent.js", "harness-agent.js",
......
...@@ -69,16 +69,18 @@ SKIPPED_FEATURES = set([]) ...@@ -69,16 +69,18 @@ SKIPPED_FEATURES = set([])
DATA = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data") DATA = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data")
BASE_DIR = os.path.dirname(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
TEST_262_HARNESS_FILES = ["sta.js", "assert.js"] TEST_262_HARNESS_FILES = ["sta.js", "assert.js"]
TEST_262_NATIVE_FILES = ["detachArrayBuffer.js"] TEST_262_NATIVE_FILES = ["detachArrayBuffer.js"]
TEST_262_SUITE_PATH = ["data", "test"] TEST_262_SUITE_PATH = ["data", "test"]
TEST_262_HARNESS_PATH = ["data", "harness"] TEST_262_HARNESS_PATH = ["data", "harness"]
TEST_262_TOOLS_PATH = ["harness", "src"] TEST_262_TOOLS_ABS_PATH = [BASE_DIR, "third_party", "test262-harness", "src"]
TEST_262_LOCAL_TESTS_PATH = ["local-tests", "test"] TEST_262_LOCAL_TESTS_PATH = ["local-tests", "test"]
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), sys.path.append(os.path.join(*TEST_262_TOOLS_ABS_PATH))
*TEST_262_TOOLS_PATH))
class VariantsGenerator(testsuite.VariantsGenerator): class VariantsGenerator(testsuite.VariantsGenerator):
...@@ -139,15 +141,14 @@ class TestSuite(testsuite.TestSuite): ...@@ -139,15 +141,14 @@ class TestSuite(testsuite.TestSuite):
self.parse_test_record = self._load_parse_test_record() self.parse_test_record = self._load_parse_test_record()
def _load_parse_test_record(self): def _load_parse_test_record(self):
root = os.path.join(self.root, *TEST_262_TOOLS_PATH) root = os.path.join(*TEST_262_TOOLS_ABS_PATH)
f = None f = None
try: try:
(f, pathname, description) = imp.find_module("parseTestRecord", [root]) (f, pathname, description) = imp.find_module("parseTestRecord", [root])
module = imp.load_module("parseTestRecord", f, pathname, description) module = imp.load_module("parseTestRecord", f, pathname, description)
return module.parseTestRecord return module.parseTestRecord
except: except:
print ('Cannot load parseTestRecord; ' print('Cannot load parseTestRecord')
'you may need to gclient sync for test262')
raise raise
finally: finally:
if f: if f:
......
The << Software identified by reference to the Ecma Standard* (“Software)”>> is protected by copyright and is being
made available under the “BSD License”, included below. This Software may be subject to third party rights (rights
from parties other than Ecma International), including patent rights, and no licenses under such third party rights
are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA
CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT http://www.ecma-international.org/memento/codeofconduct.htm FOR
INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS*.
Copyright © <<2012>> <<Ecma International>>
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
disclaimer.
2. 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.
3. Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "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 ECMA INTERNATIONAL 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.
* Ecma International Standards hereafter means Ecma International Standards as well as Ecma Technical Reports
\ No newline at end of file
file:../../INFRA_OWNERS
syg@chromium.org
# Test262 Python Harness
### Usage
Loaded as a module, this project defines a single function, `parseTestRecord`.
This function creates an object representation of the metadata encoded in the
"frontmatter" of the provided Test262 test source code.
`test262.py` is an executable designed to execute Test262 tests. It is exposed
for public use. For usage instructions, invoke this executable with the
`--help` flag, as in:
$ test262.py --help
### Tests
Run the following command from the root of this projcet:
$ python -m unittest discover test
Name: test262-harness
Short Name: test262-harness
URL: https://github.com/test262-utils/test262-harness-py
Version: 0
Revision: 278bcfaed0dcaa13936831fb1769d15e7c1e3b2b
Date: 2022-02-18
License: BSD
License File: LICENSE
Security Critical: no
Description:
Provides the parseTestRecord function in Python for the test262 runner.
Local modifications:
src/_monkeyYaml.py was made Python 3 compatible
from src.parseTestRecord import parseTestRecord
<?xml version="1.0" encoding="utf-8" ?>
<excludeList>
</excludeList>
# Copyright (c) 2012 Ecma International. All rights reserved.
# This code is governed by the BSD license found in the LICENSE file.
#--Imports---------------------------------------------------------------------
import parseTestRecord
#--Stubs-----------------------------------------------------------------------
#--Globals---------------------------------------------------------------------
#--Helpers--------------------------------------------------------------------#
def convertDocString(docString):
envelope = parseTestRecord.parseTestRecord(docString, '')
envelope.pop('header', None)
envelope.pop('test', None)
return envelope
#!/usr/bin/env python
# Copyright 2014 by Sam Mikes. All rights reserved.
# This code is governed by the BSD license found in the LICENSE file.
# This code provides a fallback parser that can handle the subset of
# YAML used in test262 frontmatter
import re
mYamlKV = re.compile(r"(.*?):(.*)")
mYamlIntDigits = re.compile(r"^[-0-9]*$")
mYamlFloatDigits = re.compile(r"^[-.0-9eE]*$")
mYamlListPattern = re.compile(r"^\[(.*)\]$")
mYamlMultilineList = re.compile(r"^ *- (.*)$")
mYamlStringValue = re.compile(r"^('|\").*\1$")
def load(str):
return myReadDict(str.splitlines())[1]
def myReadDict(lines, indent=""):
dict = None
key = None
emptyLines = 0
while lines:
if not lines[0].startswith(indent):
break
line = lines.pop(0)
if myIsAllSpaces(line):
emptyLines += 1
continue
result = mYamlKV.match(line)
if result:
if not dict:
dict = {}
key = result.group(1).strip()
value = result.group(2).strip()
(lines, value) = myReadValue(lines, value, indent)
dict[key] = value
else:
if dict and key and key in dict:
c = " " if emptyLines == 0 else "\n" * emptyLines
dict[key] += c + line.strip()
else:
raise Exception("monkeyYaml is confused at " + line)
emptyLines = 0
return lines, dict
def myReadValue(lines, value, indent):
if value == ">" or value == "|":
(lines, value) = myMultiline(lines, value == "|")
value = value + "\n"
return (lines, value)
if lines and not value:
if myMaybeList(lines[0]):
return myMultilineList(lines, value)
indentMatch = re.match("(" + indent + r"\s+)", lines[0])
if indentMatch:
if ":" in lines[0]:
return myReadDict(lines, indentMatch.group(1))
return myMultiline(lines, False)
return lines, myReadOneLine(value)
def myMaybeList(value):
return mYamlMultilineList.match(value)
def myMultilineList(lines, value):
# assume no explcit indentor (otherwise have to parse value)
value = []
indent = 0
while lines:
line = lines.pop(0)
leading = myLeadingSpaces(line)
if myIsAllSpaces(line):
pass
elif leading < indent:
lines.insert(0, line)
break;
else:
indent = indent or leading
value += [myReadOneLine(myRemoveListHeader(indent, line))]
return (lines, value)
def myRemoveListHeader(indent, line):
line = line[indent:]
return mYamlMultilineList.match(line).group(1)
def myReadOneLine(value):
if mYamlListPattern.match(value):
return myFlowList(value)
elif mYamlIntDigits.match(value):
try:
value = int(value)
except ValueError:
pass
elif mYamlFloatDigits.match(value):
try:
value = float(value)
except ValueError:
pass
elif mYamlStringValue.match(value):
value = value[1:-1]
return value
def myFlowList(value):
result = mYamlListPattern.match(value)
values = result.group(1).split(",")
return [myReadOneLine(v.strip()) for v in values]
def myMultiline(lines, preserveNewlines=False):
# assume no explcit indentor (otherwise have to parse value)
value = ""
indent = myLeadingSpaces(lines[0])
wasEmpty = None
while lines:
line = lines.pop(0)
isEmpty = myIsAllSpaces(line)
if isEmpty:
if preserveNewlines:
value += "\n"
elif myLeadingSpaces(line) < indent:
lines.insert(0, line)
break;
else:
if preserveNewlines:
if wasEmpty != None:
value += "\n"
else:
if wasEmpty == False:
value += " "
elif wasEmpty == True:
value += "\n"
value += line[(indent):]
wasEmpty = isEmpty
return (lines, value)
def myIsAllSpaces(line):
return len(line.strip()) == 0
def myLeadingSpaces(line):
return len(line) - len(line.lstrip(' '))
This diff is collapsed.
# Copyright (c) 2012 Ecma International. All rights reserved.
# This code is governed by the BSD license found in the LICENSE file.
#--Imports---------------------------------------------------------------------
import os
import subprocess
import stat
import re
#--Globals---------------------------------------------------------------------
MAX_CASES_PER_JSON = 1000
WEBSITE_SHORT_NAME = "website"
CONSOLE_SHORT_NAME = "console"
DEFAULT_TESTCASE_TEMPLATE="test262"
ONE_JSON_PER_CHAPTER = False
TESTCASELIST_PER_JSON = True
#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")
#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, "harness")
#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_CONSOLE_CASES_DIR = os.path.join(TEST262_ROOT, CONSOLE_SHORT_NAME)
#Directory containing the website's test harness (ported over from
#TEST262_HARNESS_DIR)
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
WEBSITE_CASES_PATH = "json/"
#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, "excludelist.xml")
WEBSITE_EXCLUDE_RE_LIST = ["bestPractice", "intl402"]
WEBSITE_EXCLUDE_RE_LIST = [ re.compile(x) for x in WEBSITE_EXCLUDE_RE_LIST]
#------------------------------------------------------------------------------
TEMPLATE_LINES = None
__lastHarnessType = None
def generateHarness(harnessType, jsonName, title):
global TEMPLATE_LINES
global __lastHarnessType
#TODO: temp hack to make experimental internationalization tests work
if jsonName=="testcases_intl402.json":
harnessType = "intl402"
elif jsonName=="testcases_bestPractice.json":
harnessType = "bestPractice"
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_SHORT_NAME,
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 = \"json/" + 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(["git", "add", filename])
SC_HELPER = SCAbstraction()
#!/usr/bin/env python
# Copyright 2011 by Google, Inc. All rights reserved.
# This code is governed by the BSD license found in the LICENSE file.
# TODO: resolve differences with common.py and unify into one file.
from __future__ import print_function
import os
import re
import imp
from _monkeyYaml import load as yamlLoad
#def onerror(message):
# print(message)
# Matches trailing whitespace and any following blank lines.
_BLANK_LINES = r"([ \t]*[\r\n]{1,2})*"
# Matches the YAML frontmatter block.
_YAML_PATTERN = re.compile(r"/\*---(.*)---\*/" + _BLANK_LINES, re.DOTALL)
# Matches all known variants for the license block.
# https://github.com/tc39/test262/blob/705d78299cf786c84fa4df473eff98374de7135a/tools/lint/lib/checks/license.py
_LICENSE_PATTERN = re.compile(
r'// Copyright( \([C]\))? (\w+) .+\. {1,2}All rights reserved\.[\r\n]{1,2}' +
r'(' +
r'// This code is governed by the( BSD)? license found in the LICENSE file\.' +
r'|' +
r'// See LICENSE for details.' +
r'|' +
r'// Use of this source code is governed by a BSD-style license that can be[\r\n]{1,2}' +
r'// found in the LICENSE file\.' +
r'|' +
r'// See LICENSE or https://github\.com/tc39/test262/blob/(master|HEAD)/LICENSE' +
r')' + _BLANK_LINES, re.IGNORECASE)
def yamlAttrParser(testRecord, attrs, name, onerror = print):
parsed = yamlLoad(attrs)
if parsed is None:
onerror("Failed to parse yaml in name %s" % name)
return
for key in parsed:
value = parsed[key]
if key == "info":
key = "commentary"
testRecord[key] = value
if 'flags' in testRecord:
for flag in testRecord['flags']:
testRecord[flag] = ""
def findLicense(src):
match = _LICENSE_PATTERN.search(src)
if not match:
return None
return match.group(0)
def findAttrs(src):
match = _YAML_PATTERN.search(src)
if not match:
return (None, None)
return (match.group(0), match.group(1).strip())
def parseTestRecord(src, name, onerror = print):
# Find the license block.
header = findLicense(src)
# Find the YAML frontmatter.
(frontmatter, attrs) = findAttrs(src)
# YAML frontmatter is required for all tests.
if frontmatter is None:
onerror("Missing frontmatter: %s" % name)
# The license shuold be placed before the frontmatter and there shouldn't be
# any extra content between the license and the frontmatter.
if header is not None and frontmatter is not None:
headerIdx = src.index(header)
frontmatterIdx = src.index(frontmatter)
if headerIdx > frontmatterIdx:
onerror("Unexpected license after frontmatter: %s" % name)
# Search for any extra test content, but ignore whitespace only or comment lines.
extra = src[headerIdx + len(header) : frontmatterIdx]
if extra and any(line.strip() and not line.lstrip().startswith("//") for line in extra.split("\n")):
onerror("Unexpected test content between license and frontmatter: %s" % name)
# Remove the license and YAML parts from the actual test content.
test = src
if frontmatter is not None:
test = test.replace(frontmatter, '')
if header is not None:
test = test.replace(header, '')
testRecord = {}
testRecord['header'] = header.strip() if header else ''
testRecord['test'] = test
if attrs:
yamlAttrParser(testRecord, attrs, name, onerror)
# Report if the license block is missing in non-generated tests.
if header is None and "generated" not in testRecord and "hashbang" not in name:
onerror("No license found in: %s" % name)
return testRecord
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
# Unit tests for python packaging tools
This directory holds tests for the python code, not tests of EMCAScript
## Running tests
````
$ cd tools/packaging/test
$ for x in test*.py; do python $x; done
````
// fake copyright comment
/*---
info: >
Sample test info
description: Sample test description
negative:
phase: early
type: SyntaxError
---*/
???
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* The production Block { } in strict code can't contain function
* declaration;
*
* @path bestPractice/Sbp_A1_T1.js
* @description Trying to declare function at the Block statement
* @onlyStrict
* @negative SyntaxError
* @bestPractice http://wiki.ecmascript.org/doku.php?id=conventions:no_non_standard_strict_decls
*/
"use strict";
{
function __func(){}
}
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: >
The production Block { } in strict code can't contain function
declaration;
description: Trying to declare function at the Block statement
negative: SyntaxError
bestPractice: "http://wiki.ecmascript.org/doku.php?id=conventions:no_non_standard_strict_decls"
flags: [onlyStrict]
---*/
"use strict";
{
function __func(){}
}
#!/usr/bin/env python
# Copyright 2014 by Sam Mikes. All rights reserved.
# This code is governed by the BSD license found in the LICENSE file.
import unittest
import os
# add parent dir to search path
import sys
sys.path.append("src")
from _common import *
def slurpFile(name):
with open('test/' + name) as f:
contents = f.read()
return contents
class TestOldParsing(unittest.TestCase):
def test_test(self):
pass
def test_overview(self):
name = 'fixtures/test262-old-headers.js'
contents = slurpFile(name)
record = convertDocString(contents)
self.assertEqual("""The production Block { } in strict code can't contain function
declaration;""", record['commentary'])
self.assertEqual("bestPractice/Sbp_A1_T1.js", record['path'])
self.assertEqual("Trying to declare function at the Block statement",
record['description'])
self.assertEqual("", record['onlyStrict'])
self.assertEqual("SyntaxError", record['negative'])
self.assertEqual("http://wiki.ecmascript.org/doku.php?id=conventions:no_non_standard_strict_decls",
record['bestPractice'])
class TestYAMLParsing(unittest.TestCase):
def test_overview(self):
name = 'fixtures/test262-yaml-headers.js'
contents = slurpFile(name)
record = convertDocString(contents)
self.assertEqual("The production Block { } in strict code can't contain function declaration;\n", record['commentary'])
self.assertEqual("Trying to declare function at the Block statement",
record['description'])
self.assertEqual(['onlyStrict'], record['flags'])
self.assertEqual("", record['onlyStrict'])
self.assertEqual("SyntaxError", record['negative'])
self.assertEqual("http://wiki.ecmascript.org/doku.php?id=conventions:no_non_standard_strict_decls",
record['bestPractice'])
if __name__ == '__main__':
unittest.main()
#!/usr/bin/env python
# Copyright 2014 by Sam Mikes. All rights reserved.
# This code is governed by the BSD license found in the LICENSE file.
import unittest
import os
import yaml
import imp
# add parent dir to search path
import sys
sys.path.append("src")
import _monkeyYaml as monkeyYaml
class TestMonkeyYAMLParsing(unittest.TestCase):
def test_empty(self):
self.assertEqual(monkeyYaml.load(""), yaml.load(""))
def test_newline(self):
self.assertEqual(monkeyYaml.load("\n"), yaml.load("\n"))
def test_oneline(self):
y = "foo: bar"
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_twolines(self):
y = "foo: bar\nbaz_bletch : blith:er"
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_multiLine(self):
y = "foo: >\n bar\nbaz: 3"
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_es5id(self):
y = "es5id: 15.2.3.6-4-102"
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_Multiline_1(self):
lines = [" foo"]
value = ">"
y = "\n".join([value] + lines)
(lines, value) = monkeyYaml.myMultiline(lines, value)
self.assertEqual(lines, [])
self.assertEqual(value, yaml.load(y))
def test_Multiline_2(self):
lines = [" foo", " bar"]
y = "\n".join([">"] + lines)
(lines, value) = monkeyYaml.myMultiline(lines)
self.assertEqual(lines, [])
self.assertEqual(value, yaml.load(y))
def test_Multiline_3(self):
lines = [" foo", " bar"]
y = "\n".join([">"] + lines)
(lines, value) = monkeyYaml.myMultiline(lines)
self.assertEqual(lines, [])
self.assertEqual(value, yaml.load(y))
def test_Multiline_4(self):
lines = [" foo", " bar", " other: 42"]
(lines, value) = monkeyYaml.myMultiline(lines)
self.assertEqual(lines, [" other: 42"])
self.assertEqual(value, "foo bar")
def test_myLeading(self):
self.assertEqual(2, monkeyYaml.myLeadingSpaces(" foo"))
self.assertEqual(2, monkeyYaml.myLeadingSpaces(" "))
self.assertEqual(0, monkeyYaml.myLeadingSpaces("\t "))
def test_includes_flow(self):
y = "includes: [a.js,b.js, c_with_wings.js]\n"
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_myFlowList_1(self):
y = "[a.js,b.js, c_with_wings.js, 3, 4.12]"
self.assertEqual(monkeyYaml.myFlowList(y), ['a.js', 'b.js', 'c_with_wings.js', 3, 4.12])
def test_multiline_list_1(self):
y = "foo:\n - bar\n - baz"
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_multiline_list2(self):
self.assertEqual(monkeyYaml.myRemoveListHeader(2, " - foo"), "foo")
def test_multiline_list3(self):
(lines, value) = monkeyYaml.myMultilineList([" - foo", " - bar", "baz: bletch"], "")
self.assertEqual(lines, ["baz: bletch"])
self.assertEqual(value, ["foo", "bar"])
def test_multiline_list_carriage_return(self):
y = "foo:\r\n - bar\r\n - baz"
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_oneline_indented(self):
y = " foo: bar\n baz: baf\n"
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_indentation_215(self):
self.maxDiff = None
y = """
description: >
The method should exist on the Array prototype, and it should be writable
and configurable, but not enumerable.
includes: [propertyHelper.js]
es6id: 22.1.3.13
"""
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_indentation_215_2(self):
self.maxDiff = None
y = """
description: >
The method should exist
includes: [propertyHelper.js]
es6id: 22.1.3.13
"""
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_line_folding(self):
self.maxDiff = None
y = """
description: aaa
bbb
es6id: 19.1.2.1
"""
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_line_folding_2(self):
self.maxDiff = None
y = """
description: ccc
ddd
es6id: 19.1.2.1
"""
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_line_folding_3(self):
self.maxDiff = None
y = """
description: eee
fff
es6id: 19.1.2.1
"""
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_line_folding_4(self):
self.maxDiff = None
y = """
description: ggg
hhh
iii
jjj
es6id: 19.1.2.1
"""
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_no_folding(self):
y = """
description: |
This is text that, naively parsed, would appear
to: have
nested: data
"""
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_value_multiline(self):
y = """
description:
This is a multi-line value
whose trailing newline should be stripped
"""
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_nested_1(self):
y = """
es61d: 19.1.2.1
negative:
stage: early
type: ReferenceError
description: foo
"""
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
def test_nested_2(self):
y = """
es61d: 19.1.2.1
first:
second_a:
third: 1
second_b: 3
description: foo
"""
self.assertEqual(monkeyYaml.load(y), yaml.load(y))
if __name__ == '__main__':
unittest.main()
#!/usr/bin/env python
# Copyright 2014 by Sam Mikes. All rights reserved.
# This code is governed by the BSD license found in the LICENSE file.
import unittest
import os
import yaml
# add parent dir to search path
import sys
sys.path.append("src")
from parseTestRecord import *
def slurpFile(name):
with open('test/' + name) as f:
contents = f.read()
return contents
class TestOldParsing(unittest.TestCase):
def test_test(self):
self.assertTrue(True)
def test_overview(self):
name = 'fixtures/test262-old-headers.js'
contents = slurpFile(name)
record = parseTestRecord(contents, name)
self.assertEqual("""// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.""",
record['header'])
self.assertEqual("""The production Block { } in strict code can't contain function
declaration;""", record['commentary'])
self.assertEqual("bestPractice/Sbp_A1_T1.js", record['path'])
self.assertEqual("Trying to declare function at the Block statement",
record['description'])
self.assertEqual("", record['onlyStrict'])
self.assertEqual("SyntaxError", record['negative'])
self.assertEqual("http://wiki.ecmascript.org/doku.php?id=conventions:no_non_standard_strict_decls",
record['bestPractice'])
self.assertEqual(""""use strict";
{
function __func(){}
}
""", record['test'])
@unittest.expectedFailure
def test_nomatch(self):
with self.assertRaisesRegexp(Exception, "unrecognized"):
parseTestRecord("#!/usr/bin/env python", "random.py")
def test_duplicate(self):
with self.assertRaisesRegexp(Exception, "duplicate: foo"):
parseTestRecord("""
// Copyright
/**
* @foo bar
* @foo bar
*/
1;
"""
, "name")
def test_malformed(self):
with self.assertRaisesRegexp(Exception, 'Malformed "@" attribute: name'):
parseTestRecord("""
// Copyright
/**
* @ baz
* @foo bar
*/
1;
"""
, "name")
def test_stripStars(self):
self.assertEqual("", stripStars(""))
self.assertEqual("foo", stripStars("\n* foo"))
self.assertEqual("@foo bar", stripStars("\n* @foo bar"))
self.assertEqual("@foo bar", stripStars("\n *@foo bar"))
class TestYAMLParsing(unittest.TestCase):
def test_test(self):
self.assertTrue(True)
def test_split(self):
name = 'fixtures/test262-yaml-headers.js'
contents = slurpFile(name)
self.assertTrue('---' in contents)
match = matchParts(contents, name)
self.assertEqual("""---
info: >
The production Block { } in strict code can't contain function
declaration;
description: Trying to declare function at the Block statement
negative: SyntaxError
bestPractice: "http://wiki.ecmascript.org/doku.php?id=conventions:no_non_standard_strict_decls"
flags: [onlyStrict]
---""", match.group(2))
def test_yamlParse(self):
text = """
info: >
The production Block { } in strict code can't contain function
declaration;
description: Trying to declare function at the Block statement
negative: SyntaxError
bestPractice: "http://wiki.ecmascript.org/doku.php?id=conventions:no_non_standard_strict_decls"
flags: [onlyStrict]"""
parsed = yaml.load(text)
self.assertEqual("Trying to declare function at the Block statement",
parsed['description'])
self.assertEqual("SyntaxError", parsed['negative'])
self.assertEqual('http://wiki.ecmascript.org/doku.php?id=conventions:no_non_standard_strict_decls', parsed['bestPractice'])
self.assertEqual(["onlyStrict"], parsed['flags'])
self.assertEqual("The production Block { } in strict code can't contain function declaration;\n", parsed['info'])
def test_hasYAML(self):
self.assertTrue(hasYAML("---\n some: yaml\n\n---"))
self.assertFalse(hasYAML("\n* Test description\n *\n * @foo bar\n* @noStrict\n"))
def test_fixturehasYAML(self):
name = 'fixtures/test262-yaml-headers.js'
contents = slurpFile(name)
self.assertTrue('---' in contents)
match = matchParts(contents, name)
self.assertTrue(hasYAML(match.group(2)))
def test_missingKeys(self):
result = {}
yamlAttrParser(result, """---
info: some info (note no flags or includes)
---""", "")
self.assertEqual("some info (note no flags or includes)", result['commentary'])
def test_overview(self):
name = 'fixtures/test262-yaml-headers.js'
contents = slurpFile(name)
record = parseTestRecord(contents, name)
self.assertEqual("""// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.""",
record['header'])
self.assertEqual("The production Block { } in strict code can't contain function declaration;\n", record['commentary'])
self.assertEqual("Trying to declare function at the Block statement",
record['description'])
self.assertEqual(['onlyStrict'], record['flags'])
self.assertEqual("", record['onlyStrict'])
self.assertEqual("SyntaxError", record['negative'])
self.assertEqual("http://wiki.ecmascript.org/doku.php?id=conventions:no_non_standard_strict_decls",
record['bestPractice'])
self.assertEqual(""""use strict";
{
function __func(){}
}
""", record['test'])
def test_negative(self):
name = 'fixtures/negative.js'
contents = slurpFile(name)
record = parseTestRecord(contents, name)
self.assertEqual('early', record['negative']['phase'])
self.assertEqual('SyntaxError', record['negative']['type'])
if __name__ == '__main__':
unittest.main()
#!/usr/bin/env python
# Copyright 2014 by Sam Mikes. All rights reserved.
# This code is governed by the BSD license found in the LICENSE file.
import unittest
import sys
import os
import cStringIO
from functools import wraps
sys.path.append("src")
import test262
class TestTest262(unittest.TestCase):
def test_that_tests_run(self):
self.assertEqual(1 + 2, 3)
class MockTest(object):
def __init__(self, name, negative):
self.name = name
self.negative = negative if negative else False
self.strict_mode = False
def GetName(self):
return self.name
def IsNegative(self):
return self.negative
def GetMode(self):
if self.strict_mode:
return "strict mode"
return "non-strict mode"
class MockResult(object):
def __init__(self, case):
self.case = case
class TestTestSuite(unittest.TestCase):
def test_that_tests_run(self):
self.assertEqual(1 + 2, 3)
def test_create_test_suite(self):
test_suite = test262.TestSuite(".",
False,
False,
False,
None)
self.assertNotEqual(test_suite, None)
def test_summary(self):
test_suite = test262.TestSuite(".",
False,
False,
False,
None)
progress = test262.ProgressIndicator(100)
progress.succeeded = 98
progress.failed = 2
result = mute(True)(test_suite.PrintSummary)(progress, None)
self.assertEqual("""
=== Summary ===
- Ran 100 tests
- Passed 98 tests (98.0%)
- Failed 2 tests (2.0%)
""", result)
def test_summary_logfile(self):
test_suite = test262.TestSuite(".",
False,
False,
False,
None)
progress = test262.ProgressIndicator(100)
progress.succeeded = 98
progress.failed = 2
fake_log = cStringIO.StringIO()
test_suite.logf = fake_log
result = mute(True)(test_suite.PrintSummary)(progress, True)
expected_out = """
=== Summary ===
- Ran 100 tests
- Passed 98 tests (98.0%)
- Failed 2 tests (2.0%)
"""
expected_log = """=== Summary ===
- Ran 100 tests
- Passed 98 tests (98.0%)
- Failed 2 tests (2.0%)
"""
self.assertEqual(expected_out, result)
self.assertEqual(expected_log, fake_log.getvalue())
def test_summary_withfails(self):
test_suite = test262.TestSuite(".",
False,
False,
False,
None)
progress = test262.ProgressIndicator(100)
progress.succeeded = 98
progress.failed = 2
progress.failed_tests = [
MockResult(MockTest("foo", False)),
MockResult(MockTest("bar", True))
]
result = mute(True)(test_suite.PrintSummary)(progress, None)
self.assertEqual("""
=== Summary ===
- Ran 100 tests
- Passed 98 tests (98.0%)
- Failed 2 tests (2.0%)
Failed Tests
foo in non-strict mode
Expected to fail but passed ---
bar in non-strict mode
""", result)
def test_summary_withfails_andlog(self):
test_suite = test262.TestSuite(".",
False,
False,
False,
None)
progress = test262.ProgressIndicator(100)
progress.succeeded = 98
progress.failed = 2
progress.failed_tests = [
MockResult(MockTest("foo", False)),
MockResult(MockTest("bar", True))
]
fake_log = cStringIO.StringIO()
test_suite.logf = fake_log
expected_out = """
=== Summary ===
- Ran 100 tests
- Passed 98 tests (98.0%)
- Failed 2 tests (2.0%)
Failed Tests
foo in non-strict mode
Expected to fail but passed ---
bar in non-strict mode
"""
expected_log = """=== Summary ===
- Ran 100 tests
- Passed 98 tests (98.0%)
- Failed 2 tests (2.0%)
Failed Tests
foo in non-strict mode
Expected to fail but passed ---
bar in non-strict mode
"""
result = mute(True)(test_suite.PrintSummary)(progress, True)
self.assertEqual(expected_out, result)
self.assertEqual(expected_log, fake_log.getvalue())
def test_summary_success_logfile(self):
test_suite = test262.TestSuite(".",
False,
False,
False,
None)
progress = test262.ProgressIndicator(100)
progress.succeeded = 100
progress.failed = 0
fake_log = cStringIO.StringIO()
test_suite.logf = fake_log
result = mute(True)(test_suite.PrintSummary)(progress, True)
expected_out = """
=== Summary ===
- Ran 100 tests
- All tests succeeded
"""
expected_log = """=== Summary ===
- Ran 100 tests
- All tests succeeded
"""
self.assertEqual(expected_out, result)
self.assertEqual(expected_log, fake_log.getvalue())
def test_percent_format(self):
self.assertEqual(test262.PercentFormat(1, 100), "1 test (1.0%)")
self.assertEqual(test262.PercentFormat(0, 100), "0 tests (0.0%)")
self.assertEqual(test262.PercentFormat(99, 100), "99 tests (99.0%)")
# module level utility functions
# copied from https://stackoverflow.com/questions/2828953/silence-the-stdout-of-a-function-in-python-without-trashing-sys-stdout-and-resto
def mute(returns_output=False):
"""
Decorate a function that prints to stdout, intercepting the output.
If "returns_output" is True, the function will return a generator
yielding the printed lines instead of the return values.
The decorator litterally hijack sys.stdout during each function
execution for ALL THE THREADS, so be careful with what you apply it to
and in which context.
>>> def numbers():
print "42"
print "1984"
...
>>> numbers()
42
1984
>>> mute()(numbers)()
>>> list(mute(True)(numbers)())
['42', '1984']
"""
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
saved_stdout = sys.stdout
sys.stdout = cStringIO.StringIO()
try:
out = func(*args, **kwargs)
if returns_output:
out = sys.stdout.getvalue()
finally:
sys.stdout = saved_stdout
return out
return wrapper
return decorator
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment