Skip to content
Snippets Groups Projects
Commit 01490455 authored by Brian Terlson's avatar Brian Terlson
Browse files

Merge pull request #86 from smikes/pr/83

browser runner: check negative regex
parents 0caf4eec 4debe087
No related branches found
No related tags found
No related merge requests found
......@@ -6,9 +6,20 @@
//Error Detector
if (this.window!==undefined) { //for console support
this.window.onerror = function(errorMsg, url, lineNumber) {
this.window.iframeError = errorMsg;
if(typeof $DONE === 'function') $DONE();
this.window.onerror = function(errorMsg, url, lineNumber, colNumber, error) {
var cookedError;
if (error) {
cookedError = error.toString();
} else {
if (/Error:/.test(errorMsg)) {
cookedError = errorMsg;
} else {
cookedError = "UnknownError: " + errorMsg;
}
}
$DONE(cookedError);
};
}
......@@ -5,68 +5,66 @@
/// copyright and this notice and otherwise comply with the Use Terms.
//Global Scope Test Case Validator
function $DONE() {
var doneCalled;
function $DONE(argError) {
var testError;
var result, resultError;
if (argError) {
testError = argError.toString();
}
if (doneCalled) {
// ? log called twice
return;
}
doneCalled = true;
//An exception is expected
if (testDescrip.negative !== undefined) {
//TODO - come up with a generic way of catching the error type
//from this.onerror
testDescrip.negative = testDescrip.negative === "NotEarlyError" ?
testDescrip.negative :
(testDescrip.negative === "^((?!NotEarlyError).)*$" ?
testDescrip.negative : ".");
if (this.iframeError === undefined) { //no exception was thrown
testRun(testDescrip.id,
testDescrip.path,
testDescrip.description,
testDescrip.code,
'fail',
Error('No exception was thrown; expected an error "message"' +
' property matching the regular expression "' +
testDescrip.negative + '".'));
} else if (!(new RegExp(testDescrip.negative,
"i").test(this.iframeError))) {
var negRegexp = new RegExp(testDescrip.negative, "i"),
unkRegexp = /^UnknownError:/;
if (!testError) { //no exception was thrown
result = 'fail';
resultError = Error('No exception was thrown; expected an error "message"' +
' property matching the regular expression "' +
testDescrip.negative + '".');
} else if (!negRegexp.test(testError) &&
!unkRegexp.test(testError)) {
//wrong type of exception thrown
testRun(testDescrip.id,
testDescrip.path,
testDescrip.description,
testDescrip.code,
'fail',
Error('Expected an exception with a "message"' +
' property matching the regular expression "' +
testDescrip.negative +
'" to be thrown; actual was "' +
this.iframeError + '".'));
result = 'fail';
resultError = Error('Expected an exception with a "message"' +
' property matching the regular expression "' +
testDescrip.negative +
'" to be thrown; actual was "' +
testError + '".');
} else {
testRun(testDescrip.id,
testDescrip.path,
testDescrip.description,
testDescrip.code,
'pass',
undefined);
result = 'pass';
resultError = 'undefined';
}
} else if (testError) {
//Exception was not expected to be thrown
result = 'fail';
resultError = Error('Unexpected exception, "' + testError + '" was thrown.');
} else {
result = 'pass';
resultError = undefined;
}
//Exception was not expected to be thrown
else if (this.iframeError !== undefined) {
testRun(testDescrip.id,
testDescrip.path,
testDescrip.description,
testDescrip.code,
'fail',
Error('Unexpected exception, "' +
this.iframeError + '" was thrown.'));
}
else {
testRun(testDescrip.id,
testDescrip.path,
testDescrip.description,
testDescrip.code,
'pass',
undefined);
}
testRun(testDescrip.id,
testDescrip.path,
testDescrip.description,
testDescrip.code,
result,
resultError);
//teardown
testFinished();
}
\ No newline at end of file
}
......@@ -129,7 +129,7 @@ function BrowserRunner() {
//TODO - 500ms *should* be a sufficient delay
setTimeout(function() {
instance.supportsWindowOnerror = iwinPrereqs.failCount === 2;
instance.supportsWindowOnerror = (iwinPrereqs.failCount === 2);
//alert(iwinPrereqs.failCount);
document.body.removeChild(iframePrereqs);
instance.run(test, code);
......
......@@ -14,8 +14,9 @@ var y = 1;
//////////////////////////////////////////////////////////////////////////////
//CHECK#1
if(delete y){
$ERROR('#1: y = 1; (delete y) === false. Actual: ' + ((delete y)));
var result = delete y;
if(result){
$ERROR('#1: y = 1; (delete y) === false. Actual: ' + result);
};
//
//////////////////////////////////////////////////////////////////////////////
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment