Skip to content

Commit

Permalink
Added assertionCache loading and tracability (web-platform-tests#3298)
Browse files Browse the repository at this point in the history
JSON Schema referenced in assertions by name (e.g., "foo.json") were
being loaded but not placed in the cache.  This meant that they were not
actually being used when testing.

Also improved the output when there are subtests to make it easier to
evaluate which assertion was being evaluated (since assertions are
evaluated bottom-up if there is complex nesting).

Finally, also changed relative URI handling so that we know the complete
path of each component loaded to make it easier to debug.
  • Loading branch information
halindrome authored and ddorwin committed Sep 13, 2016
1 parent 5c25732 commit 7745644
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions annotation-model/scripts/JSONtest.js
Expand Up @@ -24,7 +24,8 @@ function JSONtest(params) {
this.Assertions = []; // object that will contain the assertions to process
this.AssertionText = ""; // string that holds the titles of all the assertions in use
this.DescriptionText = "";
this.Base = null; // URI "base" for the tests being run
this.Base = null; // URI "base" for the test suite being run
this.TestDir = null; // URI "base" for the test case being run
this.Params = null; // paramaters passed in
this.Properties = null; // testharness_properties from the opening window
this.Test = null; // test being run
Expand Down Expand Up @@ -52,6 +53,7 @@ function JSONtest(params) {

var l = document.location;
var p = l.pathname;
this.TestDir = p.substr(0, 1+p.lastIndexOf('/'));
this.Base = p.substr(0, 1+p.indexOf('/', 1));

// if we are under runner, then there are props in the parent window
Expand Down Expand Up @@ -365,7 +367,7 @@ JSONtest.prototype = {
} else {
assert_true(result, err) ;
}
}.bind(this), assert.title);
}.bind(this), "" + level + ":" + (num+1) + " " + assert.title);
// we are going to return out of this
return;
}
Expand All @@ -384,6 +386,18 @@ JSONtest.prototype = {

var schemaName = "inline " + level + ":" + (num+1);

if (typeof assert === "string") {
// the assertion passed in is a file name; find it in the cache
if (this._assertionCache[assert]) {
assert = this._assertionCache[assert];
} else {
test( function() {
assert_true(false, "Reference to assertion " + assert + " at level " + level + ":" + (num+1) + " unresolved") ;
}, "Processing " + assert);
return ;
}
}

if (assert.assertionFile) {
schemaName = "external file " + assert.assertionFile + " " + level + ":" + (num+1);
}
Expand Down Expand Up @@ -432,7 +446,7 @@ JSONtest.prototype = {
} else {
assert_true(result, err) ;
}
}.bind(this), assert.title);
}.bind(this), "" + level + ":" + (num+1) + " " + assert.title);
}
}.bind(this));
}
Expand Down Expand Up @@ -497,6 +511,7 @@ JSONtest.prototype = {
this._loadFile("GET", theFile, true)
.then(function(data) {
data.assertionFile = afile;
this._assertionCache[afile] = data;
resolve(data);
}.bind(this))
.catch(function(err) {
Expand Down Expand Up @@ -581,7 +596,7 @@ JSONtest.prototype = {
if (theURI.indexOf('/') === -1) {
// no slash - it's relative to where we are
// so just use it
return theURI;
return this.TestDir + theURI;
} else if (theURI.indexOf('/') === 0 || theURI.indexOf('http:') === 0 || theURI.indexOf('https:') === 0) {
// it is an absolute URI so just use it
return theURI;
Expand Down Expand Up @@ -619,7 +634,8 @@ JSONtest.prototype = {
} else if (typeof assert === "object") {
ret.push(assert) ;
if (assert.hasOwnProperty("assertions")) {
ret.push(this._assertionRefs(assert.assertions));
// there are embedded assertions; get those too
ret.concat(this._assertionRefs(assert.assertions));
}
} else {
// it is a file name
Expand Down

0 comments on commit 7745644

Please sign in to comment.