File Coverage

lib/JS/Test/Simple.pm
Criterion Covered Total %
statement 3 3 100.0
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 4 4 100.0


line stmt bran cond sub pod time code
1             package JS::Test::Simple;
2              
3 1     1   27126 use 5.006;
  1         4  
  1         94  
4              
5             our $VERSION = '0.29';
6              
7             1;
8              
9             =encoding utf8
10              
11             =head1 Name
12              
13             Test.Simple - Basic utilities for writing JavaScript tests.
14              
15             =head1 Synopsis
16              
17            
21              
22             =head1 Description
23              
24             This is an extremely simple, extremely basic module for writing tests suitable
25             for JavaScript classes and other pursuits. If you wish to do more complicated
26             testing, use Test.More (a drop-in replacement for this one).
27              
28             The basic unit of testing is the ok. For each thing you want to test your
29             program will print out an "ok" or "not ok" to indicate pass or fail. You do
30             this with the ok() function (see below).
31              
32             The only other constraint is that you must pre-declare how many tests you
33             plan to run. This is in case something goes horribly wrong during the test and
34             your test program aborts, or skips a test or whatever. You do this like so:
35              
36            
39              
40             You B have a plan.
41              
42             =over
43              
44             =item B
45              
46             ok( foo == bar, description );
47             ok( foo == bar );
48              
49             ok() is given an expression (in this case C). If it's true, the
50             test passed. If it's false, it didn't. That's about it.
51              
52             ok() prints out either "ok" or "not ok" along with a test number (it keeps
53             track of that for you).
54              
55             // This produces "ok 1 - Hell not yet frozen over" (or not ok)
56             ok( getTemperature(hell) > 0, 'Hell not yet frozen over' );
57              
58             If you provide a C, that will be printed along with the "ok/not
59             ok" to make it easier to find your test when if fails (just search for the
60             name). It also makes it easier for the next guy to understand what your test
61             is for. It's highly recommended you use test names.
62              
63             =back
64              
65             Test.Simple will start by printing number of tests run in the form "1..M" (so
66             "1..5" means you're going to run 5 tests). This strange format lets
67             Test.Harness know how many tests you plan on running in case something goes
68             horribly wrong.
69              
70             If all your tests passed, Test.Simple will exit with zero (which is normal). If
71             anything failed it will exit with how many failed. If you run less (or more)
72             tests than you planned, the missing (or extras) will be considered failures.
73             If no tests were ever run, Test.Simple will throw a warning and exit with 255.
74             If the test died, even after having successfully completed all its tests, it
75             will still be considered a failure and will exit with 255.
76              
77             This module is by no means trying to be a complete testing system. It's just
78             to get you started. Once you're off the ground, we recommended that you look
79             at L.
80              
81             =head1 Example
82              
83             Here's an example of a simple test file for the fictional JavaScript Film
84             class:
85              
86            
87            
88            
89            
90            
91            
92            
104            
105              
106             It will produce output like this:
107              
108             1..5
109             ok 1 - Constructor works
110             ok 2 - title() get
111             ok 3 - director() get
112             not ok 4 - rating() get
113             # Failed test (t/film.html at line 14)
114             ok 5 - numExplodingSheep() get
115             # Looks like you failed 1 tests of 5
116              
117             Indicating that the C method is broken.
118              
119             =head1 History
120              
121             This module was conceived by Michael Schwern while talking with Tony Bowden in
122             his kitchen one night about the problems he was having writing some really
123             complicated feature into the new Testing module. Tony observed that the main
124             problem is not dealing with these edge cases but that people hate to write
125             tests B. What was needed was a dead simple module that took all the
126             hard work out of testing and was really, really easy to learn. Paul Johnson
127             simultaneously had this idea (unfortunately, he wasn't in Tony's kitchen).
128             This is it...ported to JavaScript.
129              
130             =head1 See Also
131              
132             =over
133              
134             =item L
135              
136             More testing functions! Once you outgrow Test.Simple, look at Test.More.
137             Test.Simple is 100% forward compatible with Test.More (i.e. you can just use
138             Test.More instead of Test.Simple in your programs and things will still work).
139              
140             =begin _unimplemented
141              
142             =item L
143              
144             Interprets the output of your test program.
145              
146             =end _unimplemented
147              
148             =item L
149              
150             JSUnit: elaborate xUnit-style testing framework.
151              
152             =back
153              
154             =head1 Authors
155              
156             Idea by Tony Bowden and Paul Johnson. Original Perl implementation by Michael
157             G Schwern . JavaScript implementation by David Wheeler
158             . JavaScript implementation packaged for CPAN by Ingy
159             döt Net . Wardrobe by Calvin Klein.
160              
161             =head1 Copyright
162              
163             Copyright 2001, 2002, 2004 by Michael G Schwern , 2005,
164             2008 by David Wheeler.
165              
166             This program is free software; you can redistribute it and/or modify it under
167             the terms of the Perl Artistic License or the GNU GPL.
168              
169             See L and
170             L.
171              
172             =cut