Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bterlson committed Jul 29, 2014
0 parents commit 39acead
Show file tree
Hide file tree
Showing 31 changed files with 2,445 additions and 0 deletions.
27 changes: 27 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright (c) 2014, Microsoft Corporation
All rights reserved.

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 [project] 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 HOLDER 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.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Test262-Harness
An experimental Node-based test262 harness. Once this harness has stabilized, I plan to push to include it by default in official test262.

Note that this harness requires the normalized test262 format currently proposed in http://github.com/tc39/test262/pulls/51.

### Running tests
1. Clone the repository
2. `npm install`
3. `node bin\run.js <glob of files to match>`

### Example
Run chapter 8 tests:

`> node bin\run.js ../test262/test/suite/ch08/**/*.js`

#### Options
| Name | Action |
|------------|---------------|
| --runner | Selects a runner to use. Currently available are `node` and `console`
| --consoleCommand | For console runner, sets the command to invoke. Must be in PATH.
| --consolePrintCommand | For console runner, sets the command to write to console. Used for reporting errors to the harness.
| --testStrict | Tests both strict and non-strict mode (note: many tests need fixing for this to work)
| --reporter | Selects test case result format. Currently either `json` or `tap`. Default `tap`.
59 changes: 59 additions & 0 deletions bin/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (C) 2014, Microsoft Corporation. All rights reserved.
// This code is governed by the BSD License found in the LICENSE file.

var parser = require('../lib/parser');
var tapify = require('../lib/tapify');
var glob = require('glob');
var through = require('through');
var fs = require('fs');
var jss = require('JSONStream').stringify()

var args = require('minimist')(process.argv.slice(2), {
default: {
runner: 'node',
reporter: 'tap',
threads: 1,
consolePrintCommand: 'console.log'
}
});

// Try to create our runner
var Runner;
try {
Runner = require('../lib/runners/' + args.runner);
} catch(e) {
if(e.code === 'MODULE_NOT_FOUND') throw new Error('Runner ' + args.runner + ' not found.');
throw e;
}

glob(args._[0], function (err, files) {
var index = -1;

function nextFile() {
index++;
if(index < files.length) {
processFile(files[index], nextFile);
} else {
parser.end();
}
}

nextFile();

function processFile(file, cb) {
fs.readFile(file, 'utf-8', function(err, contents) {
parser.write({file: file, contents: contents});
cb();
});
}
});

var runner = new Runner(args);
var results = parser
.pipe(runner.getStreamingCompiler());

if(args.reporter === 'json') {
results.pipe(jss).pipe(process.stdout);
} else if(args.reporter === 'tap') {
results.pipe(tapify).pipe(process.stdout);
}
11 changes: 11 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (C) 2014, Microsoft Corporation. All rights reserved.
// This code is governed by the BSD License found in the LICENSE file.

var fs = require('fs');
var parseFile = require('./parser').parseFile;

fs.readdirSync(__dirname + '/helpers')
.forEach(function(file) {
exports[file] =
parseFile({contents: fs.readFileSync(__dirname + '/helpers/' + file, 'utf-8'), file: file});
});
10 changes: 10 additions & 0 deletions lib/helpers/$FAIL.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*---
includes: [Test262Error.js]
---*/
function testFailed(message) {
throw new Test262Error(message);
}

function $FAIL(message) {
testFailed(message);
}
1 change: 1 addition & 0 deletions lib/helpers/$INCLUDE.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function $INCLUDE(){}
2 changes: 2 additions & 0 deletions lib/helpers/$PRINT.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
function $PRINT() {};

80 changes: 80 additions & 0 deletions lib/helpers/Date_constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

var HoursPerDay = 24;
var MinutesPerHour = 60;
var SecondsPerMinute = 60;

var msPerDay = 86400000;
var msPerSecond = 1000;
var msPerMinute = 60000;
var msPerHour = 3600000;

var date_1899_end = -2208988800001;
var date_1900_start = -2208988800000;
var date_1969_end = -1;
var date_1970_start = 0;
var date_1999_end = 946684799999;
var date_2000_start = 946684800000;
var date_2099_end = 4102444799999;
var date_2100_start = 4102444800000;

//the following values are normally generated by the sputnik.py driver
var $LocalTZ,
$DST_start_month,
$DST_start_sunday,
$DST_start_hour,
$DST_start_minutes,
$DST_end_month,
$DST_end_sunday,
$DST_end_hour,
$DST_end_minutes;

(function () {
/**
* Finds the first date, starting from |start|, where |predicate|
* holds.
*/
var findNearestDateBefore = function(start, predicate) {
var current = start;
var month = 1000 * 60 * 60 * 24 * 30;
for (var step = month; step > 0; step = Math.floor(step / 3)) {
if (!predicate(current)) {
while (!predicate(current))
current = new Date(current.getTime() + step);
current = new Date(current.getTime() - step);
}
}
while (!predicate(current)) {
current = new Date(current.getTime() + 1);
}
return current;
};

var juneDate = new Date(2000, 5, 20, 0, 0, 0, 0);
var decemberDate = new Date(2000, 11, 20, 0, 0, 0, 0);
var juneOffset = juneDate.getTimezoneOffset();
var decemberOffset = decemberDate.getTimezoneOffset();
var isSouthernHemisphere = (juneOffset > decemberOffset);
var winterTime = isSouthernHemisphere ? juneDate : decemberDate;
var summerTime = isSouthernHemisphere ? decemberDate : juneDate;

var dstStart = findNearestDateBefore(winterTime, function (date) {
return date.getTimezoneOffset() == summerTime.getTimezoneOffset();
});
$DST_start_month = dstStart.getMonth();
$DST_start_sunday = dstStart.getDate() > 15 ? '"last"' : '"first"';
$DST_start_hour = dstStart.getHours();
$DST_start_minutes = dstStart.getMinutes();

var dstEnd = findNearestDateBefore(summerTime, function (date) {
return date.getTimezoneOffset() == winterTime.getTimezoneOffset();
});
$DST_end_month = dstEnd.getMonth();
$DST_end_sunday = dstEnd.getDate() > 15 ? '"last"' : '"first"';
$DST_end_hour = dstEnd.getHours();
$DST_end_minutes = dstEnd.getMinutes();

return;
})();

Loading

0 comments on commit 39acead

Please sign in to comment.