Skip to content

Commit

Permalink
Import of ERIK/Test-Functional-0.04 from CPAN.
Browse files Browse the repository at this point in the history
gitpan-cpan-distribution: Test-Functional
gitpan-cpan-version:      0.04
gitpan-cpan-path:         ERIK/Test-Functional-0.04.tar.gz
gitpan-cpan-author:       ERIK
gitpan-cpan-maturity:     released
  • Loading branch information
Erik Andreas Osheim authored and Gitpan committed Oct 21, 2014
1 parent 4c1e82e commit 07b179f
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 22 deletions.
4 changes: 4 additions & 0 deletions Build.PL
Expand Up @@ -21,6 +21,10 @@ my $builder = Module::Build->new(
'Test::Builder' => 0,
'Test::More' => 0,
},
recommends => {
'Test::Pod' => 0,
'Test::Pod::Coverage' => 0,
},
add_to_cleanup => [ 'Test-Functional-*' ],
create_makefile_pl => 'traditional',
create_readme => 1,
Expand Down
6 changes: 6 additions & 0 deletions Changes
@@ -1,5 +1,11 @@
Revision history for Test-Functional

0.04 Sun Aug 16 10:48:15 EDT 2009
- improved test coverage
- fixed pretest/group bug
- added configure() function
- found Test::Builder::Tester problem

0.03 Thu Jul 9 11:10:33 EDT 2009
- removed boilerplate test
- fixed strange version bug
Expand Down
1 change: 1 addition & 0 deletions MANIFEST
@@ -1,5 +1,6 @@
Build.PL
Changes
foo.t
lib/Test/Functional.pm
lib/Test/Functional/Conf.pm
Makefile.PL
Expand Down
9 changes: 6 additions & 3 deletions META.yml
@@ -1,6 +1,6 @@
---
name: Test-Functional
version: 0.03
version: 0.04
author:
- 'Erik Osheim <erik@osheim.org>'
abstract: Perl tests in a functional style.
Expand All @@ -15,13 +15,16 @@ requires:
perl: 5.6.0
build_requires:
Test::More: 0
recommends:
Test::Pod: 0
Test::Pod::Coverage: 0
provides:
Test::Functional:
file: lib/Test/Functional.pm
version: 0.03
version: 0.04
Test::Functional::Conf:
file: lib/Test/Functional/Conf.pm
version: 0.03
version: 0.04
generated_by: Module::Build version 0.280801
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.2.html
Expand Down
12 changes: 6 additions & 6 deletions Makefile.PL
Expand Up @@ -3,16 +3,16 @@ require 5.6.0;
use ExtUtils::MakeMaker;
WriteMakefile
(
'PL_FILES' => {},
'INSTALLDIRS' => 'site',
'NAME' => 'Test::Functional',
'EXE_FILES' => [],
'VERSION_FROM' => 'lib/Test/Functional.pm',
'PREREQ_PM' => {
'Test::More' => 0,
'Data::Compare' => 0,
'Scalar::Quote' => 0,
'Test::Builder' => 0,
'Scalar::Quote' => 0
}
'Test::More' => 0
},
'INSTALLDIRS' => 'site',
'EXE_FILES' => [],
'PL_FILES' => {}
)
;
13 changes: 13 additions & 0 deletions README
Expand Up @@ -51,6 +51,19 @@ EXPORTS
# import all but notest
use Test::Functional tests => 23, import => ['!notest'];

CONFIGURE
This package has two settings which can be altered to change
performance:

unstable - run tests which are normally skipped
fastout - cause the entire test to end after the first failure

This package can be configured via Test::Functional::Conf or the
configure() function.

configure KEY => VALUE, ...
Changes configuration values at run-time.

TEST STRUCTURES
test { BLOCK } [CONDITION,] NAME
This is the basic building block of Test::Functional. Each test
Expand Down
7 changes: 7 additions & 0 deletions foo.t
@@ -0,0 +1,7 @@
use Test::Functional;

group {
test { 14 } 14, "test1";
pretest { 14 } 13, "test2";
test { 13 } 13, "test3";
} "grp";
48 changes: 40 additions & 8 deletions lib/Test/Functional.pm
Expand Up @@ -3,7 +3,7 @@ package Test::Functional;
use warnings FATAL => 'all';
use strict;

our $VERSION = '0.03';
our $VERSION = '0.04';

