Add test/ directory, including run-tests.html from Test.AnotherWay, and some of Phil's work from the original Hunut code base. Test.AnotherWay lives at http://www.openjsan.org/src/a/ar/artemkhodush/Test.AnotherWay-0.51/doc/.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@10 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
16
test/README.txt
Normal file
16
test/README.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
This directory contains unit tests for the OpenLayers library.
|
||||
|
||||
Tests use the Test.AnotherWay library from <http://openjsan.org>. The test
|
||||
runner is 'run-tests.html' and new test files need to be added to
|
||||
'list-tests.html'.
|
||||
|
||||
The following file naming conventions are used:
|
||||
|
||||
* A filename that starts with `test_` and has an `.html` extension
|
||||
contains tests. These should contain tests for a specific class.
|
||||
|
||||
* A filename starting with `page_` and has an `.html` extension is a
|
||||
supporting HTML file used in one or more tests.
|
||||
|
||||
* A filename starting with 'data_` is a supporting data file used in one
|
||||
or more tests.
|
||||
2379
test/run-tests.html
Normal file
2379
test/run-tests.html
Normal file
File diff suppressed because it is too large
Load Diff
83
test/throws.js
Normal file
83
test/throws.js
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
|
||||
throws.js -- Adds a `throws_` method to AnotherWay test objects.
|
||||
|
||||
Copyright 2005 MetaCarta, Inc., released under the BSD License.
|
||||
|
||||
|
||||
A reference to this file needs to be added to `run-tests.html` in the
|
||||
head element after the AnotherWay classes are created:
|
||||
|
||||
<script type="text/javascript" src="throws.js"></script>
|
||||
|
||||
Then, it can be used just like the `ok`, `fail` and other such methods
|
||||
in your unit tests.
|
||||
|
||||
e.g.
|
||||
|
||||
t.throws_(function () {new OpenLayers.View.Map.Dynamic();},
|
||||
ReferenceError("No container supplied."),
|
||||
"OpenLayers.View.Map.Dynamic instantiation with no container "
|
||||
+ "must throw.");
|
||||
|
||||
This was inspired by the `assertRaises` method of Python's unittest
|
||||
library.
|
||||
|
||||
Possible future enhancements:
|
||||
|
||||
* Contribute to official AnotherWay distribution.
|
||||
* Use `apply` rather than require a inner function (or as an option).
|
||||
* Preserve the stack fields.
|
||||
|
||||
*/
|
||||
|
||||
Test.AnotherWay._test_object_t.prototype.throws_ =
|
||||
function (fn, expectedException, doc) {
|
||||
/*
|
||||
|
||||
Executes the supplied function object catching any exception(s)
|
||||
thrown, then verifies the supplied expected exception occurred.
|
||||
|
||||
If no exception is thrown the test fails.
|
||||
|
||||
If an exception is thrown and it does not match the supplied
|
||||
expected exception the test fails.
|
||||
|
||||
If the exception thrown matches the supplied expected exception
|
||||
the test passes.
|
||||
|
||||
Two exceptions "match" if Test.AnotherWay's `eq` method considers
|
||||
the two equal when their respective stacks are ignored.
|
||||
|
||||
fn - The function object to be executed
|
||||
expectedException - The exception object expected to result
|
||||
doc - Description of the test
|
||||
|
||||
Note: The name of this method is `throws_` (with a trailing
|
||||
underscore) as `throws` is a reserved identifier and can
|
||||
not be used as a method name.
|
||||
|
||||
Note: This function does not preserve the stack field associated
|
||||
with either exception.
|
||||
|
||||
*/
|
||||
var theCaughtException = null;
|
||||
|
||||
try {
|
||||
fn();
|
||||
} catch (innerCaughtException) {
|
||||
// As `innerCaughtException` is not visible outside the scope
|
||||
// of this `catch` block we need to make it visible explicitly.
|
||||
theCaughtException = innerCaughtException;
|
||||
}
|
||||
|
||||
if (theCaughtException) {
|
||||
// We delete the stacks before comparison as they will never match.
|
||||
delete theCaughtException.stack;
|
||||
delete expectedException.stack;
|
||||
this.eq(theCaughtException, expectedException, doc);
|
||||
} else {
|
||||
this.fail(doc);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user