summaryrefslogtreecommitdiff
path: root/cpan/Test-Simple/t/lib
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2009-10-02 16:19:41 +0100
committerNicholas Clark <nick@ccl4.org>2009-10-02 16:19:41 +0100
commite0ee75a6976f08f9bc3868227f1cd11ab6507895 (patch)
tree5366acf520d51f2f3961274ced349a4178685be5 /cpan/Test-Simple/t/lib
parent8c5b8ff02c62badaeb38078556879720bdf8945a (diff)
downloadperl-e0ee75a6976f08f9bc3868227f1cd11ab6507895.tar.gz
Move Test::Simple from ext/ to cpan/
Diffstat (limited to 'cpan/Test-Simple/t/lib')
-rw-r--r--cpan/Test-Simple/t/lib/Dev/Null.pm8
-rw-r--r--cpan/Test-Simple/t/lib/Dummy.pm6
-rw-r--r--cpan/Test-Simple/t/lib/MyOverload.pm30
-rw-r--r--cpan/Test-Simple/t/lib/NoExporter.pm12
-rw-r--r--cpan/Test-Simple/t/lib/SigDie.pm8
-rw-r--r--cpan/Test-Simple/t/lib/Test/Builder/NoOutput.pm122
-rw-r--r--cpan/Test-Simple/t/lib/Test/Simple/Catch.pm20
-rw-r--r--cpan/Test-Simple/t/lib/Test/Simple/sample_tests/death.plx16
-rw-r--r--cpan/Test-Simple/t/lib/Test/Simple/sample_tests/death_in_eval.plx22
-rw-r--r--cpan/Test-Simple/t/lib/Test/Simple/sample_tests/death_with_handler.plx20
-rw-r--r--cpan/Test-Simple/t/lib/Test/Simple/sample_tests/exit.plx3
-rw-r--r--cpan/Test-Simple/t/lib/Test/Simple/sample_tests/extras.plx16
-rw-r--r--cpan/Test-Simple/t/lib/Test/Simple/sample_tests/five_fail.plx13
-rw-r--r--cpan/Test-Simple/t/lib/Test/Simple/sample_tests/last_minute_death.plx19
-rw-r--r--cpan/Test-Simple/t/lib/Test/Simple/sample_tests/one_fail.plx14
-rw-r--r--cpan/Test-Simple/t/lib/Test/Simple/sample_tests/pre_plan_death.plx17
-rw-r--r--cpan/Test-Simple/t/lib/Test/Simple/sample_tests/require.plx1
-rw-r--r--cpan/Test-Simple/t/lib/Test/Simple/sample_tests/success.plx13
-rw-r--r--cpan/Test-Simple/t/lib/Test/Simple/sample_tests/too_few.plx11
-rw-r--r--cpan/Test-Simple/t/lib/Test/Simple/sample_tests/too_few_fail.plx12
-rw-r--r--cpan/Test-Simple/t/lib/Test/Simple/sample_tests/two_fail.plx14
-rw-r--r--cpan/Test-Simple/t/lib/TieOut.pm30
22 files changed, 427 insertions, 0 deletions
diff --git a/cpan/Test-Simple/t/lib/Dev/Null.pm b/cpan/Test-Simple/t/lib/Dev/Null.pm
new file mode 100644
index 0000000000..24ec07ab57
--- /dev/null
+++ b/cpan/Test-Simple/t/lib/Dev/Null.pm
@@ -0,0 +1,8 @@
+package Dev::Null;
+
+use strict;
+
+sub TIEHANDLE { bless {}, shift }
+sub PRINT { 1 }
+
+1;
diff --git a/cpan/Test-Simple/t/lib/Dummy.pm b/cpan/Test-Simple/t/lib/Dummy.pm
new file mode 100644
index 0000000000..cdff79d540
--- /dev/null
+++ b/cpan/Test-Simple/t/lib/Dummy.pm
@@ -0,0 +1,6 @@
+package Dummy;
+
+use strict;
+our $VERSION = '0.01';
+
+1;
diff --git a/cpan/Test-Simple/t/lib/MyOverload.pm b/cpan/Test-Simple/t/lib/MyOverload.pm
new file mode 100644
index 0000000000..65f5ea5a7d
--- /dev/null
+++ b/cpan/Test-Simple/t/lib/MyOverload.pm
@@ -0,0 +1,30 @@
+package Overloaded; ##no critic (Modules::RequireFilenameMatchesPackage)
+
+use strict;
+
+sub new {
+ my $class = shift;
+ bless { string => shift, num => shift }, $class;
+}
+
+package Overloaded::Compare;
+
+use strict;
+our @ISA = qw(Overloaded);
+
+# Sometimes objects have only comparison ops overloaded and nothing else.
+# For example, DateTime objects.
+use overload
+ q{eq} => sub { $_[0]->{string} eq $_[1] },
+ q{==} => sub { $_[0]->{num} == $_[1] };
+
+package Overloaded::Ify;
+
+use strict;
+our @ISA = qw(Overloaded);
+
+use overload
+ q{""} => sub { $_[0]->{string} },
+ q{0+} => sub { $_[0]->{num} };
+
+1;
diff --git a/cpan/Test-Simple/t/lib/NoExporter.pm b/cpan/Test-Simple/t/lib/NoExporter.pm
new file mode 100644
index 0000000000..6273e32d74
--- /dev/null
+++ b/cpan/Test-Simple/t/lib/NoExporter.pm
@@ -0,0 +1,12 @@
+package NoExporter;
+
+use strict;
+our $VERSION = 1.02;
+
+sub import {
+ shift;
+ die "NoExporter exports nothing. You asked for: @_" if @_;
+}
+
+1;
+
diff --git a/cpan/Test-Simple/t/lib/SigDie.pm b/cpan/Test-Simple/t/lib/SigDie.pm
new file mode 100644
index 0000000000..0774728d4e
--- /dev/null
+++ b/cpan/Test-Simple/t/lib/SigDie.pm
@@ -0,0 +1,8 @@
+package SigDie;
+
+use strict;
+
+our $DIE;
+$SIG{__DIE__} = sub { $DIE = $@ };
+
+1;
diff --git a/cpan/Test-Simple/t/lib/Test/Builder/NoOutput.pm b/cpan/Test-Simple/t/lib/Test/Builder/NoOutput.pm
new file mode 100644
index 0000000000..d83db9f178
--- /dev/null
+++ b/cpan/Test-Simple/t/lib/Test/Builder/NoOutput.pm
@@ -0,0 +1,122 @@
+package Test::Builder::NoOutput;
+
+use strict;
+use warnings;
+
+use base qw(Test::Builder);
+
+
+=head1 NAME
+
+Test::Builder::NoOutput - A subclass of Test::Builder which prints nothing
+
+=head1 SYNOPSIS
+
+ use Test::Builder::NoOutput;
+
+ my $tb = Test::Builder::NoOutput->new;
+
+ ...test as normal...
+
+ my $output = $tb->read;
+
+=head1 DESCRIPTION
+
+This is a subclass of Test::Builder which traps all its output.
+It is mostly useful for testing Test::Builder.
+
+=head3 read
+
+ my $all_output = $tb->read;
+ my $output = $tb->read($stream);
+
+Returns all the output (including failure and todo output) collected
+so far. It is destructive, each call to read clears the output
+buffer.
+
+If $stream is given it will return just the output from that stream.
+$stream's are...
+
+ out output()
+ err failure_output()
+ todo todo_output()
+ all all outputs
+
+Defaults to 'all'.
+
+=cut
+
+my $Test = __PACKAGE__->new;
+
+sub create {
+ my $class = shift;
+ my $self = $class->SUPER::create(@_);
+
+ my %outputs = (
+ all => '',
+ out => '',
+ err => '',
+ todo => '',
+ );
+ $self->{_outputs} = \%outputs;
+
+ tie *OUT, "Test::Builder::NoOutput::Tee", \$outputs{all}, \$outputs{out};
+ tie *ERR, "Test::Builder::NoOutput::Tee", \$outputs{all}, \$outputs{err};
+ tie *TODO, "Test::Builder::NoOutput::Tee", \$outputs{all}, \$outputs{todo};
+
+ $self->output(*OUT);
+ $self->failure_output(*ERR);
+ $self->todo_output(*TODO);
+
+ return $self;
+}
+
+sub read {
+ my $self = shift;
+ my $stream = @_ ? shift : 'all';
+
+ my $out = $self->{_outputs}{$stream};
+
+ $self->{_outputs}{$stream} = '';
+
+ # Clear all the streams if 'all' is read.
+ if( $stream eq 'all' ) {
+ my @keys = keys %{$self->{_outputs}};
+ $self->{_outputs}{$_} = '' for @keys;
+ }
+
+ return $out;
+}
+
+
+package Test::Builder::NoOutput::Tee;
+
+# A cheap implementation of IO::Tee.
+
+sub TIEHANDLE {
+ my($class, @refs) = @_;
+
+ my @fhs;
+ for my $ref (@refs) {
+ my $fh = Test::Builder->_new_fh($ref);
+ push @fhs, $fh;
+ }
+
+ my $self = [@fhs];
+ return bless $self, $class;
+}
+
+sub PRINT {
+ my $self = shift;
+
+ print $_ @_ for @$self;
+}
+
+sub PRINTF {
+ my $self = shift;
+ my $format = shift;
+
+ printf $_ @_ for @$self;
+}
+
+1;
diff --git a/cpan/Test-Simple/t/lib/Test/Simple/Catch.pm b/cpan/Test-Simple/t/lib/Test/Simple/Catch.pm
new file mode 100644
index 0000000000..9a2efb192d
--- /dev/null
+++ b/cpan/Test-Simple/t/lib/Test/Simple/Catch.pm
@@ -0,0 +1,20 @@
+# For testing Test::Simple;
+package Test::Simple::Catch;
+
+use strict;
+
+use Symbol;
+use TieOut;
+my( $out_fh, $err_fh ) = ( gensym, gensym );
+my $out = tie *$out_fh, 'TieOut';
+my $err = tie *$err_fh, 'TieOut';
+
+use Test::Builder;
+my $t = Test::Builder->new;
+$t->output($out_fh);
+$t->failure_output($err_fh);
+$t->todo_output($err_fh);
+
+sub caught { return( $out, $err ) }
+
+1;
diff --git a/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/death.plx b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/death.plx
new file mode 100644
index 0000000000..e682ec08a2
--- /dev/null
+++ b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/death.plx
@@ -0,0 +1,16 @@
+require Test::Simple;
+
+push @INC, 't/lib';
+require Test::Simple::Catch;
+my($out, $err) = Test::Simple::Catch::caught();
+
+require Dev::Null;
+
+Test::Simple->import(tests => 5);
+tie *STDERR, 'Dev::Null';
+
+ok(1);
+ok(1);
+ok(1);
+$! = 0;
+die "This is a test";
diff --git a/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/death_in_eval.plx b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/death_in_eval.plx
new file mode 100644
index 0000000000..269bffa802
--- /dev/null
+++ b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/death_in_eval.plx
@@ -0,0 +1,22 @@
+require Test::Simple;
+use Carp;
+
+push @INC, 't/lib';
+require Test::Simple::Catch;
+my($out, $err) = Test::Simple::Catch::caught();
+
+Test::Simple->import(tests => 5);
+
+ok(1);
+ok(1);
+ok(1);
+eval {
+ die "Foo";
+};
+ok(1);
+eval "die 'Bar'";
+ok(1);
+
+eval {
+ croak "Moo";
+};
diff --git a/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/death_with_handler.plx b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/death_with_handler.plx
new file mode 100644
index 0000000000..7dabb31d60
--- /dev/null
+++ b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/death_with_handler.plx
@@ -0,0 +1,20 @@
+require Test::Simple;
+
+push @INC, 't/lib';
+require Test::Simple::Catch;
+my($out, $err) = Test::Simple::Catch::caught();
+
+Test::Simple->import(tests => 2);
+
+# Test we still get the right exit code despite having a die
+# handler.
+$SIG{__DIE__} = sub {};
+
+require Dev::Null;
+tie *STDERR, 'Dev::Null';
+
+ok(1);
+ok(1);
+
+$! = 0;
+die "This is a test";
diff --git a/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/exit.plx b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/exit.plx
new file mode 100644
index 0000000000..7f8ff73f75
--- /dev/null
+++ b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/exit.plx
@@ -0,0 +1,3 @@
+require Test::Builder;
+
+exit 1;
diff --git a/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/extras.plx b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/extras.plx
new file mode 100644
index 0000000000..c9c89520aa
--- /dev/null
+++ b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/extras.plx
@@ -0,0 +1,16 @@
+require Test::Simple;
+
+push @INC, 't/lib';
+require Test::Simple::Catch;
+my($out, $err) = Test::Simple::Catch::caught();
+
+Test::Simple->import(tests => 5);
+
+
+ok(1);
+ok(1);
+ok(1);
+ok(1);
+ok(0);
+ok(1);
+ok(0);
diff --git a/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/five_fail.plx b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/five_fail.plx
new file mode 100644
index 0000000000..c058e1f8f0
--- /dev/null
+++ b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/five_fail.plx
@@ -0,0 +1,13 @@
+require Test::Simple;
+
+use lib 't/lib';
+require Test::Simple::Catch;
+my($out, $err) = Test::Simple::Catch::caught();
+
+Test::Simple->import(tests => 5);
+
+ok(0);
+ok(0);
+ok('');
+ok(0);
+ok(0);
diff --git a/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/last_minute_death.plx b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/last_minute_death.plx
new file mode 100644
index 0000000000..e3d01beeb7
--- /dev/null
+++ b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/last_minute_death.plx
@@ -0,0 +1,19 @@
+require Test::Simple;
+
+push @INC, 't/lib';
+require Test::Simple::Catch;
+my($out, $err) = Test::Simple::Catch::caught();
+
+Test::Simple->import(tests => 5);
+
+require Dev::Null;
+tie *STDERR, 'Dev::Null';
+
+ok(1);
+ok(1);
+ok(1);
+ok(1);
+ok(1);
+
+$! = 0;
+die "This is a test";
diff --git a/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/one_fail.plx b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/one_fail.plx
new file mode 100644
index 0000000000..99c720250d
--- /dev/null
+++ b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/one_fail.plx
@@ -0,0 +1,14 @@
+require Test::Simple;
+
+push @INC, 't/lib';
+require Test::Simple::Catch;
+my($out, $err) = Test::Simple::Catch::caught();
+
+Test::Simple->import(tests => 5);
+
+
+ok(1);
+ok(2);
+ok(0);
+ok(1);
+ok(2);
diff --git a/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/pre_plan_death.plx b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/pre_plan_death.plx
new file mode 100644
index 0000000000..f72d3b65e5
--- /dev/null
+++ b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/pre_plan_death.plx
@@ -0,0 +1,17 @@
+# ID 20020716.013, the exit code would become 0 if the test died
+# before a plan.
+
+require Test::Simple;
+
+push @INC, 't/lib';
+require Test::Simple::Catch;
+my($out, $err) = Test::Simple::Catch::caught();
+
+close STDERR;
+die "Knife?";
+
+Test::Simple->import(tests => 3);
+
+ok(1);
+ok(1);
+ok(1);
diff --git a/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/require.plx b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/require.plx
new file mode 100644
index 0000000000..1a06690d9d
--- /dev/null
+++ b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/require.plx
@@ -0,0 +1 @@
+require Test::Simple;
diff --git a/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/success.plx b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/success.plx
new file mode 100644
index 0000000000..585d6c3d79
--- /dev/null
+++ b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/success.plx
@@ -0,0 +1,13 @@
+require Test::Simple;
+
+push @INC, 't/lib';
+require Test::Simple::Catch;
+my($out, $err) = Test::Simple::Catch::caught();
+
+Test::Simple->import(tests => 5);
+
+ok(1);
+ok(5, 'yep');
+ok(3, 'beer');
+ok("wibble", "wibble");
+ok(1);
diff --git a/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/too_few.plx b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/too_few.plx
new file mode 100644
index 0000000000..bbc630ddce
--- /dev/null
+++ b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/too_few.plx
@@ -0,0 +1,11 @@
+require Test::Simple;
+
+push @INC, 't/lib';
+require Test::Simple::Catch;
+my($out, $err) = Test::Simple::Catch::caught();
+
+Test::Simple->import(tests => 5);
+
+
+ok(1);
+ok(1);
diff --git a/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/too_few_fail.plx b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/too_few_fail.plx
new file mode 100644
index 0000000000..9ca4517b66
--- /dev/null
+++ b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/too_few_fail.plx
@@ -0,0 +1,12 @@
+require Test::Simple;
+
+push @INC, 't/lib';
+require Test::Simple::Catch;
+my($out, $err) = Test::Simple::Catch::caught();
+
+Test::Simple->import(tests => 5);
+
+
+ok(0);
+ok(1);
+ok(0);
diff --git a/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/two_fail.plx b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/two_fail.plx
new file mode 100644
index 0000000000..e3d92296af
--- /dev/null
+++ b/cpan/Test-Simple/t/lib/Test/Simple/sample_tests/two_fail.plx
@@ -0,0 +1,14 @@
+require Test::Simple;
+
+push @INC, 't/lib';
+require Test::Simple::Catch;
+my($out, $err) = Test::Simple::Catch::caught();
+
+Test::Simple->import(tests => 5);
+
+
+ok(0);
+ok(1);
+ok(1);
+ok(0);
+ok(1);
diff --git a/cpan/Test-Simple/t/lib/TieOut.pm b/cpan/Test-Simple/t/lib/TieOut.pm
new file mode 100644
index 0000000000..a08a9116ba
--- /dev/null
+++ b/cpan/Test-Simple/t/lib/TieOut.pm
@@ -0,0 +1,30 @@
+package TieOut;
+
+use strict;
+
+sub TIEHANDLE {
+ my $scalar = '';
+ bless( \$scalar, $_[0] );
+}
+
+sub PRINT {
+ my $self = shift;
+ $$self .= join( '', @_ );
+}
+
+sub PRINTF {
+ my $self = shift;
+ my $fmt = shift;
+ $$self .= sprintf $fmt, @_;
+}
+
+sub FILENO { }
+
+sub read {
+ my $self = shift;
+ my $data = $$self;
+ $$self = '';
+ return $data;
+}
+
+1;