Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include test "compilation" logic #7

Merged
merged 6 commits into from
Jan 19, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/test/collateral/
/lib/compilerdeps.js
2 changes: 1 addition & 1 deletion lib/compile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
const fs = require('fs');
const path = require('path');
const compile = require('test262-compiler');
const compile = require('./compiler');

const createScenarios = require('./create-scenarios');

Expand Down
45 changes: 45 additions & 0 deletions lib/compiler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict';
const fs = require('fs');
const path = require('path');
const parseFile = require('test262-parser').parseFile;
const deps = fs.readFileSync(__dirname + '/compilerdeps.js');

module.exports = function compile(test, options) {
options = options || {};
if (!options.test262Dir && !options.includesDir) {
throw new Error('Need one of test262Dir or includesDir options');
}

if (options.test262Dir && !options.includesDir) {
options.includesDir = path.join(options.test262Dir, 'harness');
}

test = parseFile(test);

if (test.attrs.flags.raw) {
return test;
}

if (test.contents.indexOf('$DONE') === -1) {
test.contents += '\n;$DONE();';
}

let preludeContents = '';
if (test.attrs.flags.onlyStrict) {
preludeContents += '"use strict";\n';
}
preludeContents += deps;

const helpers = test.attrs.includes;
helpers.push('assert.js');
for (let i = 0; i < helpers.length; i++) {
preludeContents += '\n';
preludeContents += fs.readFileSync(
path.join(options.includesDir, helpers[i])
);
}

test.contents = preludeContents + test.contents;

return test;
};
30 changes: 30 additions & 0 deletions lib/compilerdeps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function Test262Error(message) {
if (message) this.message = message;
}

Test262Error.prototype.name = "Test262Error";

Test262Error.prototype.toString = function () {
return "Test262Error: " + this.message;
};

function $ERROR(err) {
if(typeof err === "object" && err !== null && "name" in err) {
throw err;
} else {
throw new Test262Error(err);
}
}

function $DONE(err) {
if (err) {
if(typeof err === "object" && err !== null && "name" in err) {
print('test262/error ' + err.name + ': ' + err.message);
} else {
print('test262/error Test262Error: ' + err);
}
}
print('test262/done');
$262.destroy();
}

9 changes: 5 additions & 4 deletions lib/create-scenarios.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use strict';

module.exports = function scenariosForTest(test) {
// The `test262-compiler` project inserts a global "use strict" directive for
// tests marked with the `onlyStrict` flag. While this obviates the need for
// additional transformations to the source, the `scenario` metadata must
// still be set accordingly.
// The "compilation" logic has been inherited from the `test262-compiler`
// module, which inserts a global "use strict" directive for tests marked
// with the `onlyStrict` flag. While this obviates the need for additional
// transformations to the source, the `scenario` metadata must still be set
// accordingly.
test.scenario = test.attrs.flags.onlyStrict ? 'strict mode' : 'default';

if (!test.attrs.flags.onlyStrict &&
Expand Down
Loading