mirror of
https://github.com/zaphar/test-tap.git
synced 2025-07-26 21:09:59 -04:00
Compare commits
9 Commits
d4da1d7dee
...
975d7f22af
Author | SHA1 | Date | |
---|---|---|---|
975d7f22af | |||
595fef5a2c | |||
5af40106dd | |||
726dd2778f | |||
7e18862cdd | |||
1f6f7f8d16 | |||
f84a7c1bcc | |||
d26f60241f | |||
44feb46f69 |
200
Changes
200
Changes
@ -1,200 +0,0 @@
|
|||||||
Tue Oct 21 16:34:03 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* fixed dirty global scope problems in run_it
|
|
||||||
|
|
||||||
Tue Oct 21 16:27:00 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* Test.TAP needs to know the global scope sometimes so we store it here
|
|
||||||
|
|
||||||
Mon Oct 20 21:51:02 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* added description to the html test harness
|
|
||||||
|
|
||||||
Mon Oct 20 21:49:29 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* using pound properly again
|
|
||||||
|
|
||||||
Mon Oct 20 21:47:43 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* added a license agreement to Class.js
|
|
||||||
|
|
||||||
Mon Oct 20 21:47:28 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* added a new helper script
|
|
||||||
|
|
||||||
Mon Oct 20 18:57:30 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* mkdist shell script
|
|
||||||
|
|
||||||
Mon Oct 20 18:13:07 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* fixed mysterious *pound* bug
|
|
||||||
|
|
||||||
Sun Oct 19 20:20:16 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* use pount instead of ? for test specification
|
|
||||||
|
|
||||||
Sun Oct 19 20:15:09 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* additional harness features
|
|
||||||
|
|
||||||
Sat Oct 18 02:01:14 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* bugfix wrong directory to write to
|
|
||||||
|
|
||||||
Sat Oct 18 01:56:25 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* helper script
|
|
||||||
|
|
||||||
Sat Oct 18 01:31:14 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* added todo and skipped
|
|
||||||
|
|
||||||
Fri Oct 17 22:37:33 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* templates for harness setup
|
|
||||||
|
|
||||||
Thu Oct 16 21:28:00 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* do things in the right order
|
|
||||||
|
|
||||||
Thu Oct 16 21:24:55 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* count needs to be incremented so the onfinished handler gets run correctly
|
|
||||||
|
|
||||||
Thu Oct 16 21:19:50 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* refactored the Test Class library to be more friendly to multi method tests
|
|
||||||
|
|
||||||
Thu Oct 16 21:19:09 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* refactored tests to one testclass and changed harnesses accordingly
|
|
||||||
|
|
||||||
Thu Oct 16 00:06:57 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* a rhino harness for the test suite
|
|
||||||
|
|
||||||
Wed Oct 15 23:55:35 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* whole new test files yay!!
|
|
||||||
|
|
||||||
Wed Oct 15 23:53:15 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* refactored a whole lotta tests
|
|
||||||
|
|
||||||
Wed Oct 15 23:18:51 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* changed the size of the test divs for less scrolling
|
|
||||||
|
|
||||||
Wed Oct 15 23:11:28 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* asynchronous harness and accompanying tests
|
|
||||||
|
|
||||||
Wed Oct 15 22:54:50 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* made the asynchronous stuff safe for non-browser tests
|
|
||||||
|
|
||||||
Wed Oct 15 22:42:20 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* imported Malte Ubl's asynchronous testing feature
|
|
||||||
|
|
||||||
Wed Oct 15 22:21:42 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* changes to constructor arguments and improvements to class plan setting
|
|
||||||
|
|
||||||
Wed Oct 15 21:52:32 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* setup and teardown for Test.TAP.Class
|
|
||||||
|
|
||||||
Tue Oct 14 22:56:14 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* a whole lot of refactore goin on (uhhuh)
|
|
||||||
|
|
||||||
Tue Oct 14 22:48:19 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* refactored the harness location
|
|
||||||
|
|
||||||
Tue Oct 14 22:47:18 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* html harness enhancements
|
|
||||||
|
|
||||||
Tue Oct 14 22:07:58 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* Test.TAP.Class is added
|
|
||||||
|
|
||||||
Tue Oct 14 20:45:59 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* Runner uses the refactored Test Class functionality
|
|
||||||
|
|
||||||
Tue Oct 14 20:43:08 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* added a new Test Class to replace Runner
|
|
||||||
|
|
||||||
Tue Oct 14 20:42:31 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* refactored some of Test.TAP for easier reuse of code
|
|
||||||
|
|
||||||
Tue Oct 14 20:27:22 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* pass in your own output function for to override output method
|
|
||||||
|
|
||||||
Sun Sep 28 23:24:34 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* better summaries from the runner
|
|
||||||
|
|
||||||
Sun Sep 28 22:51:37 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* fixed excess newlines in print for commandline systems
|
|
||||||
|
|
||||||
Sat Jun 28 17:29:37 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* updated TODO
|
|
||||||
|
|
||||||
Sat Jun 28 17:28:11 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* fixed descriptions for throws ok
|
|
||||||
|
|
||||||
Sat Jun 28 17:13:41 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* if a test suite dies it doesn't kill the runner now
|
|
||||||
|
|
||||||
Sat Jun 28 14:31:31 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* TODO file added
|
|
||||||
|
|
||||||
Fri Jun 6 20:58:05 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* changed teh Tap.j TAP.js
|
|
||||||
|
|
||||||
Fri Jun 6 20:51:19 CDT 2008 jeremy@marzhillstudios.com
|
|
||||||
* html versions of the tests have been added
|
|
||||||
|
|
||||||
Thu Feb 28 10:20:41 CST 2008 jeremy@marzhillstudios.com
|
|
||||||
tagged V0.12
|
|
||||||
|
|
||||||
Thu Feb 28 10:20:23 CST 2008 jeremy@marzhillstudios.com
|
|
||||||
* up the version number
|
|
||||||
|
|
||||||
Thu Feb 28 10:18:18 CST 2008 jeremy@marzhillstudios.com
|
|
||||||
* added dies_ok and lives_ok tests
|
|
||||||
|
|
||||||
Fri Feb 1 21:02:16 CST 2008 jeremy@marzhillstudios.com
|
|
||||||
* make can_ok work for prototype methods also.
|
|
||||||
|
|
||||||
currently only supports one level of inheritance. this will be fixed later
|
|
||||||
|
|
||||||
|
|
||||||
Fri Sep 14 17:08:58 CDT 2007 jeremy@marzhillstudios.com
|
|
||||||
* documentation for Test.TAP.Runner
|
|
||||||
|
|
||||||
Tue Sep 11 19:50:22 CDT 2007 jeremy@marzhillstudios.com
|
|
||||||
* POD Documentation for Test.TAP
|
|
||||||
|
|
||||||
Mon Sep 10 14:12:34 CDT 2007 jeremy@marzhillstudios.com
|
|
||||||
* fixed version number
|
|
||||||
|
|
||||||
Mon Sep 10 14:10:30 CDT 2007 jeremy@marzhillstudios.com
|
|
||||||
* added changelog
|
|
||||||
|
|
||||||
Mon Sep 10 14:09:01 CDT 2007 jeremy@marzhillstudios.com
|
|
||||||
tagged first release
|
|
||||||
|
|
||||||
Mon Sep 10 14:05:21 CDT 2007 jeremy@marzhillstudios.com
|
|
||||||
* additional debugging output
|
|
||||||
|
|
||||||
Mon Sep 10 14:03:42 CDT 2007 jeremy@marzhillstudios.com
|
|
||||||
* Runner bugfix and the tests that revealed the bug;
|
|
||||||
|
|
||||||
Sat Sep 8 14:00:38 CDT 2007 jeremy@marzhillstudios.com
|
|
||||||
* fixed mut[_^H_]l[_^H_][_^H_][_^H_]
|
|
||||||
|
|
||||||
Fri Sep 7 20:59:27 CDT 2007 jeremy@marzhillstudios.com
|
|
||||||
* readded the running tests <name> tests message
|
|
||||||
|
|
||||||
Fri Sep 7 20:46:40 CDT 2007 jeremy@marzhillstudios.com
|
|
||||||
* added a new message about the name of the test running
|
|
||||||
|
|
||||||
Fri Sep 7 20:45:33 CDT 2007 jeremy@marzhillstudios.com
|
|
||||||
* whitespace cleanup of a mock testobj definition
|
|
||||||
|
|
||||||
Fri Sep 7 20:44:17 CDT 2007 jeremy@marzhillstudios.com
|
|
||||||
* removed test for the running test message
|
|
||||||
|
|
||||||
Fri Sep 7 20:35:54 CDT 2007 jeremy@marzhillstudios.com
|
|
||||||
* added Test.TAP.Runner Library
|
|
||||||
|
|
||||||
Fri Sep 7 20:35:13 CDT 2007 jeremy@marzhillstudios.com
|
|
||||||
* added TAP Directory
|
|
||||||
|
|
||||||
Fri Sep 7 20:34:48 CDT 2007 jeremy@marzhillstudios.com
|
|
||||||
* added tests for Test.TAP.Runner
|
|
||||||
|
|
||||||
Fri Sep 7 19:17:50 CDT 2007 jeremy@marzhillstudios.com
|
|
||||||
* additional META for the library
|
|
||||||
|
|
||||||
Fri Sep 7 19:16:54 CDT 2007 jeremy@marzhillstudios.com
|
|
||||||
* minor changes to the counter and bugfix for throws_ok
|
|
||||||
|
|
||||||
Fri Sep 7 19:16:00 CDT 2007 jeremy@marzhillstudios.com
|
|
||||||
* More tests for Test.TAP test functions [can_ok throws_ok plan]
|
|
||||||
|
|
||||||
Wed Sep 5 19:08:11 CDT 2007 jeremy@marzhillstudios.com
|
|
||||||
* initial start of repository
|
|
8
META.yml
8
META.yml
@ -1,8 +0,0 @@
|
|||||||
--- #YAML:1.0
|
|
||||||
name: Test.TAP
|
|
||||||
version: 0.12
|
|
||||||
author:
|
|
||||||
- Jeremy Wall <Jeremy@marzhillstudiso.com>
|
|
||||||
abstract: A zero dependency TAP compliant test library. Useable from commandline with no mocking
|
|
||||||
license: perl
|
|
||||||
generated_by: Jeremy Wall <Jeremy@marzhillstudiso.com>
|
|
11
README.md
Normal file
11
README.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Test-Tap a 0 dependency single file Test Anything Protocol suite.
|
||||||
|
|
||||||
|
# Install
|
||||||
|
|
||||||
|
copy `src/Tap.mjs` into your source tree.
|
||||||
|
|
||||||
|
Eventually I'll see about publishing it to npm but for now this is good enough.
|
||||||
|
|
||||||
|
# Use
|
||||||
|
|
||||||
|
See the `tests/01_tap.t.js` and `TapHarness.html` for node cli and browser based examples.
|
212
src/Class.js
212
src/Class.js
@ -1,212 +0,0 @@
|
|||||||
if (typeof Test == 'undefined') {
|
|
||||||
Test = {};
|
|
||||||
}
|
|
||||||
if (typeof Test.TAP == 'undefined') {
|
|
||||||
if (typeof JSAN != 'undefined') {
|
|
||||||
JSAN.use('Test.TAP');
|
|
||||||
} else {
|
|
||||||
throw new ReferenceError('Test.TAP.Runner is dependent on Test.TAP');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
=head1 NAME
|
|
||||||
|
|
||||||
Test.TAP.Runner - A Simple Test Harness for Test.TAP
|
|
||||||
|
|
||||||
=head1 Synopsis
|
|
||||||
|
|
||||||
var r = new Test.TAP.Runner().
|
|
||||||
|
|
||||||
var testobj = {};
|
|
||||||
testobj.runtests = function() {
|
|
||||||
var t = new Test.TAP();
|
|
||||||
t.plan(2);
|
|
||||||
t.ok(true, 'true is true');
|
|
||||||
t.is(1, 1, 'one is one');
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
r.run_tests(obj);
|
|
||||||
=cut
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
Test.TAP.Class = function() {
|
|
||||||
var self = this;
|
|
||||||
// call our superclasses constructor as well
|
|
||||||
Test.TAP.apply(self, arguments);
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
=head1 Methods
|
|
||||||
|
|
||||||
=head2 out()
|
|
||||||
|
|
||||||
internal method inherited from L<Test.TAP> see L<Test.TAP> for useage
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
=head2 diag()
|
|
||||||
|
|
||||||
internal method inherited from L<Test.TAP> see L<Test.TAP> for useage
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
=head2 run_it()
|
|
||||||
|
|
||||||
runs the tests in a test object and reports on the results
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
Test.TAP.Class.prototype = new Test.TAP();
|
|
||||||
|
|
||||||
Test.TAP.Class.prototype.run_it = function(method) {
|
|
||||||
var self = this;
|
|
||||||
var fun = self[method];
|
|
||||||
self.diag("trying to run "+method+" tests");
|
|
||||||
|
|
||||||
// remember the globals that existed before the test execution
|
|
||||||
var originalGlobal = {};
|
|
||||||
var top = self.top();
|
|
||||||
for(var name in top ) {
|
|
||||||
originalGlobal[name] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (typeof this.setup == 'function') {
|
|
||||||
self.setup();
|
|
||||||
}
|
|
||||||
fun.call(self);
|
|
||||||
if (typeof this.teardown == 'function') {
|
|
||||||
self.teardown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(err) {
|
|
||||||
this.diag("Test Suite Crashed!!! (" + err + ")");
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
// Delete globals which were created during test execution
|
|
||||||
// THis avoid conflicts between tests when running multiple tests in a row
|
|
||||||
for(var name in top) {
|
|
||||||
if(!originalGlobal[name]) {
|
|
||||||
try {
|
|
||||||
delete top[name]
|
|
||||||
} catch (e) {
|
|
||||||
// Delete threw an error, so just assign undefined
|
|
||||||
top[name] = undefined
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
=head2 run_tests()
|
|
||||||
|
|
||||||
r.run_tests(obj1, obj2);
|
|
||||||
|
|
||||||
runs the tests in a list of test objects and reports on the results
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
Test.TAP.Class.prototype.run_tests = function() {
|
|
||||||
var self = this;
|
|
||||||
var counter = 0;
|
|
||||||
|
|
||||||
var methods = [];
|
|
||||||
for (m in self) {
|
|
||||||
if (m.match(/^test.+/)) {
|
|
||||||
methods.push(m)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.finished = true;
|
|
||||||
|
|
||||||
var onFinish = function () {
|
|
||||||
if (self.planned > self.counter) {
|
|
||||||
self.diag('looks like you planned ' + self.planned + ' tests but only ran '
|
|
||||||
+ self.counter + ' tests');
|
|
||||||
} else if (self.planned < self.counter) {
|
|
||||||
self.diag('looks like you planned ' + self.planned + ' tests but ran '
|
|
||||||
+ (self.counter - self.planned) + ' tests extra');
|
|
||||||
}
|
|
||||||
self.diag('ran ' + self.counter + ' tests out of ' + self.planned);
|
|
||||||
self.diag('passed ' + self.passed + ' tests out of ' + self.planned)
|
|
||||||
self.diag('failed ' + self.failed + ' tests out of ' + self.planned)
|
|
||||||
}
|
|
||||||
|
|
||||||
var count = 0;
|
|
||||||
var testRunInterval
|
|
||||||
if (typeof setInterval == 'undefined') {
|
|
||||||
setInterval = function() {
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (typeof clearInterval == 'undefined') {
|
|
||||||
clearInterval = function() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var run = function () {
|
|
||||||
if(self.finished) {
|
|
||||||
if(count > 0) {
|
|
||||||
if(self.on_finished) {
|
|
||||||
onFinish()
|
|
||||||
self.on_finished()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(methods.length == 0) {
|
|
||||||
clearInterval(testRunInterval)
|
|
||||||
if(self.on_finished_all) {
|
|
||||||
self.on_finished_all()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
self.finished = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(self.planned == "no_plan"
|
|
||||||
|| self.planned == 0
|
|
||||||
|| self.counter >= self.planned) {
|
|
||||||
self.finished = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
testRunInterval = setInterval(run, 50)
|
|
||||||
run();
|
|
||||||
var methodname;
|
|
||||||
while (methodname = methods.shift()) {
|
|
||||||
self.run_it(methodname);
|
|
||||||
count++
|
|
||||||
}
|
|
||||||
run();
|
|
||||||
|
|
||||||
return self;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
=head1 SEE ALSO
|
|
||||||
|
|
||||||
L<Test.Simple>
|
|
||||||
L<Test.AnotherWay>
|
|
||||||
|
|
||||||
=head1 AUTHOR
|
|
||||||
|
|
||||||
Jeremy Wall L<< jeremy@marzhillstudios.com >>
|
|
||||||
|
|
||||||
=head1 COPYRIGHT AND LICENSE
|
|
||||||
|
|
||||||
Copyright (C) 2007 Jeremy Wall
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or modify
|
|
||||||
it under the same terms as Perl itself, either Perl version 5.8.4 or,
|
|
||||||
at your option, any later version of Perl 5 you may have available.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
*/
|
|
104
src/Runner.js
104
src/Runner.js
@ -1,104 +0,0 @@
|
|||||||
if (typeof Test == 'undefined') {
|
|
||||||
Test = {};
|
|
||||||
}
|
|
||||||
if (typeof Test.TAP == 'undefined') {
|
|
||||||
if (typeof JSAN != 'undefined') {
|
|
||||||
JSAN.use('Test.TAP');
|
|
||||||
} else {
|
|
||||||
throw new Error('Test.TAP.Runner is dependent on Test.TAP');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
|
|
||||||
=head1 NAME
|
|
||||||
|
|
||||||
Test.TAP.Runner - A Simple Test Harness for Test.TAP
|
|
||||||
|
|
||||||
=head1 Synopsis
|
|
||||||
|
|
||||||
var r = new Test.TAP.Runner().
|
|
||||||
|
|
||||||
var testobj = {};
|
|
||||||
testobj.runtests = function() {
|
|
||||||
var t = new Test.TAP();
|
|
||||||
t.plan(2);
|
|
||||||
t.ok(true, 'true is true');
|
|
||||||
t.is(1, 1, 'one is one');
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
r.run_tests(obj);
|
|
||||||
=cut
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
Test.TAP.Runner = function() {};
|
|
||||||
|
|
||||||
Test.TAP.Runner.prototype = new Test();
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
=head1 Methods
|
|
||||||
|
|
||||||
=head2 out()
|
|
||||||
|
|
||||||
internal method inherited from L<Test.TAP> see L<Test.TAP> for useage
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
=head2 diag()
|
|
||||||
|
|
||||||
internal method inherited from L<Test.TAP> see L<Test.TAP> for useage
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
=head2 run_it()
|
|
||||||
|
|
||||||
runs the tests in a test object and reports on the results
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
Test.TAP.Runner.prototype.run_it = function(obj) {
|
|
||||||
this.diag('running ' + obj.name + ' tests');
|
|
||||||
var tester;
|
|
||||||
try {
|
|
||||||
tester = obj.runtests();
|
|
||||||
if (tester.planned > tester.counter) {
|
|
||||||
tester.diag('looks like you planned ' + tester.planned + ' tests but only ran '
|
|
||||||
+ tester.counter + ' tests');
|
|
||||||
} else if (tester.planned < tester.counter) {
|
|
||||||
tester.diag('looks like you planned ' + tester.planned + ' tests but ran '
|
|
||||||
+ (tester.counter - tester.planned) + ' tests extra');
|
|
||||||
}
|
|
||||||
this.diag('ran ' + tester.counter + ' tests out of ' + tester.planned);
|
|
||||||
this.diag('passed ' + tester.passed + ' tests out of ' + tester.planned)
|
|
||||||
this.diag('failed ' + tester.failed + ' tests out of ' + tester.planned)
|
|
||||||
}
|
|
||||||
catch(err) {
|
|
||||||
this.diag("Test Suite Crashed!!! (" + err + ")");
|
|
||||||
}
|
|
||||||
|
|
||||||
return tester;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
=head2 run_tests()
|
|
||||||
|
|
||||||
r.run_tests(obj1, obj2);
|
|
||||||
|
|
||||||
runs the tests in a list of test objects and reports on the results
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
Test.TAP.Runner.prototype.run_tests = function() {
|
|
||||||
var all = [];
|
|
||||||
for (i=0; i<arguments.length; i++) {
|
|
||||||
all.push(this.run_it(arguments[i]));
|
|
||||||
this.out('\n');
|
|
||||||
}
|
|
||||||
return all;
|
|
||||||
};
|
|
118
src/TAP.mjs
118
src/TAP.mjs
@ -27,7 +27,7 @@ class NodeRenderer {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
diag(lines) {
|
comment(lines) {
|
||||||
for (var line of lines) {
|
for (var line of lines) {
|
||||||
this.out('# ' + line);
|
this.out('# ' + line);
|
||||||
}
|
}
|
||||||
@ -36,12 +36,44 @@ class NodeRenderer {
|
|||||||
|
|
||||||
/** @implements TapRenderer */
|
/** @implements TapRenderer */
|
||||||
class BrowserRenderer {
|
class BrowserRenderer {
|
||||||
out(text) {
|
#target = document.body;
|
||||||
// TODO(jeremy):
|
|
||||||
|
/** @param {HtmlElement=} target */
|
||||||
|
constructor(target) {
|
||||||
|
if (target) {
|
||||||
|
this.#target = target;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
diag(lines) {
|
/** @returns TextNode */
|
||||||
|
#createText(text) {
|
||||||
|
return document.createTextNode(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Node} nodes
|
||||||
|
* @returns HTMLDivElement
|
||||||
|
*/
|
||||||
|
#createDiv(nodes) {
|
||||||
|
const div = document.createElement("div");
|
||||||
|
div.append(...nodes);
|
||||||
|
return div;
|
||||||
|
}
|
||||||
|
|
||||||
|
out(text) {
|
||||||
|
const textNode = this.#createText(text);
|
||||||
|
this.#target.appendChild(this.#createDiv([textNode]));
|
||||||
|
}
|
||||||
|
|
||||||
|
comment(lines) {
|
||||||
// TODO(jeremy):
|
// TODO(jeremy):
|
||||||
|
var elems = [];
|
||||||
|
for (var line of lines) {
|
||||||
|
elems.push(this.#createText(line), document.createElement("br"));
|
||||||
|
}
|
||||||
|
var commentDiv = this.#createDiv(elems);
|
||||||
|
commentDiv.setAttribute("class", "tap-comment");
|
||||||
|
this.#target.appendChild(commentDiv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,8 +96,8 @@ class Tap {
|
|||||||
* Construct a new Tap Suite with a renderLine function.
|
* Construct a new Tap Suite with a renderLine function.
|
||||||
* @param {TapRenderer}
|
* @param {TapRenderer}
|
||||||
*/
|
*/
|
||||||
constructor(renderFunc) {
|
constructor(renderer) {
|
||||||
this.#renderer = renderFunc;
|
this.#renderer = renderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -98,18 +130,19 @@ class Tap {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
diag(msg){
|
comment(msg){
|
||||||
if(!msg) {
|
if(!msg) {
|
||||||
msg = " ";
|
msg = " ";
|
||||||
}
|
}
|
||||||
var lines = msg.split("\n");
|
var lines = msg.split("\n");
|
||||||
this.#renderer.diag(lines);
|
this.#renderer.comment(lines);
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Render a pass TAP output message.
|
/** Render a pass TAP output message.
|
||||||
* @param {string} description
|
* @param {string} description
|
||||||
*/
|
*/
|
||||||
pass(description) {
|
pass(description) {
|
||||||
|
this.passed++;
|
||||||
this.mk_tap('ok', description);
|
this.mk_tap('ok', description);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -117,6 +150,7 @@ class Tap {
|
|||||||
* @param {string} description
|
* @param {string} description
|
||||||
*/
|
*/
|
||||||
fail(description) {
|
fail(description) {
|
||||||
|
this.failed++;
|
||||||
this.mk_tap('not ok', description);
|
this.mk_tap('not ok', description);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -194,7 +228,7 @@ class Tap {
|
|||||||
throws_ok(func, msg) {
|
throws_ok(func, msg) {
|
||||||
var errormsg = ' ';
|
var errormsg = ' ';
|
||||||
if (typeof func != 'function')
|
if (typeof func != 'function')
|
||||||
this.diag('throws_ok needs a function to run');
|
this.comment('throws_ok needs a function to run');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
func();
|
func();
|
||||||
@ -214,7 +248,7 @@ class Tap {
|
|||||||
var errormsg = ' ';
|
var errormsg = ' ';
|
||||||
var msg = false;
|
var msg = false;
|
||||||
if (typeof func != 'function')
|
if (typeof func != 'function')
|
||||||
this.diag('throws_ok needs a function to run');
|
this.comment('throws_ok needs a function to run');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
func();
|
func();
|
||||||
@ -234,7 +268,7 @@ class Tap {
|
|||||||
lives_ok(func, msg) {
|
lives_ok(func, msg) {
|
||||||
var errormsg = true;
|
var errormsg = true;
|
||||||
if (typeof func != 'function')
|
if (typeof func != 'function')
|
||||||
this.diag('throws_ok needs a function to run');
|
this.comment('throws_ok needs a function to run');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
func();
|
func();
|
||||||
@ -259,11 +293,11 @@ class Tap {
|
|||||||
var result = typeof eval('obj.prototype.' + arguments[i]);
|
var result = typeof eval('obj.prototype.' + arguments[i]);
|
||||||
if (result == 'undefined') {
|
if (result == 'undefined') {
|
||||||
pass = false;
|
pass = false;
|
||||||
this.diag('Missing ' + arguments[i] + ' method');
|
this.comment('Missing ' + arguments[i] + ' method');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pass = false;
|
pass = false;
|
||||||
this.diag('Missing ' + arguments[i] + ' method');
|
this.comment('Missing ' + arguments[i] + ' method');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
desc += ' ' + arguments[i];
|
desc += ' ' + arguments[i];
|
||||||
@ -338,51 +372,51 @@ class Tap {
|
|||||||
* @param {function(Tap)} test
|
* @param {function(Tap)} test
|
||||||
*/
|
*/
|
||||||
function runTest(t, testName, test) {
|
function runTest(t, testName, test) {
|
||||||
t.diag('running ' + testName + ' tests');
|
t.comment('running ' + testName + ' tests');
|
||||||
try {
|
try {
|
||||||
test(t);
|
test(t);
|
||||||
if (t.planned > t.counter) {
|
summarize(t);
|
||||||
t.diag('looks like you planned ' + t.planned + ' tests but only ran '
|
|
||||||
+ t.counter + ' tests');
|
|
||||||
} else if (t.planned < t.counter) {
|
|
||||||
t.diag('looks like you planned ' + t.planned + ' tests but ran '
|
|
||||||
+ (t.counter - t.planned) + ' tests extra');
|
|
||||||
}
|
|
||||||
t.diag('ran ' + t.counter + ' tests out of ' + t.planned);
|
|
||||||
t.diag('passed ' + t.passed + ' tests out of ' + t.planned);
|
|
||||||
t.diag('failed ' + t.failed + ' tests out of ' + t.planned);
|
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
t.diag("Test Suite Crashed!!! (" + err + ")");
|
t.comment("Test Suite Crashed!!! (" + err + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs a set of TAP tests defined by a function.
|
* Output a summary of the tests as comments.
|
||||||
* Uses the NodeRenderer for the test output.
|
|
||||||
*
|
*
|
||||||
* @param {string} testName
|
* @param {Tap} t
|
||||||
* @param {function(Tap)} test
|
|
||||||
*/
|
*/
|
||||||
function runNodeTap(testName, test) {
|
function summarize(t) {
|
||||||
var t = Tap.Node();
|
if (t.planned > t.counter) {
|
||||||
return runTest(t, testName, test);
|
t.comment('looks like you planned ' + t.planned + ' tests but only ran '
|
||||||
|
+ t.counter + ' tests');
|
||||||
|
} else if (t.planned < t.counter) {
|
||||||
|
t.comment('looks like you planned ' + t.planned + ' tests but ran '
|
||||||
|
+ (t.counter - t.planned) + ' tests extra');
|
||||||
|
}
|
||||||
|
t.comment('ran ' + t.counter + ' tests out of ' + t.planned);
|
||||||
|
t.comment('passed ' + t.passed + ' tests out of ' + t.planned);
|
||||||
|
t.comment('failed ' + t.failed + ' tests out of ' + t.planned);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs a set of TAP tests defined by a function.
|
* @param {Tap} t
|
||||||
* Uses the Browser renderer for the test output.
|
* @param {Array<{'plan': Number, name: string, 'test': function(Tap)}} suite
|
||||||
*
|
|
||||||
* @param {string} testName
|
|
||||||
* @param {function(Tap)} test
|
|
||||||
*/
|
*/
|
||||||
function runBrowserTap(testName, test) {
|
function runSuite(t, suite) {
|
||||||
var t = Tap.Browser();
|
const plan = suite.reduce((acc, item) => {
|
||||||
return runTest(t, testName, test);
|
return acc + item.plan
|
||||||
|
}, 0);
|
||||||
|
t.plan(plan);
|
||||||
|
for (var item of suite) {
|
||||||
|
t.comment('running ' + item.name + ' tests');
|
||||||
|
item.test(t);
|
||||||
|
}
|
||||||
|
summarize(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(zaphar): The runner interface as well.
|
export { Tap, runTest, runSuite, summarize, BrowserRenderer, NodeRenderer };
|
||||||
export { Tap, runNodeTap, runBrowserTap };
|
|
||||||
|
|
||||||
|
@ -1,103 +0,0 @@
|
|||||||
function load(path) {
|
|
||||||
var url = location.pathname + "#" + encodeURIComponent(path.replace(/^\.\//, ''))
|
|
||||||
Test.TAP.prototype.diag('loading: '+path+' <a href="'+url+'">(run in a single window)</a>...');
|
|
||||||
var req = new XMLHttpRequest();
|
|
||||||
req.open("GET", path, false);
|
|
||||||
req.send(null);
|
|
||||||
if (req.readyState == 4) {
|
|
||||||
var testobj = eval(req.responseText);
|
|
||||||
return testobj;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function createScriptTag(library) {
|
|
||||||
var path = library.replace(/\./g, '/')+'.js';
|
|
||||||
var script = document.createElement("script");
|
|
||||||
script.src = lib+'/'+path;
|
|
||||||
return script;
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadlib(library) {
|
|
||||||
document.body.appendChild(createScriptTag(library));
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadTest(test) {
|
|
||||||
var path = testlib+'/'+test;
|
|
||||||
return load(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadComponents() {
|
|
||||||
for (c in toLoad) {
|
|
||||||
var comp = toLoad[c];
|
|
||||||
loadlib(comp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function runtest(t) {
|
|
||||||
var outtxt = "";
|
|
||||||
var div = document.createElement("div");
|
|
||||||
|
|
||||||
var onclick = function () {
|
|
||||||
var c = div.className;
|
|
||||||
if (c.match(/big/)) {
|
|
||||||
c = c.replace(/big/, "small");
|
|
||||||
} else if (c.match(/small/)) {
|
|
||||||
c = c.replace(/small/, "big");
|
|
||||||
}
|
|
||||||
div.className = c;
|
|
||||||
};
|
|
||||||
div.addEventListener('click', onclick, true);
|
|
||||||
|
|
||||||
div.className = 'test small';
|
|
||||||
document.body.appendChild(div);
|
|
||||||
|
|
||||||
var outfunc = function(text) {
|
|
||||||
if (text) {
|
|
||||||
outtxt += text;
|
|
||||||
if (text.match(/(not ok|Test Suite Crashed)/g) ) {
|
|
||||||
div.innerHTML = "<div class='fail'>" + div.innerHTML + "\n" + text + "</div>"
|
|
||||||
} else {
|
|
||||||
div.innerHTML = "<div class='pass'>" + div.innerHTML + "\n" + text + "</div>"
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// set globally for synchronous run
|
|
||||||
Test.TAP.prototype.out = outfunc;
|
|
||||||
var testobj = loadTest(t);
|
|
||||||
if (!testobj) {
|
|
||||||
alert ("Test Object: "+t+" did not load");
|
|
||||||
throw new ReferenceError("Test Object did now load");
|
|
||||||
}
|
|
||||||
// also set to instance for asynchronous output
|
|
||||||
testobj.out = outfunc
|
|
||||||
|
|
||||||
testobj.on_finished = function () {
|
|
||||||
if (outtxt.match(/(not ok|Test Suite Crashed)/g) ) {
|
|
||||||
div.className += ' failsuite';
|
|
||||||
div.className.replace(/small/, 'big');
|
|
||||||
|
|
||||||
}
|
|
||||||
results.push(div);
|
|
||||||
}
|
|
||||||
|
|
||||||
setTimeout(function () {
|
|
||||||
testobj.run_tests()
|
|
||||||
}, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
var test = loc.match(/.+[#?](.*)\??.*/);
|
|
||||||
|
|
||||||
loadComponents();
|
|
||||||
|
|
||||||
window.onload = function() {
|
|
||||||
var testlist = [];
|
|
||||||
if (test) {
|
|
||||||
runtest(test[1]);
|
|
||||||
} else {
|
|
||||||
for (t in tests) {
|
|
||||||
runtest(tests[t]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -10,7 +10,7 @@ class TapRenderer {
|
|||||||
*
|
*
|
||||||
* @param {Array<string>} lines
|
* @param {Array<string>} lines
|
||||||
*/
|
*/
|
||||||
diag(lines) {
|
comment(lines) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,154 +1,19 @@
|
|||||||
import('../src/TAP.mjs').then(m => {
|
/** @implements TapRenderer */
|
||||||
var runNodeTap = m.runNodeTap;
|
class FakeRenderer {
|
||||||
|
output = "nothing yet";
|
||||||
|
commentOutput = "";
|
||||||
|
|
||||||
function tapSuite(t) {
|
out(text) {
|
||||||
var out = "nothing yet";
|
this.output = text;
|
||||||
var diag = "";
|
|
||||||
t.plan(17);
|
|
||||||
|
|
||||||
var testCan = function () {
|
|
||||||
// setup fake test object
|
|
||||||
var f = new m.Tap(function(newout) { out = newout }); // the TAP thats failing
|
|
||||||
f.out = function(newout) { out = newout };
|
|
||||||
f.diag = function(newdiag) { diag += newdiag };
|
|
||||||
f.plan(4);
|
|
||||||
|
|
||||||
//mock a fake object to run test against
|
|
||||||
var obj = new Object;
|
|
||||||
obj.run = function() {};
|
|
||||||
var method = 'run';
|
|
||||||
|
|
||||||
// begin real tests!
|
|
||||||
f.can_ok(obj, 'not_there');
|
|
||||||
t.like(out, /not ok 1 - object can \[ not_there \]/, 'can_ok failed');
|
|
||||||
f.can_ok(obj, method);
|
|
||||||
diag = '';
|
|
||||||
t.like(out, /ok 2 - object can \[ run \]/, 'can_ok passed');
|
|
||||||
|
|
||||||
//Now we need to test the whole prototype method assignment thing
|
|
||||||
|
|
||||||
function MockObj() {
|
|
||||||
this.attr = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MockObj.prototype.fakeme = function () {};
|
comment(lines) {
|
||||||
|
for (var line of lines) {
|
||||||
f.can_ok(MockObj, 'fakeme');
|
this.commentOutput += line;
|
||||||
diag = '';
|
|
||||||
t.like(out, /^ok .* \[ fakeme \]/,
|
|
||||||
'can_ok recognized prototype methods');
|
|
||||||
f.can_ok(MockObj, 'fakeme2');
|
|
||||||
diag = '';
|
|
||||||
t.like(out, /^not ok .* \[ fakeme2 \]/,
|
|
||||||
'can_ok prototype recognization doesnt break methods');
|
|
||||||
};
|
|
||||||
|
|
||||||
var testLike = function() {
|
|
||||||
// setup fake test object
|
|
||||||
var f = new m.Tap(function(newout) { out = newout }); // the TAP that's failing
|
|
||||||
f.out = function(newout) { out = newout };
|
|
||||||
f.plan(1);
|
|
||||||
|
|
||||||
// begin real tests!
|
|
||||||
f.like("hello", /hello/, "hello matches hello");
|
|
||||||
t.like(out, /ok 1 - hello matches hello/, 'got description in TAP output');
|
|
||||||
};
|
|
||||||
|
|
||||||
var testDiag = function() {
|
|
||||||
// setup fake test object
|
|
||||||
var f = new m.Tap(function(newout) { out = newout }); // the TAP that's failing
|
|
||||||
f.out = function(newout) { out = newout };
|
|
||||||
f.plan(10);
|
|
||||||
// begin real tests!
|
|
||||||
f.diag("hello");
|
|
||||||
t.like(out, /# hello/, 'got hello');
|
|
||||||
};
|
|
||||||
|
|
||||||
var testException = function() {
|
|
||||||
// setup fake test object
|
|
||||||
var f = new m.Tap(function(newout) { out = newout }); // the TAP that's failing
|
|
||||||
f.out = function(newout) { out = newout };
|
|
||||||
f.plan(2);
|
|
||||||
|
|
||||||
// begin real tests!
|
|
||||||
f.throws_ok(function() {throw new Error('I made a boo boo')}, 'I made a boo boo');
|
|
||||||
//t.diag(out);
|
|
||||||
t.like(out, /ok 1 - code threw \[Error: I made a boo boo\]/, 'uncaught exception');
|
|
||||||
f.throws_ok(function() {}, 'I made a boo boo');
|
|
||||||
//t.diag(out);
|
|
||||||
t.like(out, /not ok 2 - code threw \[ \]/, 'false failed');
|
|
||||||
};
|
|
||||||
testException();
|
|
||||||
|
|
||||||
var testFails = function() {
|
|
||||||
// setup fake test object
|
|
||||||
var f = new m.Tap(function(newout) { out = newout }); // the TAP that's failing
|
|
||||||
f.out = function(newout) { out = newout };
|
|
||||||
f.plan(3);
|
|
||||||
|
|
||||||
// begin real tests!
|
|
||||||
f.ok(false, 'false fails');
|
|
||||||
t.like(out, /not ok 1 - false fails/, 'false failed');
|
|
||||||
|
|
||||||
f.ok(0, 'zero fails');
|
|
||||||
t.like(out, /not ok 2 - zero fails/, '0 failed');
|
|
||||||
|
|
||||||
f.is(0, 1, 'zero is one');
|
|
||||||
t.like(out, /not ok 3 - zero is one/, '0 != 1');
|
|
||||||
};
|
|
||||||
testFails();
|
|
||||||
|
|
||||||
var testPass = function() {
|
|
||||||
t.ok(true, 'true is true');
|
|
||||||
t.is(1,1, '1 is 1');
|
|
||||||
t.pass('pass passes');
|
|
||||||
t.like("hello world", /hel+o/, 'regexen work');
|
|
||||||
t.unlike("hello there", /world/, 'no world');
|
|
||||||
};
|
|
||||||
testPass();
|
|
||||||
|
|
||||||
var testPlan = function() {
|
|
||||||
// setup fake test object
|
|
||||||
var f = new m.Tap(function(newout) { out = newout }); // the TAP that's failing
|
|
||||||
f.out = function(newout) { out = newout };
|
|
||||||
f.plan(2);
|
|
||||||
|
|
||||||
// begin real tests!
|
|
||||||
f.ok(false, 'false fails');
|
|
||||||
t.is(f.counter, 1, 'counter increments by one');
|
|
||||||
t.is(f.planned, 2, 'planned = 2');
|
|
||||||
};
|
|
||||||
testPlan();
|
|
||||||
|
|
||||||
var testTodoSkip = function() {
|
|
||||||
var out;
|
|
||||||
t.can_ok(m.Tap, 'todo', 'skip');
|
|
||||||
var f = new m.Tap(); // the TAP that's failing
|
|
||||||
f.out = function(newout) { out = newout };
|
|
||||||
f.plan(4);
|
|
||||||
|
|
||||||
f.todo(function() {
|
|
||||||
f.ok(true, 'true is true');
|
|
||||||
});
|
|
||||||
t.like(out, /ok 1 - # TODO: true is true/g,
|
|
||||||
'the non todo output is suitably formatted');
|
|
||||||
f.ok(!false, 'not false is true');
|
|
||||||
t.like(out, /ok 2 -/g, 'the regular output is suitably formatted');
|
|
||||||
|
|
||||||
f.skip(true, 'because I said so', 1,
|
|
||||||
function() {
|
|
||||||
f.is(1, 2, 'one is two');
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
t.like(out, /^not ok 3 - # SKIP because I said so$/,
|
|
||||||
'the skipped output is suitably formatted');
|
|
||||||
f.is(1, 1, 'one is one');
|
|
||||||
t.like(out, /ok 4 - one is one/,
|
|
||||||
'the non skipped output is suitable formatted');
|
|
||||||
};
|
|
||||||
testTodoSkip();
|
|
||||||
|
|
||||||
return t;
|
|
||||||
}
|
}
|
||||||
runNodeTap("Tap dogfood test suite", tapSuite);
|
}
|
||||||
|
|
||||||
|
import('./suite.mjs').then(m => {
|
||||||
|
m.runTest(m.Tap.Node(), "Tap dogfood test suite", m.tapSuite);
|
||||||
});
|
});
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
<html>
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<script type="text/javascript" src="../lib/Test/TAP.js"></script>
|
|
||||||
<script type="text/javascript" src="../lib/Test/TAP/Runner.js"></script>
|
|
||||||
<script type="text/javascript" src="../lib/Test/TAP/Class.js"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
@ -30,26 +25,19 @@
|
|||||||
|
|
||||||
</style>
|
</style>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var top = this;
|
|
||||||
/** Configuration options
|
/** Configuration options
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
var tests = [
|
var tests = [
|
||||||
'01_tap.t.js',
|
'01_tap.t.js',
|
||||||
];
|
];
|
||||||
var testlib = '.';
|
|
||||||
|
|
||||||
/** Setup
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
</script>
|
</script>
|
||||||
This is the Test.TAP.Class and company test harness for the browser.
|
This is the Tap test harness for the browser.
|
||||||
<script type="text/javascript" src="../lib/Test/TAPBrowser.js"></script>
|
<script type="module">
|
||||||
<script type="text/javascript">
|
import { Tap, runTest } from '../src/TAP.mjs';
|
||||||
window.onload = function() {
|
import { tapSuite } from './suite.mjs';
|
||||||
var browser = new Test.TAPBrowser(testlib, tests);
|
|
||||||
browser.run();
|
runTest(Tap.Browser(), 'Tap Dogfood Tests', tapSuite);
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
162
tests/suite.mjs
Normal file
162
tests/suite.mjs
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
/** @implements TapRenderer */
|
||||||
|
import {Tap, runTest} from '../src/TAP.mjs';
|
||||||
|
|
||||||
|
class FakeRenderer {
|
||||||
|
output = "nothing yet";
|
||||||
|
commentOutput = "";
|
||||||
|
|
||||||
|
out(text) {
|
||||||
|
this.output = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
comment(lines) {
|
||||||
|
for (var line of lines) {
|
||||||
|
this.commentOutput += line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function tapSuite(t) {
|
||||||
|
t.plan(23);
|
||||||
|
|
||||||
|
var renderer = new FakeRenderer();
|
||||||
|
var testCan = function() {
|
||||||
|
// setup fake test object
|
||||||
|
var f = new Tap(renderer); // the TAP thats failing
|
||||||
|
f.plan(4);
|
||||||
|
|
||||||
|
//mock a fake object to run test against
|
||||||
|
var obj = new Object;
|
||||||
|
obj.run = function() { };
|
||||||
|
var method = 'run';
|
||||||
|
|
||||||
|
// begin real tests!
|
||||||
|
f.can_ok(obj, 'not_there');
|
||||||
|
t.like(renderer.output, /not ok 1 - object can \[ not_there \]/, 'can_ok failed');
|
||||||
|
f.can_ok(obj, method);
|
||||||
|
t.like(renderer.output, /ok 2 - object can \[ run \]/, 'can_ok passed');
|
||||||
|
|
||||||
|
//Now we need to test the whole prototype method assignment thing
|
||||||
|
|
||||||
|
function MockObj() {
|
||||||
|
this.attr = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
MockObj.prototype.fakeme = function() { };
|
||||||
|
|
||||||
|
f.can_ok(MockObj, 'fakeme');
|
||||||
|
renderer.commentOutput = '';
|
||||||
|
t.like(renderer.output, /^ok .* \[ fakeme \]/,
|
||||||
|
'can_ok recognized prototype methods');
|
||||||
|
f.can_ok(MockObj, 'fakeme2');
|
||||||
|
renderer.commentOutput = '';
|
||||||
|
t.like(renderer.output, /^not ok .* \[ fakeme2 \]/,
|
||||||
|
'can_ok prototype recognization doesnt break methods');
|
||||||
|
};
|
||||||
|
testCan();
|
||||||
|
|
||||||
|
var testLike = function() {
|
||||||
|
// setup fake test object
|
||||||
|
var f = new Tap(renderer); // the TAP that's failing
|
||||||
|
f.plan(1);
|
||||||
|
|
||||||
|
// begin real tests!
|
||||||
|
f.like("hello", /hello/, "hello matches hello");
|
||||||
|
t.like(renderer.output, /ok 1 - hello matches hello/, 'got description in TAP output');
|
||||||
|
};
|
||||||
|
testLike()
|
||||||
|
|
||||||
|
var testDiag = function() {
|
||||||
|
// setup fake test object
|
||||||
|
var f = new Tap(renderer); // the TAP that's failing
|
||||||
|
f.plan(10);
|
||||||
|
// begin real tests!
|
||||||
|
f.comment("hello");
|
||||||
|
t.comment(renderer.commentOutput);
|
||||||
|
t.like(renderer.commentOutput, /hello/, 'got hello');
|
||||||
|
};
|
||||||
|
testDiag();
|
||||||
|
|
||||||
|
var testException = function() {
|
||||||
|
// setup fake test object
|
||||||
|
var f = new Tap(renderer); // the TAP that's failing
|
||||||
|
f.plan(2);
|
||||||
|
|
||||||
|
// begin real tests!
|
||||||
|
f.throws_ok(function() { throw new Error('I made a boo boo') }, 'I made a boo boo');
|
||||||
|
//t.comment(renderer.output);
|
||||||
|
t.like(renderer.output, /ok 1 - code threw \[Error: I made a boo boo\]/, 'uncaught exception');
|
||||||
|
f.throws_ok(function() { }, 'I made a boo boo');
|
||||||
|
//t.comment(renderer.output);
|
||||||
|
t.like(renderer.output, /not ok 2 - code threw \[ \]/, 'false failed');
|
||||||
|
};
|
||||||
|
testException();
|
||||||
|
|
||||||
|
var testFails = function() {
|
||||||
|
// setup fake test object
|
||||||
|
var f = new Tap(renderer); // the TAP that's failing
|
||||||
|
f.plan(3);
|
||||||
|
|
||||||
|
// begin real tests!
|
||||||
|
f.ok(false, 'false fails');
|
||||||
|
t.like(renderer.output, /not ok 1 - false fails/, 'false failed');
|
||||||
|
|
||||||
|
f.ok(0, 'zero fails');
|
||||||
|
t.like(renderer.output, /not ok 2 - zero fails/, '0 failed');
|
||||||
|
|
||||||
|
f.is(0, 1, 'zero is one');
|
||||||
|
t.like(renderer.output, /not ok 3 - zero is one/, '0 != 1');
|
||||||
|
};
|
||||||
|
testFails();
|
||||||
|
|
||||||
|
var testPass = function() {
|
||||||
|
t.ok(true, 'true is true');
|
||||||
|
t.is(1, 1, '1 is 1');
|
||||||
|
t.pass('pass passes');
|
||||||
|
t.like("hello world", /hel+o/, 'regexen work');
|
||||||
|
t.unlike("hello there", /world/, 'no world');
|
||||||
|
};
|
||||||
|
testPass();
|
||||||
|
|
||||||
|
var testPlan = function() {
|
||||||
|
// setup fake test object
|
||||||
|
var f = new Tap(renderer); // the TAP that's failing
|
||||||
|
f.plan(2);
|
||||||
|
|
||||||
|
// begin real tests!
|
||||||
|
f.ok(false, 'false fails');
|
||||||
|
t.is(f.counter, 1, 'counter increments by one');
|
||||||
|
t.is(f.planned, 2, 'planned = 2');
|
||||||
|
};
|
||||||
|
testPlan();
|
||||||
|
|
||||||
|
var testTodoSkip = function() {
|
||||||
|
t.can_ok(Tap, 'todo', 'skip');
|
||||||
|
var f = new Tap(renderer); // the TAP that's failing
|
||||||
|
f.plan(4);
|
||||||
|
|
||||||
|
f.todo(function() {
|
||||||
|
f.ok(true, 'true is true');
|
||||||
|
});
|
||||||
|
t.like(renderer.output, /ok 1 - # TODO: true is true/g,
|
||||||
|
'the non todo output is suitably formatted');
|
||||||
|
f.ok(!false, 'not false is true');
|
||||||
|
t.like(renderer.output, /ok 2 -/g, 'the regular output is suitably formatted');
|
||||||
|
|
||||||
|
f.skip(true, 'because I said so', 1,
|
||||||
|
function() {
|
||||||
|
f.is(1, 2, 'one is two');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
t.like(renderer.output, /^not ok 3 - # SKIP because I said so$/,
|
||||||
|
'the skipped output is suitably formatted');
|
||||||
|
f.is(1, 1, 'one is one');
|
||||||
|
t.like(renderer.output, /ok 4 - one is one/,
|
||||||
|
'the non skipped output is suitable formatted');
|
||||||
|
};
|
||||||
|
testTodoSkip();
|
||||||
|
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { tapSuite, runTest, Tap };
|
@ -1,51 +0,0 @@
|
|||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
||||||
|
|
||||||
<script type="text/javascript" src="../ext/Test/TAP.js"></script>
|
|
||||||
<script type="text/javascript" src="../ext/Test/TAP/Class.js"></script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<style type="text/css">
|
|
||||||
.test {
|
|
||||||
margin-top : 10px;
|
|
||||||
margin-bottom : 10px;
|
|
||||||
border : 3px;
|
|
||||||
border-style : inset;
|
|
||||||
overflow : auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.small {
|
|
||||||
height : 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.big {
|
|
||||||
height : 600px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.fail { background-color : red; }
|
|
||||||
.pass { background-color : green; }
|
|
||||||
.failsuite {border: 3px solid red;}
|
|
||||||
</style>
|
|
||||||
<!--Test Description here -->
|
|
||||||
<script type="text/javascript">
|
|
||||||
var top = this;
|
|
||||||
/** Configuration options
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
var tests = [
|
|
||||||
'<list test files here>',
|
|
||||||
];
|
|
||||||
// Change this to the path of your test scripts
|
|
||||||
var testlib = '.';
|
|
||||||
|
|
||||||
/** Setup
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
var loc = String(top.location);
|
|
||||||
var results = [];
|
|
||||||
</script>
|
|
||||||
<script type="text/javascript" src="../ext/Test/TAPBrowser.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
rhino harness/rhino_harness.js
|
|
@ -1,35 +0,0 @@
|
|||||||
var libpath = 'lib';
|
|
||||||
var extpath = 'ext';
|
|
||||||
var testpath = 't';
|
|
||||||
|
|
||||||
var extlibs = [
|
|
||||||
'Test/TAP.js',
|
|
||||||
'Test/TAP/Class.js',
|
|
||||||
'Test/TAP/Runner.js',
|
|
||||||
'joose.js'
|
|
||||||
];
|
|
||||||
|
|
||||||
var libs = [
|
|
||||||
'<list external libs here>'
|
|
||||||
];
|
|
||||||
|
|
||||||
var tests = [
|
|
||||||
'<list test files here>',
|
|
||||||
];
|
|
||||||
|
|
||||||
for (i in extlibs) {
|
|
||||||
var lib = extlibs[i];
|
|
||||||
load(extpath+'/'+lib);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i in libs) {
|
|
||||||
var lib = libs[i];
|
|
||||||
load(libpath+'/'+lib);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i in tests) {
|
|
||||||
var test = tests[i];
|
|
||||||
var script = readFile(testpath+'/'+test);
|
|
||||||
t = eval(script);
|
|
||||||
t.run_tests();
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user