From 4205a1da64ca124fa0852b0170679772d2ca5786 Mon Sep 17 00:00:00 2001 From: Sam Mikes Date: Fri, 1 Aug 2014 12:38:31 +0100 Subject: [PATCH] harness: remove unused code sta.js: slight change to Test262Error() semantics; message property now always set (default "") make $ERROR a var set $ERROR to function $ERROR so it can be overridden if needed remove 2009 copyright in favor of 2012 copyright REVERTED: remove never-used fn testFailed testFailed actually used by $FAIL remove obsolete fn $INCLUDE ed.js: remove commented-out obsolete code test262.py: remove always-included harness file that provides no functions used by any extant test add comment line to nonstrict cth.js: define `print` for node, cscript use cth (console test harness) to define functions for console runner. V8, Spidermonkey (js) and JavaScriptCore (jsc) provide a function `print`. Provide a default `print` for node and cscript set print_handle to 'print' by default (can still override) for cscript: wrap tests in try/catch so we get syntax errors --- test/harness/cth.js | 30 +++++++++++++++++++++++++++--- test/harness/ed.js | 17 ----------------- test/harness/sta.js | 20 ++++++-------------- tools/packaging/test262.py | 31 ++++++++++++++++++++++--------- 4 files changed, 55 insertions(+), 43 deletions(-) diff --git a/test/harness/cth.js b/test/harness/cth.js index c741b0f8a2..4fae994a04 100644 --- a/test/harness/cth.js +++ b/test/harness/cth.js @@ -10,6 +10,30 @@ function testRun(id, path, description, codeString, result, error) { } } -function testFinished() { - //no-op -} \ No newline at end of file +// define a default `print` function for async tests where there is no +// global `print` +var print; + +// in node use console.log +if (typeof console === "object") { + print = function () { + var args = Array.prototype.slice.call(arguments); + console.log(args.join(" ")); + }; +} + +// in WScript, use WScript.Echo +if (typeof WScript === "object") { + print = function () { + var args = Array.prototype.slice.call(arguments); + WScript.Echo(args.join(" ")); + }; + + // also override $ERROR to force a nonzero exit code exit + // TODO? report syntax errors + var oldError = $ERROR; + $ERROR = function (message) { + print("Test262 Error: " + message); + WScript.Quit(1); + }; +} diff --git a/test/harness/ed.js b/test/harness/ed.js index 88e2cecc49..1c5cabd8e8 100644 --- a/test/harness/ed.js +++ b/test/harness/ed.js @@ -12,20 +12,3 @@ if (this.window!==undefined) { //for console support }; } -//This doesn't work with early errors in current versions of Opera -/* -if (/opera/i.test(navigator.userAgent)) { - (function() { - var origError = window.Error; - window.Error = function() { - if (arguments.length>0) { - try { - window.onerror(arguments[0]); - } catch(e) { - alert("Failed to invoke window.onerror (from ed.js)"); - } - } - return origError.apply(this, arguments); - } - })(); -}*/ \ No newline at end of file diff --git a/test/harness/sta.js b/test/harness/sta.js index 863ba6998a..e779fc9108 100644 --- a/test/harness/sta.js +++ b/test/harness/sta.js @@ -4,31 +4,23 @@ /// "Use Terms"). Any redistribution of this code must retain the above /// copyright and this notice and otherwise comply with the Use Terms. - - -//----------------------------------------------------------------------------- var NotEarlyErrorString = "NotEarlyError"; var EarlyErrorRePat = "^((?!" + NotEarlyErrorString + ").)*$"; var NotEarlyError = new Error(NotEarlyErrorString); -//----------------------------------------------------------------------------- -// Copyright 2009 the Sputnik authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - function Test262Error(message) { - if (message) this.message = message; + this.message = message || ""; } Test262Error.prototype.toString = function () { return "Test262 Error: " + this.message; }; -function testFailed(message) { +var $ERROR; +$ERROR = function $ERROR(message) { throw new Test262Error(message); -} +}; -function $INCLUDE(message) { } -function $ERROR(message) { - testFailed(message); +function testFailed(message) { + $ERROR(message); } - diff --git a/tools/packaging/test262.py b/tools/packaging/test262.py index 0c3caf7d62..55cb55add3 100755 --- a/tools/packaging/test262.py +++ b/tools/packaging/test262.py @@ -74,7 +74,7 @@ def BuildOptions(): result.add_option("--junitname", help="Filename to save test results in JUnit XML format") result.add_option("--loglevel", default="warning", help="sets log level to debug, info, warning, error, or critical") - result.add_option("--print-handle", default="", help="Command to print from console") + result.add_option("--print-handle", default="print", help="Command to print from console") result.add_option("--list-includes", default=False, action="store_true", help="List includes required by tests") return result @@ -261,11 +261,22 @@ class TestCase(object): def GetAdditionalIncludes(self): return '\n'.join([self.suite.GetInclude(include) for include in self.GetIncludeList()]) - def GetSource(self): + def WrapTest(self, command): + if "cscript" not in command: + return self.test + + return """ +try { +""" + self.test + """ +} catch(e) { + $ERROR(e.message); +} +""" + + def GetSource(self, command_template): # "var testDescrip = " + str(self.testRecord) + ';\n\n' + \ - source = self.suite.GetInclude("cth.js") + \ - self.suite.GetInclude("sta.js") + \ - self.suite.GetInclude("ed.js") + source = self.suite.GetInclude("sta.js") + \ + self.suite.GetInclude("cth.js") if self.IsAsyncTest(): source = source + \ @@ -274,12 +285,14 @@ class TestCase(object): source = source + \ self.GetAdditionalIncludes() + \ - self.test + '\n' + self.WrapTest(command_template) + '\n' if self.strict_mode: source = '"use strict";\nvar strict_mode = true;\n' + source else: - source = "var strict_mode = false; \n" + source + # add comment line so line numbers match in both strict and non-strict version + source = '//"no strict";\nvar strict_mode = false;\n' + source + return source def InstantiateTemplate(self, template, params): @@ -312,7 +325,7 @@ class TestCase(object): return (code, out, err) def RunTestIn(self, command_template, tmp): - tmp.Write(self.GetSource()) + tmp.Write(self.GetSource(command_template)) tmp.Close() command = self.InstantiateTemplate(command_template, { 'path': tmp.name @@ -329,7 +342,7 @@ class TestCase(object): return result def Print(self): - print self.GetSource() + print self.GetSource("") class ProgressIndicator(object):