=head1 NAME
Expand Down Expand Up @@ -77,9 +77,37 @@ our @EXPORT = (
);

# three global variables: two settings and a stack for test groups
my $UNSTABLE = Test::Functional::Conf->unstable;
my $FASTOUT = Test::Functional::Conf->fastout;
my @STACK;
my ($UNSTABLE, $FASTOUT, @STACK);

=head1 CONFIGURE
This package has two settings which can be altered to change performance:
unstable - run tests which are normally skipped
fastout - cause the entire test to end after the first failure
This package can be configured via L<Test::Functional::Conf> or the configure()
function.
=over
=item configure KEY => VALUE, ...
Changes configuration values at run-time.
=cut
sub configure {
my (%opts) = @_;
$UNSTABLE = $opts{unstable} if exists($opts{unstable});
$FASTOUT = $opts{fastout} if exists($opts{fastout});
}

configure(
unstable => Test::Functional::Conf->unstable,
fastout => Test::Functional::Conf->fastout,
);

=back
=head1 TEST STRUCTURES
Expand Down Expand Up @@ -165,10 +193,14 @@ sub _test {
my $t = __PACKAGE__->builder();
$t->level(3);
return _ok($@, $name, " failed to die") if $cmpfunc eq $dies;
return _fail($name, " died: $@") if $@;

$t->level(4);
my $ok = &$cmpfunc($result, $name);
my $ok;
if($@) {
_fail($name, " died: $@") if $@;
$ok = 0;
} else {
$t->level(4);
$ok = &$cmpfunc($result, $name);
}
die if $pre && !$ok && @STACK;
$t->BAIL_OUT("pretest failed") if !$ok && $pre;
$t->BAIL_OUT("fastout is on") if !$ok && $FASTOUT;
Expand Down
2 changes: 1 addition & 1 deletion lib/Test/Functional/Conf.pm
Expand Up @@ -3,7 +3,7 @@ package Test::Functional::Conf;
use warnings FATAL => 'all';
use strict;

our $VERSION = '0.03';
our $VERSION = '0.04';

use Carp;
use Exporter;
Expand Down
48 changes: 44 additions & 4 deletions t/output.t
@@ -1,18 +1,18 @@
#!/usr/bin/perl
use warnings FATAL => 'all';
use strict;

use Test::Builder::Tester tests => 21;
use Test::Builder::Tester tests => 25;
use Test::Functional;
use Test::More;

sub mytest_fail {
my ($offset, $msg) = @_;
my ($offset, $msg, $name) = @_;
$name ||= 'test';
my ($pkg, $file, $line) = caller();
$line += $offset || 0;
$msg ||= '';
my $err = <<ERR;
# Failed test 'test'
# Failed test '$name'
# at $file line $line.
$msg
ERR
Expand Down Expand Up @@ -125,3 +125,43 @@ test_out("not ok 1 - test");
mytest_fail(1, "# died: Died at t/output.t line 126.");
test { die } sub { like($_[0], qr/foo/, $_[1]) }, "test";
test_test("custom-die");

test_out("not ok 1 - grp.test");
mytest_fail(2, "# got: '8'\n# expected: '34'", 'grp.test');
group {
pretest { 8 } 34, "test";
test { 19 } 19, "test2";
} "grp";
test_test("pretest");

test_out("not ok 1 - grp.test");
mytest_fail(2, "# died: Died at t/output.t line 140.", 'grp.test');
group {
pretest { die } 34, "test";
test { 19 } 19, "test2"
} "grp";
test_test("pretest");

test_out("ok 1 # skip test");
notest { 19 } 88, "test";
test_test("notest-stable");

Test::Functional::configure(unstable => 1, fastout => 0);

test_out("not ok 1 - test");
mytest_fail(1, "# got: '19'\n# expected: '88'");
notest { 19 } 88, "test";
test_test("notest-unstable");

# there is a bug with Test::Builder::Tester that means that when
# Test::Functional calls $t->BAIL_OUT() it causes THIS test to exit. ugh.

#Test::Functional::configure(unstable => 0, fastout => 1);
#
#test_out("not ok 1 - grp.test");
#mytest_fail(2, "# got: '8'\n# expected: '34'", 'grp.test');
#group {
# test { 8 } 34, "test";
# test { 19 } 19, "test2";
#} "grp";
#test_test("fastout");

0 comments on commit 07b179f

Please sign in to comment.