Imported Upstream version 1.21
This commit is contained in:
commit
8879c156fb
389
ChangeLog
Normal file
389
ChangeLog
Normal file
@ -0,0 +1,389 @@
|
||||
2003-01-15 13:48 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* t/15_setupteardown.t (1.4):
|
||||
|
||||
- Added/refined tests to match refined setup/teardown behaviour.
|
||||
|
||||
2003-01-15 13:47 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* Makefile.PL (1.5):
|
||||
|
||||
- Converted to use ExtUtils::AutoInstall.
|
||||
|
||||
2003-01-15 13:46 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* t/: 05_importTestData.t (1.1), 12_testdata.t (1.1):
|
||||
|
||||
Initial commit.
|
||||
|
||||
2003-01-15 12:58 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* lib/Test/SimpleUnit.pm (1.21):
|
||||
|
||||
- Removed leftover conflict section.
|
||||
|
||||
2003-01-15 12:48 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* lib/Test/SimpleUnit.pm (1.20):
|
||||
|
||||
- Added 'AutoskipFailedTeardown' global and accessors.
|
||||
|
||||
- Added loadTestData() and saveTestData() functions and ':testdata' export flag
|
||||
|
||||
- Modified comparison assertions to use Data::Compare.
|
||||
|
||||
- Added functions/data to allow modification of output handle.
|
||||
|
||||
- Generalized assertion-bookkeeping into functions.
|
||||
|
||||
- Handled undefined values more cleanly in assertion messages.
|
||||
|
||||
- Added ability to stack setup/teardown functions for one-time setup or
|
||||
teardowns.
|
||||
|
||||
2002-06-24 16:28 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* t/: 05_asserts.t (1.5), 06_skips.t (1.4), 07_setupteardown.t
|
||||
(1.4), 08_emptysuite.t (1.2), 09_bugs.t (1.2):
|
||||
|
||||
'Updated'
|
||||
|
||||
2002-05-14 17:39 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* lib/Test/SimpleUnit.pm (1.19):
|
||||
|
||||
- Cleaned up handling of undef values in default error messages for
|
||||
assertKindOf() and assertInstanceOf().
|
||||
|
||||
2002-05-13 21:02 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* Makefile.PL (1.4, RELEASE_1_18):
|
||||
|
||||
- Added some dependencies to the require list.
|
||||
|
||||
2002-05-13 21:01 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* lib/Test/SimpleUnit.pm (1.18, RELEASE_1_18):
|
||||
|
||||
- Added functions/package variables to support switching the test output IO
|
||||
handle to something different for the purposes of self-testing.
|
||||
|
||||
- Modified assertion counter code to support recursive calls to runTests().
|
||||
|
||||
2002-05-13 20:59 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* t/: 09_bugs.t (1.1), 30_bugs.t (1.1) (utags: RELEASE_1_18):
|
||||
|
||||
- Initial commit.
|
||||
|
||||
2002-04-25 14:53 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* t/: 07_setupteardown.t (1.3), 15_setupteardown.t (1.3) (utags:
|
||||
RELEASE_1_18, RELEASE_1_17):
|
||||
|
||||
- Modified to test the setup/teardown superseding rules.
|
||||
|
||||
2002-04-25 14:52 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* README (1.4, RELEASE_1_18, RELEASE_1_17):
|
||||
|
||||
- Cleaned up to reflect the changes made to the module.
|
||||
|
||||
- Clarified meaning of parts, added better example, etc.
|
||||
|
||||
- Removed references to XUnit, as this isn't exactly an XUnit-type framework.
|
||||
|
||||
2002-04-25 14:50 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* lib/Test/SimpleUnit.pm (1.17, RELEASE_1_17):
|
||||
|
||||
- Cleaned up and corrected documentation.
|
||||
|
||||
- Separated example code from synopsis
|
||||
|
||||
- Added beginnings of debugging code
|
||||
|
||||
- Modified setup/teardown to use superseding rule instead of additive rules.
|
||||
|
||||
2002-04-23 16:04 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* lib/Test/SimpleUnit.pm (1.16, RELEASE_1_16):
|
||||
|
||||
- Split up somewhat into functions.
|
||||
|
||||
- Fixed bug that surfaced when running an empty test suite, or a suite with only
|
||||
'setup' and 'teardown' tests.
|
||||
|
||||
- Fixed error reporting: now failures are reported for TEST_VERBOSE=1 as well as
|
||||
VERBOSE=1.
|
||||
|
||||
2002-04-23 16:01 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* t/: 08_emptysuite.t (1.1), 20_emptysuite.t (1.1) (utags:
|
||||
RELEASE_1_18, RELEASE_1_17, RELEASE_1_16):
|
||||
|
||||
Initial commit.
|
||||
|
||||
2002-04-22 16:15 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* lib/Test/SimpleUnit.pm (1.15, RELEASE_1_15):
|
||||
|
||||
- Fixed some X<> POD constructs that should have been L<> ones.
|
||||
|
||||
2002-04-22 16:14 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* README (1.3, RELEASE_1_16, RELEASE_1_15):
|
||||
|
||||
- Added longer description.
|
||||
|
||||
2002-04-15 13:54 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* t/: 06_skips.t (1.3), 11_skips.t (1.3) (utags: RELEASE_1_18,
|
||||
RELEASE_1_15, RELEASE_1_14, RELEASE_1_17, RELEASE_1_16):
|
||||
|
||||
- Added 'AutoskipFailedSetup' tests.
|
||||
|
||||
2002-04-15 13:54 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* lib/Test/SimpleUnit.pm (1.14, RELEASE_1_14):
|
||||
|
||||
- Updated, added documentation
|
||||
|
||||
- Changed AutoskipFailedSetup to a function, as it was rather incongruous as a
|
||||
method. The method style stills works, but it's deprecated.
|
||||
|
||||
- Added code to allow 'setup' and 'teardown' cases to specify their coderefs
|
||||
with a 'func' key rather than 'test' for clarity.
|
||||
|
||||
2002-04-08 12:57 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* README (1.2, RELEASE_1_14, RELEASE_1_13):
|
||||
|
||||
- De-tabified.
|
||||
|
||||
2002-04-08 12:52 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* README (1.1):
|
||||
|
||||
Initial commit.
|
||||
|
||||
2002-04-08 12:50 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* t/: 05_asserts.t (1.4), 10_asserts.t (1.4) (utags: RELEASE_1_18,
|
||||
RELEASE_1_15, RELEASE_1_14, RELEASE_1_17, RELEASE_1_16,
|
||||
RELEASE_1_13):
|
||||
|
||||
- Modified error messages to reflect changes in assert().
|
||||
|
||||
2002-04-08 12:47 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* lib/Test/SimpleUnit.pm (1.13, RELEASE_1_13):
|
||||
|
||||
- Modified to pass "\n" as the last arg to die to remove the irrelevant 'at
|
||||
line...' message. When I have more time, I should add code to backtrace
|
||||
through caller() and get a useful equivalent.
|
||||
|
||||
- Look for $ENV{TEST_VERBOSE}, too.
|
||||
|
||||
2002-03-29 16:45 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* Makefile.PL (1.3, RELEASE_1_17, RELEASE_1_16, RELEASE_1_15,
|
||||
RELEASE_1_14, RELEASE_1_13, RELEASE_1_12):
|
||||
|
||||
- Fixed ci/tag target
|
||||
|
||||
2002-03-29 16:41 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* Makefile.PL (1.2), lib/Test/SimpleUnit.pm (1.12, RELEASE_1_12),
|
||||
t/00_require.t (1.2, RELEASE_1_18, RELEASE_1_17, RELEASE_1_16,
|
||||
RELEASE_1_15, RELEASE_1_14, RELEASE_1_13, RELEASE_1_12),
|
||||
t/01_importAll.t (1.2, RELEASE_1_18, RELEASE_1_17, RELEASE_1_16,
|
||||
RELEASE_1_15, RELEASE_1_14, RELEASE_1_13, RELEASE_1_12),
|
||||
t/02_importAsserts.t (1.3, RELEASE_1_18, RELEASE_1_17,
|
||||
RELEASE_1_16, RELEASE_1_15, RELEASE_1_14, RELEASE_1_13,
|
||||
RELEASE_1_12), t/03_importTfuncs.t (1.2, RELEASE_1_18,
|
||||
RELEASE_1_17, RELEASE_1_16, RELEASE_1_15, RELEASE_1_14,
|
||||
RELEASE_1_13, RELEASE_1_12), t/04_importSkips.t (1.2, RELEASE_1_18,
|
||||
RELEASE_1_17, RELEASE_1_16, RELEASE_1_15, RELEASE_1_14,
|
||||
RELEASE_1_13, RELEASE_1_12), t/05_asserts.t (1.3, RELEASE_1_12),
|
||||
t/06_skips.t (1.2, RELEASE_1_13, RELEASE_1_12),
|
||||
t/07_setupteardown.t (1.2, RELEASE_1_16, RELEASE_1_15,
|
||||
RELEASE_1_14, RELEASE_1_13, RELEASE_1_12), t/10_asserts.t (1.3,
|
||||
RELEASE_1_12), t/11_skips.t (1.2, RELEASE_1_13, RELEASE_1_12),
|
||||
t/15_setupteardown.t (1.2, RELEASE_1_16, RELEASE_1_15,
|
||||
RELEASE_1_14, RELEASE_1_13, RELEASE_1_12):
|
||||
|
||||
- Renamed to Test::SimpleUnit
|
||||
|
||||
2002-03-29 15:59 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* TestFramework.pm (1.12):
|
||||
|
||||
Renamed and moved into lib/Test
|
||||
|
||||
2002-03-28 14:01 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* TestFramework.pm (1.11, RELEASE_1_11), lib/Test/SimpleUnit.pm
|
||||
(1.11):
|
||||
|
||||
- Fixed copyright.
|
||||
|
||||
2002-03-28 13:59 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* TestFramework.pm (1.10), lib/Test/SimpleUnit.pm (1.10):
|
||||
|
||||
- assertExceptionMatches(): New assertion function.
|
||||
|
||||
- assertExceptionType(): New assertion function.
|
||||
|
||||
- assertKindOf(): New assertion function.
|
||||
|
||||
- Corrected skip handling for setup/teardown.
|
||||
|
||||
- Added handler for 'skipAll' to setup/teardown.
|
||||
|
||||
2002-03-28 12:00 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* t/: 05_asserts.t (1.2), 10_asserts.t (1.2) (utags: RELEASE_1_11):
|
||||
|
||||
- Added tests for assertExceptionType() and assertExceptionMatch().
|
||||
|
||||
- Simplified some of the other tests with new asserts.
|
||||
|
||||
2002-03-22 18:21 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* t/: 07_setupteardown.t (1.1), 15_setupteardown.t (1.1) (utags:
|
||||
RELEASE_1_11, RELEASE_1_09):
|
||||
|
||||
First commit.
|
||||
|
||||
2002-03-22 18:20 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* TestFramework.pm (1.9, RELEASE_1_09), lib/Test/SimpleUnit.pm
|
||||
(1.9):
|
||||
|
||||
- Added 'setup' and 'teardown' test handling to facilitate XUnit-style pre- and post-test functions. This feature still needs documenting.
|
||||
|
||||
- AutoskipFailedSetup(): New method to automatically skip any tests in a test case after a 'setup' test has failed.
|
||||
|
||||
2002-03-21 18:30 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* t/: 04_importSkips.t (1.1, RELEASE_1_11), 05_asserts.t (1.1),
|
||||
06_skips.t (1.1, RELEASE_1_11), 10_asserts.t (1.1), 11_skips.t
|
||||
(1.1, RELEASE_1_11) (utags: RELEASE_1_09):
|
||||
|
||||
Initial commit.
|
||||
|
||||
2002-03-21 18:30 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* t/04_asserts.t (1.3):
|
||||
|
||||
- Renamed to 05_asserts.t to make room for the skip-import tests.
|
||||
|
||||
2002-03-21 18:27 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* TestFramework.pm (1.8), lib/Test/SimpleUnit.pm (1.8):
|
||||
|
||||
- fail: New function
|
||||
|
||||
- skipOne: New function
|
||||
|
||||
- skipAll: New function
|
||||
|
||||
- Fixed up some warnings that showed up when using assertUndef() and assertNot()
|
||||
with undefined values and no message.
|
||||
|
||||
2002-03-05 15:47 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* t/04_asserts.t (1.2):
|
||||
|
||||
- Modified import tag to reflect name change from 'assertFunctions' to
|
||||
'asserts'.
|
||||
|
||||
- Added tests for new assertions 'assertDefined' and 'assertUndef'.
|
||||
|
||||
2002-03-05 15:46 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* t/02_importAsserts.t (1.2, RELEASE_1_11, RELEASE_1_09):
|
||||
|
||||
- Modified import tag to reflect name change from 'assertFunctions' to
|
||||
'asserts'.
|
||||
|
||||
2002-03-05 15:46 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* TestFramework.pm (1.7), lib/Test/SimpleUnit.pm (1.7):
|
||||
|
||||
- Changed the name of the assertion exporter tag to 'asserts'; an
|
||||
'assertFunctions' tag remains for backwards-compatibility, but may be
|
||||
deprecated in the future.
|
||||
|
||||
- Added 'assertUndef' assertion
|
||||
|
||||
- Added 'assertDefined' assertion
|
||||
|
||||
2001-11-28 13:13 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* TestFramework.pm (1.6), lib/Test/SimpleUnit.pm (1.6):
|
||||
|
||||
- Update documentation.
|
||||
|
||||
2001-10-29 12:43 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* t/04_asserts.t (1.1):
|
||||
|
||||
First release.
|
||||
|
||||
2001-10-29 12:43 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* TestFramework.pm (1.5), lib/Test/SimpleUnit.pm (1.5):
|
||||
|
||||
- Cleaned up a bunch of places where an undefined value in an assertion value
|
||||
was not handled gracefully. There are probably more somewhere.
|
||||
|
||||
- Added two more assertion functions: assertMatches() and assertNotRef().
|
||||
|
||||
- Moved the scalar test out of assertRef() and into the new assertNotRef().
|
||||
|
||||
- Made the error message for assertInstanceOf() a bit more accurate.
|
||||
|
||||
2001-09-08 23:12 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* TestFramework.pm (1.4), lib/Test/SimpleUnit.pm (1.4):
|
||||
|
||||
- Fixed POD escape thingies in the docs.
|
||||
|
||||
2001-09-08 23:10 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* TestFramework.pm (1.3), lib/Test/SimpleUnit.pm (1.3):
|
||||
|
||||
- Fixed auto-generated docs, as the moduletool parser apparently doesn't like
|
||||
code sample indent stuff.
|
||||
|
||||
2001-08-03 16:35 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* TestFramework.pm (1.2), lib/Test/SimpleUnit.pm (1.2):
|
||||
|
||||
- Fixed and added more documentation
|
||||
|
||||
- Added true return value at module end
|
||||
|
||||
2001-08-03 15:55 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* Makefile.PL (1.1.1.1, RELEASE_1_11, RELEASE_1_09, RELEASE_1_1),
|
||||
TestFramework.pm (1.1.1.1, RELEASE_1_1), lib/Test/SimpleUnit.pm
|
||||
(1.1.1.1), t/00_require.t (1.1.1.1, RELEASE_1_11, RELEASE_1_09,
|
||||
RELEASE_1_1), t/01_importAll.t (1.1.1.1, RELEASE_1_11,
|
||||
RELEASE_1_09, RELEASE_1_1), t/02_importAsserts.t (1.1.1.1,
|
||||
RELEASE_1_1), t/03_importTfuncs.t (1.1.1.1, RELEASE_1_11,
|
||||
RELEASE_1_09, RELEASE_1_1):
|
||||
|
||||
Initial release.
|
||||
|
||||
2001-08-03 15:55 Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
* Makefile.PL (1.1), TestFramework.pm (1.1), lib/Test/SimpleUnit.pm
|
||||
(1.1), t/00_require.t (1.1), t/01_importAll.t (1.1),
|
||||
t/02_importAsserts.t (1.1), t/03_importTfuncs.t (1.1):
|
||||
|
||||
Initial revision
|
||||
|
17
MANIFEST
Normal file
17
MANIFEST
Normal file
@ -0,0 +1,17 @@
|
||||
ChangeLog
|
||||
MANIFEST
|
||||
Makefile.PL
|
||||
README
|
||||
lib/Test/SimpleUnit.pm
|
||||
t/00_require.t
|
||||
t/01_importAll.t
|
||||
t/02_importAsserts.t
|
||||
t/03_importTfuncs.t
|
||||
t/04_importSkips.t
|
||||
t/05_importTestData.t
|
||||
t/10_asserts.t
|
||||
t/11_skips.t
|
||||
t/12_testdata.t
|
||||
t/15_setupteardown.t
|
||||
t/20_emptysuite.t
|
||||
t/30_bugs.t
|
66
Makefile.PL
Normal file
66
Makefile.PL
Normal file
@ -0,0 +1,66 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Perl Makefile for Test::SimpleUnit
|
||||
# $Id: Makefile.PL,v 1.5 2003/01/15 20:47:17 deveiant Exp $
|
||||
#
|
||||
# Invocation:
|
||||
# $ perl Makefile.PL # interactive behaviour
|
||||
# $ perl Makefile.PL --defaultdeps # accept default value on prompts
|
||||
# $ perl Makefile.PL --checkdeps # check only, no Makefile produced
|
||||
# $ perl Makefile.PL --skipdeps # ignores all dependencies
|
||||
# $ perl Makefile.PL --testonly # don't write installation targets
|
||||
#
|
||||
# Then, to build:
|
||||
# $ make [all|test|install] # install dependencies first
|
||||
# $ make checkdeps # same as the --checkdeps above
|
||||
# $ make installdeps # install dependencies only
|
||||
#
|
||||
|
||||
# ExtUtils::AutoInstall Bootstrap Code, version 5.
|
||||
BEGIN{my$p='ExtUtils::AutoInstall';my$v=0.40;eval"use $p $v;1
|
||||
"or do{my$e=$ENV{PERL_EXTUTILS_AUTOINSTALL};(!defined($e)||$e
|
||||
!~m/--(?:default|skip|testonly)/and-t STDIN or eval"use Ext".
|
||||
"Utils::MakeMaker;WriteMakefile('PREREQ_PM'=>{'$p',$v});1"and
|
||||
exit)and print"==> $p $v required. Install it from CPAN? [Y".
|
||||
"/n] "and<STDIN>!~/^n/i and print"*** Installing $p\n"and do{
|
||||
eval{require CPANPLUS;CPANPLUS::install $p};eval"use $p $v;1"
|
||||
or eval{require CPAN;CPAN::install$p};eval"use $p $v;1"or die
|
||||
"*** Please install $p $v manually from cpan.org first.\n"}}}
|
||||
|
||||
# the above handlers must be declared before the 'use' statement
|
||||
use ExtUtils::AutoInstall (
|
||||
|
||||
# required AutoInstall version
|
||||
-version => '0.40',
|
||||
|
||||
# core modules; may also be 'all'
|
||||
-core => {
|
||||
Data::Compare => '0.02',
|
||||
Data::Dumper => '',
|
||||
Scalar::Util => '',
|
||||
Carp => '',
|
||||
IO::Handle => '',
|
||||
IO::File => '',
|
||||
Fcntl => '',
|
||||
constant => '',
|
||||
},
|
||||
|
||||
);
|
||||
|
||||
|
||||
WriteMakefile(
|
||||
NAME => 'Test::SimpleUnit',
|
||||
DISTNAME => 'Test-SimpleUnit',
|
||||
VERSION_FROM => 'lib/Test/SimpleUnit.pm', # finds $VERSION
|
||||
AUTHOR => 'Michael Granger <ged@FaerieMUD.org>',
|
||||
ABSTRACT => 'A simplified XUnit testing framework',
|
||||
dist => {
|
||||
CI => "cvs commit",
|
||||
RCS_LABEL => 'cvs tag RELEASE_$(VERSION_SYM)',
|
||||
SUFFIX => ".bz2",
|
||||
DIST_DEFAULT => 'all tardist',
|
||||
COMPRESS => "bzip2",
|
||||
},
|
||||
clean => { FILES => "*testdata*" },
|
||||
);
|
||||
|
237
README
Normal file
237
README
Normal file
@ -0,0 +1,237 @@
|
||||
|
||||
Test::SimpleUnit
|
||||
a simplified unit testing framework
|
||||
|
||||
Authors
|
||||
-------
|
||||
|
||||
Michael Granger <ged@FaerieMUD.org>
|
||||
|
||||
|
||||
General Information
|
||||
-------------------
|
||||
|
||||
This is a simplified Perl unit-testing framework for creating unit tests to be
|
||||
run either standalone or under Test::Harness.
|
||||
|
||||
|
||||
Testing
|
||||
|
||||
Testing in Test::SimpleUnit is done by running a test suite, either via 'make
|
||||
test', which uses the Test::Harness 'test' target written by
|
||||
ExtUtils::MakeMaker, or as a standalone script.
|
||||
|
||||
If errors occur while running tests via the 'make test' method, you can get
|
||||
more verbose output about the test run by adding "TEST_VERBOSE=1" to the end
|
||||
of the "make" invocation:
|
||||
|
||||
$ make test TEST_VERBOSE=1
|
||||
|
||||
If you want to display only the messages caused by failing assertions, you can
|
||||
add a "VERBOSE=1" to the end of the "make" invocation instead:
|
||||
|
||||
$ make test VERBOSE=1
|
||||
|
||||
|
||||
Test Suites
|
||||
|
||||
A test suite is one or more test cases, each of which tests a specific unit of
|
||||
functionality.
|
||||
|
||||
|
||||
Test Cases
|
||||
|
||||
A test case is a unit of testing which consists of one or more tests, combined
|
||||
with setup and teardown functions that make the necessary preparations for
|
||||
testing.
|
||||
|
||||
You may wish to split test cases up into separate files under a "t/" directory
|
||||
so they will run under a Test::Harness-style "make test".
|
||||
|
||||
|
||||
Tests
|
||||
|
||||
A test is a hashref which contains two key-value pairs: a name key with the
|
||||
name of the test as the value, and a code reference under a test key:
|
||||
|
||||
{
|
||||
name => 'This is the name of the test',
|
||||
test => sub { ...testing code... }
|
||||
}
|
||||
|
||||
Each test's "test" function can make one or more assertions by using the
|
||||
Assertion Functions provided, or can indicate that it or any trailing tests in
|
||||
the same test case should be skipped by calling one of the provided Skip
|
||||
Functions.
|
||||
|
||||
|
||||
Setup and Teardown Functions
|
||||
|
||||
If a test has the name 'setup' or 'teardown', it is run before or after each
|
||||
test that follows it, respectively. A second or succeeding setup or teardown
|
||||
function will supersede any function of the same type which preceded it. This
|
||||
allows a test designer to change the setup function as the tests progress. See
|
||||
the EXAMPLE section for an example of how to use this.
|
||||
|
||||
If a test is preceeded by multiple new setup/teardown functions, the last one
|
||||
to be specified is kept, and any others are discarded after being executed
|
||||
once. This allows one to specify one-time setup and/or teardown functions at a
|
||||
given point of testing.
|
||||
|
||||
The code reference value within a *setup* or *teardown* test case can
|
||||
optionally be named "func" instead of "test" for clarity. If there are both
|
||||
"func" and "test" key-value pairs in a *setup* or *teardown* case, the "test"
|
||||
pair is silently ignored.
|
||||
|
||||
|
||||
Saving Test Data
|
||||
|
||||
If the test suite requires configuration, or some other data which should
|
||||
persist between test cases, it can be dumped via Data::Dumper to a file with
|
||||
the saveTestData() function. In succeeding tests, it can be reloaded using the
|
||||
loadTestData() function.
|
||||
|
||||
|
||||
|
||||
Example
|
||||
-------
|
||||
|
||||
use Test::SimpleUnit qw{:functions};
|
||||
|
||||
# If a setup function fails, skip the rest of the tests
|
||||
Test::SimpleUnit::AutoskipFailedSetup( 1 );
|
||||
|
||||
my $Instance;
|
||||
my $RequireWasOkay = 0;
|
||||
|
||||
my @tests = (
|
||||
|
||||
# Require the module
|
||||
{
|
||||
name => 'require',
|
||||
test => sub {
|
||||
|
||||
# Make sure we can load the module to be tested.
|
||||
assertNoException { require MyClass };
|
||||
|
||||
# Try to import some functions, generating a custom error message if it
|
||||
# fails.
|
||||
assertNoException { MyClass->import(':myfuncs') } "Failed to import :myfuncs";
|
||||
|
||||
# Make sure calling 'import()' actually imported the functions
|
||||
assertRef 'CODE', *::myfunc{CODE};
|
||||
assertRef 'CODE', *::myotherfunc{CODE};
|
||||
|
||||
# Set the flag to let the setup function know the module loaded okay
|
||||
$RequireWasOkay = 1;
|
||||
},
|
||||
},
|
||||
|
||||
# Setup function (this will be run before any tests which follow)
|
||||
{
|
||||
name => 'setup',
|
||||
test => sub {
|
||||
# If the previous test didn't finish, it's untestable, so just skip the
|
||||
# rest of the tests
|
||||
skipAll "Module failed to load" unless $RequireWasOkay;
|
||||
$Instance = new MyClass;
|
||||
},
|
||||
},
|
||||
|
||||
# Teardown function (this will be run after any tests which follow)
|
||||
{
|
||||
name => 'teardown',
|
||||
test => sub {
|
||||
undef $Instance;
|
||||
},
|
||||
},
|
||||
|
||||
# One-time setup function -- overrides the previous setup, but is
|
||||
# immediately discarded after executing once.
|
||||
{
|
||||
name => 'setup',
|
||||
func => sub {
|
||||
MyClass::prepNetwork();
|
||||
},
|
||||
},
|
||||
|
||||
# Test the connect() and disconnect() methods
|
||||
{
|
||||
name => 'connect() and disconnect()',
|
||||
test => sub {
|
||||
my $rval;
|
||||
|
||||
assertNoException { $rval = $Instance->connect };
|
||||
assert $rval, "Connect failed without error.";
|
||||
assertNoException { $Instance->disconnect };
|
||||
},
|
||||
},
|
||||
|
||||
# Now override the previous setup function with a new one that does
|
||||
# a connect() before each remaining test.
|
||||
{
|
||||
name => 'setup',
|
||||
test => sub {
|
||||
$Instance = new MyClass;
|
||||
$Instance->connect;
|
||||
},
|
||||
}
|
||||
|
||||
# Same thing for teardown/disconnect()
|
||||
{
|
||||
name => 'teardown',
|
||||
test => sub {
|
||||
$Instance->disconnect;
|
||||
undef $Instance;
|
||||
},
|
||||
},
|
||||
|
||||
...
|
||||
|
||||
);
|
||||
|
||||
runTests( @testSuite );
|
||||
|
||||
|
||||
Caveats
|
||||
-------
|
||||
|
||||
I would greatly appreciate feedback on any aspect of this software. Suggestions,
|
||||
feature requests, questions, design critiques, and bug reports are most
|
||||
welcome. Relevant patches are particularly helpful. I may be reached at
|
||||
<ged@FaerieMUD.org>.
|
||||
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
$ perl Makefile.PL
|
||||
$ make
|
||||
$ make test
|
||||
(become root)
|
||||
# make install
|
||||
|
||||
|
||||
== Legal
|
||||
|
||||
This module is Open Source Software which is Copyright (c) 1999-2003 by The
|
||||
FaerieMUD Consortium.
|
||||
|
||||
You may use, modify, and/or redistribute this software under the terms of either
|
||||
the Perl Artistic License or the GNU Public License (version 2 or later),
|
||||
whichever you prefer. A copy of the Artistic license should have been included
|
||||
in this distribution (See the file Artistic). If it was not, a copy of it may be
|
||||
obtained from http://language.perl.com/misc/Artistic.html or
|
||||
http://www.faeriemud.org/artistic.html).
|
||||
|
||||
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
|
||||
Rev: $Id: README,v 1.5 2003/01/15 21:48:39 deveiant Exp $
|
||||
|
||||
|
||||
|
||||
|
||||
|
1215
lib/Test/SimpleUnit.pm
Normal file
1215
lib/Test/SimpleUnit.pm
Normal file
File diff suppressed because it is too large
Load Diff
34
t/00_require.t
Normal file
34
t/00_require.t
Normal file
@ -0,0 +1,34 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Test script for Test::SimpleUnit (require)
|
||||
# $Id: 00_require.t,v 1.2 2002/03/29 23:41:49 deveiant Exp $
|
||||
#
|
||||
# Before `make install' is performed this script should be runnable with
|
||||
# `make test'. After `make install' it should work as `perl test.pl'
|
||||
#
|
||||
# Please do not commit any changes you make to the module without a
|
||||
# successful 'make test'!
|
||||
#
|
||||
package main;
|
||||
use strict;
|
||||
|
||||
BEGIN { $| = 1; use vars qw{$LoadedOkay} }
|
||||
END { print "1..1\nnot ok 1\n" unless $LoadedOkay; }
|
||||
|
||||
### Load up the test framework
|
||||
require Test::SimpleUnit;
|
||||
|
||||
### Test suite (in the order they're run)
|
||||
my @testSuite = (
|
||||
{
|
||||
name => 'Require',
|
||||
test => sub {
|
||||
$LoadedOkay = 1;
|
||||
},
|
||||
},
|
||||
|
||||
);
|
||||
|
||||
Test::SimpleUnit::runTests( @testSuite );
|
||||
|
||||
|
36
t/01_importAll.t
Normal file
36
t/01_importAll.t
Normal file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Test script for Test::SimpleUnit (import functions)
|
||||
# $Id: 01_importAll.t,v 1.2 2002/03/29 23:41:49 deveiant Exp $
|
||||
#
|
||||
# Before `make install' is performed this script should be runnable with
|
||||
# `make test'. After `make install' it should work as `perl t/01_import.t'
|
||||
#
|
||||
# Please do not commit any changes you make to the module without a
|
||||
# successful 'make test'!
|
||||
#
|
||||
package main;
|
||||
use strict;
|
||||
|
||||
BEGIN { $| = 1; }
|
||||
|
||||
### Load up the test framework
|
||||
use Test::SimpleUnit qw{:functions};
|
||||
|
||||
sub genTest {
|
||||
my $functionName = shift;
|
||||
return {
|
||||
name => $functionName,
|
||||
test => sub {
|
||||
no strict 'refs';
|
||||
die "$functionName() was not imported" unless defined *{"main::${functionName}"}{CODE};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
### Generate a test suite out of the list of exported functions for the
|
||||
### 'functions' tag
|
||||
my @testSuite = map { s{^&}{}; genTest $_ } @{$Test::SimpleUnit::EXPORT_TAGS{functions}};
|
||||
Test::SimpleUnit::runTests( @testSuite );
|
||||
|
||||
|
36
t/02_importAsserts.t
Normal file
36
t/02_importAsserts.t
Normal file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Test script for Test::SimpleUnit (import functions)
|
||||
# $Id: 02_importAsserts.t,v 1.3 2002/03/29 23:41:49 deveiant Exp $
|
||||
#
|
||||
# Before `make install' is performed this script should be runnable with
|
||||
# `make test'. After `make install' it should work as `perl t/01_import.t'
|
||||
#
|
||||
# Please do not commit any changes you make to the module without a
|
||||
# successful 'make test'!
|
||||
#
|
||||
package main;
|
||||
use strict;
|
||||
|
||||
BEGIN { $| = 1; }
|
||||
|
||||
### Load up the test framework
|
||||
use Test::SimpleUnit qw{:asserts};
|
||||
|
||||
sub genTest {
|
||||
my $functionName = shift;
|
||||
return {
|
||||
name => $functionName,
|
||||
test => sub {
|
||||
no strict 'refs';
|
||||
die "$functionName() was not imported" unless defined *{"main::${functionName}"}{CODE};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
### Generate a test suite out of the list of exported functions for the
|
||||
### 'functions' tag
|
||||
my @testSuite = map { s{^&}{}; genTest $_ } @{$Test::SimpleUnit::EXPORT_TAGS{asserts}};
|
||||
Test::SimpleUnit::runTests( @testSuite );
|
||||
|
||||
|
36
t/03_importTfuncs.t
Normal file
36
t/03_importTfuncs.t
Normal file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Test script for Test::SimpleUnit (import functions)
|
||||
# $Id: 03_importTfuncs.t,v 1.2 2002/03/29 23:41:49 deveiant Exp $
|
||||
#
|
||||
# Before `make install' is performed this script should be runnable with
|
||||
# `make test'. After `make install' it should work as `perl t/01_import.t'
|
||||
#
|
||||
# Please do not commit any changes you make to the module without a
|
||||
# successful 'make test'!
|
||||
#
|
||||
package main;
|
||||
use strict;
|
||||
|
||||
BEGIN { $| = 1; }
|
||||
|
||||
### Load up the test framework
|
||||
use Test::SimpleUnit qw{:testFunctions};
|
||||
|
||||
sub genTest {
|
||||
my $functionName = shift;
|
||||
return {
|
||||
name => $functionName,
|
||||
test => sub {
|
||||
no strict 'refs';
|
||||
die "$functionName() was not imported" unless defined *{"main::${functionName}"}{CODE};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
### Generate a test suite out of the list of exported functions for the
|
||||
### 'functions' tag
|
||||
my @testSuite = map { s{^&}{}; genTest $_ } @{$Test::SimpleUnit::EXPORT_TAGS{testFunctions}};
|
||||
Test::SimpleUnit::runTests( @testSuite );
|
||||
|
||||
|
36
t/04_importSkips.t
Normal file
36
t/04_importSkips.t
Normal file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Test script for Test::SimpleUnit (import skip functions)
|
||||
# $Id: 04_importSkips.t,v 1.2 2002/03/29 23:41:49 deveiant Exp $
|
||||
#
|
||||
# Before `make install' is performed this script should be runnable with
|
||||
# `make test'. After `make install' it should work as `perl t/01_import.t'
|
||||
#
|
||||
# Please do not commit any changes you make to the module without a
|
||||
# successful 'make test'!
|
||||
#
|
||||
package main;
|
||||
use strict;
|
||||
|
||||
BEGIN { $| = 1; }
|
||||
|
||||
### Load up the test framework
|
||||
use Test::SimpleUnit qw{:skips};
|
||||
|
||||
sub genTest {
|
||||
my $functionName = shift;
|
||||
return {
|
||||
name => $functionName,
|
||||
test => sub {
|
||||
no strict 'refs';
|
||||
die "$functionName() was not imported" unless defined *{"main::${functionName}"}{CODE};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
### Generate a test suite out of the list of exported functions for the
|
||||
### 'functions' tag
|
||||
my @testSuite = map { s{^&}{}; genTest $_ } @{$Test::SimpleUnit::EXPORT_TAGS{skips}};
|
||||
Test::SimpleUnit::runTests( @testSuite );
|
||||
|
||||
|
36
t/05_importTestData.t
Normal file
36
t/05_importTestData.t
Normal file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Test script for Test::SimpleUnit
|
||||
# $Id: 05_importTestData.t,v 1.1 2003/01/15 20:46:44 deveiant Exp $
|
||||
#
|
||||
# Before `make install' is performed this script should be runnable with
|
||||
# `make test'. After `make install' it should work as `perl 05_importTestData.t'
|
||||
#
|
||||
# Please do not commit any changes you make to the module without a
|
||||
# successful 'make test'!
|
||||
#
|
||||
package main;
|
||||
use strict;
|
||||
|
||||
BEGIN { $| = 1; }
|
||||
|
||||
### Load up the test framework
|
||||
use Test::SimpleUnit qw{:testdata};
|
||||
|
||||
sub genTest {
|
||||
my $functionName = shift;
|
||||
return {
|
||||
name => $functionName,
|
||||
test => sub {
|
||||
no strict 'refs';
|
||||
die "$functionName() was not imported" unless defined *{"main::${functionName}"}{CODE};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
### Generate a test suite out of the list of exported functions for the
|
||||
### 'functions' tag
|
||||
my @testSuite = map { s{^&}{}; genTest $_ } @{$Test::SimpleUnit::EXPORT_TAGS{testdata}};
|
||||
Test::SimpleUnit::runTests( @testSuite );
|
||||
|
||||
|
482
t/10_asserts.t
Normal file
482
t/10_asserts.t
Normal file
@ -0,0 +1,482 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Test script for Test::SimpleUnit (import functions)
|
||||
# $Id: 10_asserts.t,v 1.4 2002/04/08 18:50:24 deveiant Exp $
|
||||
#
|
||||
# Before `make install' is performed this script should be runnable with
|
||||
# `make test'. After `make install' it should work as `perl t/01_import.t'
|
||||
#
|
||||
# Please do not commit any changes you make to the module without a
|
||||
# successful 'make test'!
|
||||
#
|
||||
|
||||
# Packages for testing OO asserts
|
||||
package ClassA;
|
||||
sub new {return bless {}, $_[0]}
|
||||
|
||||
package ClassB;
|
||||
use base qw{ClassA};
|
||||
|
||||
package ClassC;
|
||||
use base qw{ClassB};
|
||||
|
||||
# Main testing package
|
||||
package main;
|
||||
use strict;
|
||||
|
||||
BEGIN { $| = 1; }
|
||||
|
||||
### Load up the test framework
|
||||
use Test::SimpleUnit qw{:asserts};
|
||||
|
||||
my @testSuite = (
|
||||
|
||||
# Test the basic assert() function
|
||||
{
|
||||
name => 'Assert',
|
||||
test => sub {
|
||||
# Assert( true )
|
||||
eval { assert(1); };
|
||||
die "Failed assert(1): $@" if $@;
|
||||
|
||||
# Assert( false )
|
||||
eval { assert(0); };
|
||||
die "assert(0) unexpectedly succeeded." unless $@;
|
||||
die "Unexpected error message for assert(0): $@ (expected '0')"
|
||||
unless "$@" =~ m{0};
|
||||
|
||||
# Assert( false ) with message
|
||||
eval { assert(0, "message test") };
|
||||
die "assert(0,msg) unexpectedly succeeded." unless $@;
|
||||
die "Unexpected error message for assert(0): $@ (expected 'message test')"
|
||||
unless "$@" =~ m{message test};
|
||||
},
|
||||
},
|
||||
|
||||
# Test assertNot()
|
||||
{
|
||||
name => 'AssertNot',
|
||||
test => sub {
|
||||
# assertNot( 0 )
|
||||
eval { assertNot(0); };
|
||||
die "Failed assertNot(0): $@" if $@;
|
||||
|
||||
# assertNot( "" )
|
||||
eval { assertNot(""); };
|
||||
die "Failed assertNot(\"\"): $@" if $@;
|
||||
|
||||
# assertNot( undef )
|
||||
eval { assertNot(undef); };
|
||||
die "Failed assertNot(undef): $@" if $@;
|
||||
|
||||
# assertNot( 1 )
|
||||
eval { assertNot(1); };
|
||||
die "assertNot(1) unexpectedly succeeded." unless $@;
|
||||
die "Unexpected error message for assertNot(1): $@ (expected 'Expected a false value, got \"1\"')"
|
||||
unless "$@" =~ m{Expected a false value, got '1'};
|
||||
|
||||
# AssertNot( false ) with message
|
||||
eval { assertNot(1, "message test") };
|
||||
die "assertNot(1,msg) unexpectedly succeeded." unless $@;
|
||||
die "Unexpected error message for assertNot(0): $@ (expected 'message test')"
|
||||
unless "$@" =~ m{message test};
|
||||
},
|
||||
},
|
||||
|
||||
# Test assertDefined()
|
||||
{
|
||||
name => 'AssertDefined',
|
||||
test => sub {
|
||||
# assertDefined( 0 )
|
||||
eval { assertDefined(0); };
|
||||
die "Failed assertDefined(0): $@" if $@;
|
||||
|
||||
# assertDefined( "" )
|
||||
eval { assertDefined(""); };
|
||||
die "Failed assertDefined(\"\"): $@" if $@;
|
||||
|
||||
# assertDefined( undef )
|
||||
eval { assertDefined(undef); };
|
||||
die "assertDefined(undef) unexpectedly succeeded." unless $@;
|
||||
die "Unexpected error message for assertDefined(undef): $@ ",
|
||||
"(expected 'Expected a defined value, got an undef')"
|
||||
unless "$@" =~ m{Expected a defined value, got an undef};
|
||||
|
||||
# AssertDefined( undef ) with message
|
||||
eval { assertDefined(undef, "message test") };
|
||||
die "assertDefined(undef,msg) unexpectedly succeeded." unless $@;
|
||||
die "Unexpected error message for assertDefined(undef,msg): $@ ",
|
||||
"(expected 'message test')"
|
||||
unless "$@" =~ m{message test};
|
||||
},
|
||||
},
|
||||
|
||||
# Test assertUndef()
|
||||
{
|
||||
name => 'AssertUndef',
|
||||
test => sub {
|
||||
# assertUndef( undef )
|
||||
eval { assertUndef(undef); };
|
||||
die "Failed assertUndef(undef): $@" if $@;
|
||||
|
||||
# assertUndef( undef )
|
||||
eval { assertUndef(1); };
|
||||
die "assertUndef(1) unexpectedly succeeded." unless $@;
|
||||
die "Unexpected error message for assertUndef(1): $@ ",
|
||||
"(expected 'Expected an undefined value, got '1'')"
|
||||
unless "$@" =~ m{Expected an undefined value, got '1'};
|
||||
|
||||
# AssertUndef( undef ) with message
|
||||
eval { assertUndef(1, "message test") };
|
||||
die "assertUndef(1,msg) unexpectedly succeeded." unless $@;
|
||||
die "Unexpected error message for assertUndef(1,msg): $@ ",
|
||||
"(expected 'message test')"
|
||||
unless "$@" =~ m{message test};
|
||||
},
|
||||
},
|
||||
|
||||
# Test assertException()
|
||||
{
|
||||
name => 'AssertException',
|
||||
test => sub {
|
||||
my $res;
|
||||
|
||||
# assertException { die "test" }
|
||||
$res = eval { assertException {die "test"}; };
|
||||
die "Failed assertException {die \"test\"}: $@" if $@;
|
||||
assert( $res );
|
||||
undef $res;
|
||||
|
||||
# assertException { 1 }
|
||||
eval { assertException {1} };
|
||||
die "assertException unexpectedly succeeded" unless $@;
|
||||
die "Unexpected error message for assertException {1}: $@ ",
|
||||
"(expected 'No exception raised.')"
|
||||
unless "$@" =~ m{No exception raised\.};
|
||||
|
||||
# assertException { 1 }, $msg
|
||||
eval { assertException {1} "Ack! No exception?"; };
|
||||
die "assertException unexpectedly succeeded" unless $@;
|
||||
die "Unexpected error message for assertException {1}: $@ ",
|
||||
"(expected 'Ack! No exception?')"
|
||||
unless "$@" =~ m{Ack! No exception\?};
|
||||
},
|
||||
},
|
||||
|
||||
# Test assertExceptionType()
|
||||
{
|
||||
name => 'AssertExceptionType',
|
||||
test => sub {
|
||||
|
||||
# assertExceptionType { die "test" }
|
||||
eval { assertExceptionType {die bless ["test"], 'test'} 'test'; };
|
||||
die "Failed assertExceptionType {die bless [\"test\"], 'test'} 'test': $@" if $@;
|
||||
|
||||
# assertExceptionType { 1 }
|
||||
eval { assertExceptionType {1} 'any' };
|
||||
die "assertExceptionType unexpectedly succeeded" unless $@;
|
||||
die "Unexpected error message for assertExceptionType {1} 'any': $@ ",
|
||||
"(expected 'Expected an exception of type 'any', but none was raised. at ",
|
||||
"blib/lib/Test/SimpleUnit.pm line...')"
|
||||
unless "$@" =~ m{Expected an exception of type 'any', but none was raised\.};
|
||||
|
||||
# assertExceptionType { 1 }, $msg
|
||||
eval { assertExceptionType {1} 'any', "Ack! No exception?"; };
|
||||
die "assertExceptionType unexpectedly succeeded" unless $@;
|
||||
die "Unexpected error message for assertExceptionType {1} 'any', \"Ack! No exception?\": $@ ",
|
||||
"(expected 'Ack! No exception?')"
|
||||
unless "$@" =~ m{Ack! No exception\?};
|
||||
},
|
||||
},
|
||||
|
||||
# Test assertExceptionMatch()
|
||||
{
|
||||
name => 'AssertExceptionMatches',
|
||||
test => sub {
|
||||
|
||||
# Match a die()
|
||||
eval { assertExceptionMatches {die "Just testing"} qr{test}i; };
|
||||
die "Failed assertExceptionMatches {die \"Just testing\"} qr{test}i: $@" if $@;
|
||||
|
||||
# assertExceptionMatches { 1 } 'any'
|
||||
eval { assertExceptionMatches {1} qr{any} };
|
||||
die "assertExceptionMatches unexpectedly succeeded" unless $@;
|
||||
die "Unexpected error message for assertExceptionMatches {1} qr{any}: $@ ",
|
||||
"(expected 'Expected an exception which matched /(?-xism:any)/, but none ",
|
||||
"was raised.')"
|
||||
unless "$@" =~ m{Expected an exception which matched \Q/(?-xism:any)/\E, but none was raised\.};
|
||||
|
||||
# assertExceptionMatches { 1 } 'any', $msg
|
||||
eval { assertExceptionMatches {1} 'any', "Ack! No exception?"; };
|
||||
die "assertExceptionMatches unexpectedly succeeded" unless $@;
|
||||
die "Unexpected error message for assertExceptionMatches {1} 'any', \"Ack! No exception?\": $@ ",
|
||||
"(expected 'Ack! No exception?')"
|
||||
unless "$@" =~ m{Ack! No exception\?};
|
||||
},
|
||||
},
|
||||
|
||||
# Test assertNoException()
|
||||
{
|
||||
name => 'AssertNoException',
|
||||
test => sub {
|
||||
my $res;
|
||||
my $file = __FILE__;
|
||||
my $line;
|
||||
|
||||
# assertNoException { 1 }
|
||||
$res = eval { assertNoException {1}; };
|
||||
die "Failed assertNoException {1}: $@" if $@;
|
||||
assert( $res );
|
||||
undef $res;
|
||||
|
||||
# assertNoException { die "test" }
|
||||
$line = __LINE__ + 1;
|
||||
eval { assertNoException {die "test"} };
|
||||
die "assertNoException unexpectedly succeeded" unless $@;
|
||||
die "Unexpected error message for assertNoException {die \"test\"}: $@ ",
|
||||
"(expected 'Exception raised: test at $file line $line')"
|
||||
unless "$@" =~ m{Exception raised: test at $file line $line};
|
||||
|
||||
# assertNoException { die "test" }, $msg
|
||||
eval { assertNoException {die "test"} "Ack! Exception raised!"; };
|
||||
die "assertNoException unexpectedly succeeded" unless $@;
|
||||
die "Unexpected error message for assertNoException {die \"test\"}: $@ ",
|
||||
"(expected 'Ack! Exception raised!')"
|
||||
unless "$@" =~ m{Ack! Exception raised!};
|
||||
},
|
||||
},
|
||||
|
||||
# Test assertEquals()
|
||||
{
|
||||
name => 'AssertEquals',
|
||||
test => sub {
|
||||
my $res;
|
||||
|
||||
# assertEquals( 1, 1 )
|
||||
assertNoException { $res = assertEquals( 1, 1 ) };
|
||||
assert( $res );
|
||||
undef $res;
|
||||
|
||||
# assertEquals( 1, "1" )
|
||||
assertNoException { $res = assertEquals( 1, "1" ) };
|
||||
assert( $res );
|
||||
undef $res;
|
||||
|
||||
# assertEquals( "this", "this" )
|
||||
assertNoException { $res = assertEquals( "this", "this" ) };
|
||||
assert( $res );
|
||||
undef $res;
|
||||
|
||||
# assertEquals( undef, undef )
|
||||
assertNoException { $res = assertEquals( undef, undef ) };
|
||||
assert( $res );
|
||||
undef $res;
|
||||
|
||||
# assertEquals( 1, 2 )
|
||||
assertExceptionMatches { $res = assertEquals(1, 2) } qr{Wanted '1', got '2' instead};
|
||||
assertNot( $res );
|
||||
undef $res;
|
||||
|
||||
# assertEquals( 1, 1.1 )
|
||||
assertExceptionMatches { $res = assertEquals(1, 1.1) } qr{Wanted '1', got '1.1' instead};
|
||||
assertNot( $res );
|
||||
undef $res;
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
# Test assertMatches()
|
||||
{
|
||||
name => 'AssertMatches',
|
||||
test => sub {
|
||||
my $res;
|
||||
|
||||
# assertMatches( '\d+', 1 )
|
||||
assertNoException { $res = assertMatches( '\d+', 1 ) };
|
||||
assert( $res );
|
||||
undef $res;
|
||||
|
||||
# assertMatches( qr{\d+}, 1 )
|
||||
assertNoException { $res = assertMatches( qr{\d+}, 1 ) };
|
||||
assert( $res );
|
||||
undef $res;
|
||||
|
||||
# assertMatches( qr{\s+}, " 1" )
|
||||
assertNoException { $res = assertMatches( qr{\s+}, " 1" ) };
|
||||
assert( $res );
|
||||
undef $res;
|
||||
|
||||
# assertMatches( qr{\s+}, 1 )
|
||||
assertExceptionMatches {
|
||||
$res = assertMatches( qr{\s+}, 1 )
|
||||
} qr{Tested value '1' did not match wanted regex '\Q(?-xism:\s+)\E};
|
||||
assertNot( $res );
|
||||
undef $res;
|
||||
},
|
||||
},
|
||||
|
||||
# Test assertRef()
|
||||
{
|
||||
name => 'AssertRef',
|
||||
test => sub {
|
||||
my $res;
|
||||
|
||||
assertNoException { $res = assertRef('HASH', {}) };
|
||||
assert( $res );
|
||||
undef $res;
|
||||
|
||||
assertNoException { $res = assertRef('GLOB', \*STDIN) };
|
||||
assert( $res );
|
||||
undef $res;
|
||||
|
||||
assertNoException { $res = assertRef('ARRAY', []) };
|
||||
assert( $res );
|
||||
undef $res;
|
||||
|
||||
assertNoException { $res = assertRef('SCALAR', \"something") };
|
||||
assert( $res );
|
||||
undef $res;
|
||||
|
||||
assertNoException { $res = assertRef('ClassA', ClassA->new) };
|
||||
assert( $res );
|
||||
undef $res;
|
||||
|
||||
assertException { $res = assertRef('HASH', 'something') };
|
||||
assertMatches( qr{Expected a HASH value, got a scalar}, $@ );
|
||||
assertNot( $res );
|
||||
undef $res;
|
||||
|
||||
assertException { $res = assertRef('HASH', undef) };
|
||||
assertMatches( qr{Expected a HASH value, got a undefined value}, $@ );
|
||||
assertNot( $res );
|
||||
undef $res;
|
||||
|
||||
assertException { $res = assertRef('HASH', []) };
|
||||
assertMatches( qr{Expected a HASH value, got a ARRAY}, $@ );
|
||||
assertNot( $res );
|
||||
undef $res;
|
||||
|
||||
assertException { $res = assertRef('ClassA', []) };
|
||||
assertMatches( qr{Expected a ClassA value, got a ARRAY}, $@ );
|
||||
assertNot( $res );
|
||||
undef $res;
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
# Test assertInstanceOf()
|
||||
{
|
||||
name => 'AssertInstanceOf',
|
||||
test => sub {
|
||||
my ( $res, $aInstance, $bInstance, $cInstance );
|
||||
|
||||
$aInstance = ClassA->new;
|
||||
$bInstance = ClassB->new;
|
||||
$cInstance = ClassC->new;
|
||||
|
||||
# aInstance should be only a ClassA object...
|
||||
assertException { assertInstanceOf('ClassB', $aInstance) };
|
||||
assertMatches qr{Expected an instance of 'ClassB', got an instance of 'ClassA'}, $@;
|
||||
assertException { assertInstanceOf('ClassC', $aInstance) };
|
||||
assertMatches qr{Expected an instance of 'ClassC', got an instance of 'ClassA'}, $@;
|
||||
assertNoException { assertInstanceOf('ClassA', $aInstance) };
|
||||
|
||||
# bInstance should be only a ClassB object
|
||||
assertException { assertInstanceOf('ClassA', $bInstance) };
|
||||
assertMatches qr{Expected an instance of 'ClassA', got an instance of 'ClassB'}, $@;
|
||||
assertException { assertInstanceOf('ClassC', $bInstance) };
|
||||
assertMatches qr{Expected an instance of 'ClassC', got an instance of 'ClassB'}, $@;
|
||||
assertNoException { assertInstanceOf('ClassB', $bInstance) };
|
||||
|
||||
# cInstance should be only a ClassC object
|
||||
assertException { assertInstanceOf('ClassA', $cInstance) };
|
||||
assertMatches qr{Expected an instance of 'ClassA', got an instance of 'ClassC'}, $@;
|
||||
assertException { assertInstanceOf('ClassB', $cInstance) };
|
||||
assertMatches qr{Expected an instance of 'ClassB', got an instance of 'ClassC'}, $@;
|
||||
assertNoException { assertInstanceOf('ClassC', $cInstance) };
|
||||
|
||||
# A simple scalar shouldn't even make the ->isa() test
|
||||
assertException { assertInstanceOf('ClassA', "something") };
|
||||
assertMatches( qr{Expected an instance of 'ClassA', got a non-object \Q('something')\E}, $@ );
|
||||
|
||||
# Neither should a plain (unblessed) reference
|
||||
assertException { assertInstanceOf('ClassA', []) };
|
||||
assertMatches( qr{Expected an instance of 'ClassA', got a non-object \('ARRAY\(0x\w+\)'\)}, $@ );
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
# Test assertKindOf()
|
||||
{
|
||||
name => 'AssertKindOf',
|
||||
test => sub {
|
||||
my ( $res, $aInstance, $bInstance, $cInstance );
|
||||
|
||||
$aInstance = ClassA->new;
|
||||
$bInstance = ClassB->new;
|
||||
$cInstance = ClassC->new;
|
||||
|
||||
# aInstance should be an ClassA object...
|
||||
assertNoException { $res = assertKindOf('ClassA', $aInstance) };
|
||||
assert( $res );
|
||||
undef $res;
|
||||
|
||||
# bInstance should be both a ClassA and a ClassB object
|
||||
assertNoException { $res = assertKindOf('ClassA', $bInstance) };
|
||||
assert( $res );
|
||||
undef $res;
|
||||
|
||||
assertNoException { $res = assertKindOf('ClassB', $bInstance) };
|
||||
assert( $res );
|
||||
undef $res;
|
||||
|
||||
# cInstance should be all three
|
||||
assertNoException { $res = assertKindOf('ClassA', $cInstance) };
|
||||
assert( $res );
|
||||
undef $res;
|
||||
|
||||
assertNoException { $res = assertKindOf('ClassB', $cInstance) };
|
||||
assert( $res );
|
||||
undef $res;
|
||||
|
||||
assertNoException { $res = assertKindOf('ClassC', $cInstance) };
|
||||
assert( $res );
|
||||
undef $res;
|
||||
|
||||
# But aInstance should be neither a B nor a C
|
||||
assertException { $res = assertKindOf('ClassB', $aInstance) };
|
||||
assertMatches( qr{Expected an instance of 'ClassB' or a subclass, got an instance of 'ClassA'}, $@ );
|
||||
assertNot( $res );
|
||||
undef $res;
|
||||
|
||||
assertException { $res = assertKindOf('ClassC', $aInstance) };
|
||||
assertMatches( qr{Expected an instance of 'ClassC' or a subclass, got an instance of 'ClassA'}, $@ );
|
||||
assertNot( $res );
|
||||
undef $res;
|
||||
|
||||
# Neither should bInstance be a C
|
||||
assertException { $res = assertKindOf('ClassC', $bInstance) };
|
||||
assertMatches( qr{Expected an instance of 'ClassC' or a subclass, got an instance of 'ClassB'}, $@ );
|
||||
assertNot( $res );
|
||||
undef $res;
|
||||
|
||||
# A simple scalar shouldn't even make the ->isa() test
|
||||
assertException { $res = assertKindOf('ClassA', "something") };
|
||||
assertMatches( qr{Expected an instance of 'ClassA' or a subclass, got a non-object \Q('something')\E}, $@ );
|
||||
assertNot( $res );
|
||||
undef $res;
|
||||
|
||||
# Neither should a plain (unblessed) reference
|
||||
assertException { $res = assertKindOf('ClassA', []) };
|
||||
assertMatches( qr{Expected an instance of 'ClassA' or a subclass, got a non-object \('ARRAY\(0x\w+\)'\)}, $@ );
|
||||
assertNot( $res );
|
||||
undef $res;
|
||||
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
Test::SimpleUnit::runTests( @testSuite );
|
||||
|
||||
|
97
t/11_skips.t
Normal file
97
t/11_skips.t
Normal file
@ -0,0 +1,97 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Test script for Test::SimpleUnit
|
||||
# $Id: 11_skips.t,v 1.3 2002/04/15 19:54:35 deveiant Exp $
|
||||
#
|
||||
# Before `make install' is performed this script should be runnable with
|
||||
# `make test'. After `make install' it should work as `perl 05_skip.t'
|
||||
#
|
||||
# Please do not commit any changes you make to the module without a
|
||||
# successful 'make test'!
|
||||
#
|
||||
package main;
|
||||
use strict;
|
||||
|
||||
BEGIN { $| = 1; }
|
||||
|
||||
### Load up the test framework
|
||||
use Test::SimpleUnit qw{:functions};
|
||||
|
||||
|
||||
### Test suite (in the order they're run)
|
||||
my @testSuite = (
|
||||
|
||||
{
|
||||
name => 'Autoskip setting',
|
||||
test => sub {
|
||||
# Backwards compat
|
||||
assertNoException { Test::SimpleUnit->AutoskipFailedSetup(1) };
|
||||
assert Test::SimpleUnit::AutoskipFailedSetup();
|
||||
|
||||
assertNoException { Test::SimpleUnit::AutoskipFailedSetup(0) };
|
||||
assertNot Test::SimpleUnit::AutoskipFailedSetup();
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name => 'Skip one (no message)',
|
||||
test => sub {
|
||||
eval { skipOne };
|
||||
assertInstanceOf 'SKIPONE', $@;
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name => 'Skip one (with message)',
|
||||
test => sub {
|
||||
eval { skipOne "Testing" };
|
||||
assertInstanceOf 'SKIPONE', $@;
|
||||
assertEquals "Testing", ${$@};
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name => 'Real skip one',
|
||||
test => sub {
|
||||
skipOne "Passed.";
|
||||
fail "Test wasn't skipped.";
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name => 'Skip all (no message)',
|
||||
test => sub {
|
||||
eval { skipAll };
|
||||
assertInstanceOf 'SKIPALL', $@;
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name => 'Skip all (with message)',
|
||||
test => sub {
|
||||
eval { skipAll "Testing" };
|
||||
assertInstanceOf 'SKIPALL', $@;
|
||||
assertEquals "Testing", ${$@};
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name => 'Real skip all',
|
||||
test => sub {
|
||||
skipAll "Passed.";
|
||||
fail "Immediate test body wasn't skipped by skipAll.";
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name => 'Should be skipped',
|
||||
test => sub {
|
||||
fail "Following test body wasn't skipped by skipAll.";
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
);
|
||||
|
||||
runTests( @testSuite );
|
||||
|
87
t/12_testdata.t
Normal file
87
t/12_testdata.t
Normal file
@ -0,0 +1,87 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Test script for Test::SimpleUnit
|
||||
# $Id: 12_testdata.t,v 1.1 2003/01/15 20:46:44 deveiant Exp $
|
||||
#
|
||||
# Before `make install' is performed this script should be runnable with
|
||||
# `make test'. After `make install' it should work as `perl 10_testdata.t'
|
||||
#
|
||||
# Please do not commit any changes you make to the module without a
|
||||
# successful 'make test'!
|
||||
#
|
||||
package main;
|
||||
use strict;
|
||||
|
||||
BEGIN { $| = 1; }
|
||||
|
||||
### Load up the test framework
|
||||
use Test::SimpleUnit qw{:functions};
|
||||
|
||||
my (
|
||||
$filename,
|
||||
%testData,
|
||||
);
|
||||
|
||||
|
||||
### Test suite (in the order they're run)
|
||||
my @testSuite = (
|
||||
|
||||
### Setup/Teardown functions
|
||||
{
|
||||
name => 'setup',
|
||||
func => sub {
|
||||
$filename = "12testdata.$$";
|
||||
%testData = (
|
||||
some => 'data',
|
||||
for => "testing",
|
||||
complex => [qw{an arrayref }],
|
||||
hoh => {
|
||||
more => 'keys',
|
||||
and => 'vals',
|
||||
another => {},
|
||||
},
|
||||
);
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name => 'teardown',
|
||||
func => sub {
|
||||
$filename = '';
|
||||
%testData = ();
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
### Save the test data
|
||||
{
|
||||
name => 'savedata',
|
||||
test => sub {
|
||||
Test::SimpleUnit::Debug( 1 );
|
||||
assertNoException {
|
||||
saveTestData( $filename, %testData );
|
||||
};
|
||||
assert -f $filename;
|
||||
},
|
||||
},
|
||||
|
||||
### Load the test data back up and compare it with the original
|
||||
{
|
||||
name => 'loaddata',
|
||||
test => sub {
|
||||
my $datahash;
|
||||
|
||||
Test::SimpleUnit::Debug( 1 );
|
||||
assertNoException {
|
||||
$datahash = loadTestData( $filename );
|
||||
};
|
||||
assertRef 'HASH', $datahash;
|
||||
assertEquals \%testData, $datahash;
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
);
|
||||
|
||||
runTests( @testSuite );
|
||||
|
230
t/15_setupteardown.t
Normal file
230
t/15_setupteardown.t
Normal file
@ -0,0 +1,230 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Test script for Test::SimpleUnit
|
||||
# $Id: 15_setupteardown.t,v 1.4 2003/01/15 20:48:07 deveiant Exp $
|
||||
#
|
||||
# Before `make install' is performed this script should be runnable with
|
||||
# `make test'. After `make install' it should work as `perl 07_setupteardown.t'
|
||||
#
|
||||
# Please do not commit any changes you make to the module without a
|
||||
# successful 'make test'!
|
||||
#
|
||||
package main;
|
||||
use strict;
|
||||
|
||||
BEGIN { $| = 1; }
|
||||
|
||||
### Load up the test framework
|
||||
use Test::SimpleUnit qw{:functions};
|
||||
|
||||
#Test::SimpleUnit::Debug( 1 );
|
||||
|
||||
my %setupRuns = ();
|
||||
my %teardownRuns = ();
|
||||
|
||||
|
||||
### Test suite (in the order they're run)
|
||||
my @testSuite = (
|
||||
|
||||
### Plain setup
|
||||
|
||||
# First setup function
|
||||
{
|
||||
name => 'setup',
|
||||
func => sub {
|
||||
$setupRuns{first}++;
|
||||
},
|
||||
},
|
||||
|
||||
# Test to make sure the setup ran
|
||||
{
|
||||
name => 'test first setup',
|
||||
test => sub {
|
||||
assertEquals 1, $setupRuns{first};
|
||||
},
|
||||
},
|
||||
|
||||
### Overridden setup
|
||||
|
||||
# Override the first setup with this, the second one
|
||||
{
|
||||
name => 'setup',
|
||||
test => sub {
|
||||
$setupRuns{second}++;
|
||||
},
|
||||
},
|
||||
|
||||
# Test to be sure the two setup functions have run exactly once each
|
||||
{
|
||||
name => 'test second setup',
|
||||
test => sub {
|
||||
assertEquals 1, $setupRuns{first};
|
||||
assertEquals 1, $setupRuns{second};
|
||||
},
|
||||
},
|
||||
|
||||
# Test to be sure the first setup has still only run once, but that the
|
||||
# second has now run twice
|
||||
{
|
||||
name => 'test second setup again',
|
||||
test => sub {
|
||||
assertEquals 1, $setupRuns{first};
|
||||
assertEquals 2, $setupRuns{second};
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
### Assure all setups run at least once
|
||||
|
||||
# Override the second setup with this, the third one, but then clobber this
|
||||
# one with a fourth. This one should only be run once.
|
||||
{
|
||||
name => 'setup',
|
||||
test => sub {
|
||||
$setupRuns{third}++;
|
||||
},
|
||||
},
|
||||
|
||||
# Override the third setup with this, the fourth one.
|
||||
{
|
||||
name => 'setup',
|
||||
test => sub {
|
||||
$setupRuns{fourth}++;
|
||||
},
|
||||
},
|
||||
|
||||
# Test to be sure the first has now run once, the second twice, the third
|
||||
# once, and the fourth one once.
|
||||
{
|
||||
name => 'test third and fourth setup (1st run)',
|
||||
test => sub {
|
||||
assertEquals 1, $setupRuns{first};
|
||||
assertEquals 2, $setupRuns{second};
|
||||
assertEquals 1, $setupRuns{third};
|
||||
assertEquals 1, $setupRuns{fourth};
|
||||
},
|
||||
},
|
||||
|
||||
# Test again to be sure the first has now run once, the second twice, the
|
||||
# third still only once, and the fourth two times.
|
||||
{
|
||||
name => 'test third and fourth setup (2nd run)',
|
||||
test => sub {
|
||||
assertEquals 1, $setupRuns{first};
|
||||
assertEquals 2, $setupRuns{second};
|
||||
assertEquals 1, $setupRuns{third};
|
||||
assertEquals 2, $setupRuns{fourth};
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
### Now do the same thing for teardown functions
|
||||
|
||||
# First teardown function
|
||||
{
|
||||
name => 'teardown',
|
||||
func => sub {
|
||||
$teardownRuns{first}++;
|
||||
},
|
||||
},
|
||||
|
||||
# Test to make sure the teardown hasn't yet run, but will in the second test.
|
||||
{
|
||||
name => 'test first teardown (pre-run)',
|
||||
test => sub {
|
||||
assertNot exists $teardownRuns{first};
|
||||
},
|
||||
},
|
||||
|
||||
# Test to make sure the teardown hasn't yet run, but will in the second test.
|
||||
{
|
||||
name => 'test first teardown (post-run)',
|
||||
test => sub {
|
||||
assertEquals 1, $teardownRuns{first};
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
### Overridden teardown
|
||||
|
||||
# Override the first teardown with this, the second one
|
||||
{
|
||||
name => 'teardown',
|
||||
test => sub {
|
||||
$teardownRuns{second}++;
|
||||
},
|
||||
},
|
||||
|
||||
# Test the second teardown, pre-run
|
||||
{
|
||||
name => 'test second teardown',
|
||||
test => sub {
|
||||
assertEquals 2, $teardownRuns{first};
|
||||
assertNot exists $teardownRuns{second};
|
||||
},
|
||||
},
|
||||
|
||||
# Test the second teardown, post-run
|
||||
{
|
||||
name => 'test second teardown',
|
||||
test => sub {
|
||||
assertEquals 2, $teardownRuns{first};
|
||||
assertEquals 1, $teardownRuns{second};
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
|
||||
### Assure all teardowns run at least once
|
||||
|
||||
# Override the second teardown with this, the third one, but then clobber this
|
||||
# one with a fourth. This one should then only be run once.
|
||||
{
|
||||
name => 'teardown',
|
||||
test => sub {
|
||||
$teardownRuns{third}++;
|
||||
},
|
||||
},
|
||||
|
||||
# Override the third teardown with this, the fourth one.
|
||||
{
|
||||
name => 'teardown',
|
||||
test => sub {
|
||||
$teardownRuns{fourth}++;
|
||||
},
|
||||
},
|
||||
|
||||
# Bogus test for the third and fourth teardown, pre-run
|
||||
{
|
||||
name => 'test third and fourth teardown (pre-run)',
|
||||
test => sub { 1 },
|
||||
},
|
||||
|
||||
# Test to be sure the first has now run once, the second twice, and the
|
||||
# third and fourth once each.
|
||||
{
|
||||
name => 'test third and fourth teardown (1st run)',
|
||||
test => sub {
|
||||
assertEquals 2, $teardownRuns{first};
|
||||
assertEquals 2, $teardownRuns{second};
|
||||
assertEquals 1, $teardownRuns{third};
|
||||
assertEquals 1, $teardownRuns{fourth};
|
||||
},
|
||||
},
|
||||
|
||||
# Now make sure the third test has still only run once, but the fourth
|
||||
# should have run a second time.
|
||||
{
|
||||
name => 'test third and fourth teardown (2nd run)',
|
||||
test => sub {
|
||||
assertEquals 2, $teardownRuns{first};
|
||||
assertEquals 2, $teardownRuns{second};
|
||||
assertEquals 1, $teardownRuns{third};
|
||||
assertEquals 2, $teardownRuns{fourth};
|
||||
},
|
||||
},
|
||||
|
||||
);
|
||||
|
||||
runTests( @testSuite );
|
||||
|
40
t/20_emptysuite.t
Normal file
40
t/20_emptysuite.t
Normal file
@ -0,0 +1,40 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Test script for Test::SimpleUnit
|
||||
# $Id: 20_emptysuite.t,v 1.1 2002/04/23 22:01:34 deveiant Exp $
|
||||
#
|
||||
# Before `make install' is performed this script should be runnable with
|
||||
# `make test'. After `make install' it should work as `perl 08_emptysuite.t'
|
||||
#
|
||||
# Please do not commit any changes you make to the module without a
|
||||
# successful 'make test'!
|
||||
#
|
||||
package main;
|
||||
use strict;
|
||||
|
||||
BEGIN { $| = 1; }
|
||||
|
||||
### Load up the test framework
|
||||
use Test::SimpleUnit qw{:functions};
|
||||
|
||||
|
||||
### Test an empty test suite -- used to fail because the setup and teardown
|
||||
### tests are spliced out. Should now just skip gracefully.
|
||||
my @testSuite = (
|
||||
|
||||
{
|
||||
name => 'setup',
|
||||
func => sub {
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name => 'teardown',
|
||||
func => sub {
|
||||
},
|
||||
},
|
||||
|
||||
);
|
||||
|
||||
runTests( @testSuite );
|
||||
|
60
t/30_bugs.t
Normal file
60
t/30_bugs.t
Normal file
@ -0,0 +1,60 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Test script for fixed bugs that don't need their own suite
|
||||
# $Id: 30_bugs.t,v 1.1 2002/05/14 02:59:02 deveiant Exp $
|
||||
#
|
||||
# Before `make install' is performed this script should be runnable with
|
||||
# `make test'. After `make install' it should work as `perl 09_bugs.t'
|
||||
#
|
||||
# Please do not commit any changes you make to the module without a
|
||||
# successful 'make test'!
|
||||
#
|
||||
package main;
|
||||
use strict;
|
||||
|
||||
BEGIN { $| = 1; }
|
||||
|
||||
### Load up the test framework
|
||||
use Test::SimpleUnit qw{:functions};
|
||||
use IO::Handle;
|
||||
use IO::File;
|
||||
|
||||
#$Test::SimpleUnit::Debug = 1;
|
||||
|
||||
# Get a reference to stdout so we can switch it off for recursive tests
|
||||
my $Stdout = IO::Handle->new_from_fd( fileno STDOUT, 'w' )
|
||||
or die "Ack: STDOUT doesn't exist";
|
||||
my $DummyIO = new IO::File '/dev/null', 'w';
|
||||
|
||||
### Test suite (in the order they're run)
|
||||
my @testSuite = (
|
||||
|
||||
# Can't use string ("") as a subroutine ref while "strict refs" in use at
|
||||
# /usr/lib/perl5/site_perl/5.6.1/Test/SimpleUnit.pm line 665.
|
||||
{
|
||||
name => 'Missing "test" key-val pair',
|
||||
test => sub {
|
||||
assertNoException {
|
||||
Test::SimpleUnit::OutputHandle( $DummyIO );
|
||||
runTests({ name => 'subtest' });
|
||||
Test::SimpleUnit::OutputHandle();
|
||||
};
|
||||
},
|
||||
},
|
||||
|
||||
# Error related to the above one: Test isn't a coderef.
|
||||
{
|
||||
name => 'non-coderef value in "test" key-val pair',
|
||||
test => sub {
|
||||
assertNoException {
|
||||
Test::SimpleUnit::OutputHandle( $DummyIO );
|
||||
runTests({ name => 'subtest', test => {} });
|
||||
Test::SimpleUnit::OutputHandle();
|
||||
};
|
||||
},
|
||||
},
|
||||
|
||||
);
|
||||
|
||||
runTests( @testSuite );
|
||||
|
Loading…
Reference in New Issue
Block a user