mirror of
https://github.com/overte-org/overte.git
synced 2025-08-12 12:34:11 +02:00
Added exception checking to unit tests
This commit is contained in:
parent
b9fe5b2ef1
commit
75573a4c06
1 changed files with 18 additions and 1 deletions
|
@ -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);
|
||||
}
|
Loading…
Reference in a new issue