Added exception checking to unit tests

This commit is contained in:
Atlante45 2014-07-11 16:23:50 -07:00
parent b9fe5b2ef1
commit 75573a4c06

View file

@ -20,7 +20,7 @@ test = function(name, func) {
unitTest.run();
print(" Success: " + unitTest.numAssertions + " assertions passed");
} catch (error) {
print(" Failure: " + error.message);
print(" Failure: " + error.name + " " + error.message);
}
};
@ -30,6 +30,12 @@ AssertionException = function(expected, actual, message) {
this.name = 'AssertionException';
};
UnthrownException = function(message) {
print("Creating exception");
this.message = message + "\n";
this.name = 'UnthrownException';
};
UnitTest = function(name, func) {
this.numAssertions = 0;
this.func = func;
@ -77,4 +83,15 @@ UnitTest.prototype.arrayEqual = function(array1, array2, message) {
throw new AssertionException(array1[i], array2[i], message);
}
}
}
UnitTest.prototype.raises = function(func, message) {
this.numAssertions++;
try {
func();
} catch (error) {
return;
}
throw new UnthrownException(message);
}