File: num_method_tests.t

package info (click to toggle)
libtest-class-perl 0.35-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 476 kB
  • ctags: 102
  • sloc: perl: 1,668; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,746 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#! /usr/bin/perl -T

use strict;
use warnings;

package Foo; use base qw(Test::Class);
use Test::More;
use Test::Exception;

sub passN {
	my ($self, $n) = @_;
	my $m = $self->current_method;
	pass("$m just passing $_") foreach (1..$n);
};

sub new {
	my $class = shift;
	my $self = $class->SUPER::new(@_);
	is($self->num_method_tests('two_tests'), 2, 'fixed num tests');
	is($self->num_method_tests('no_plan_test'), 'no_plan', 'no_plan tests');
	throws_ok {$self->num_method_tests('fribble')} qr/not a test method/, 'cannot use non-method';
	throws_ok {$self->num_method_tests('no_plan_test', 'goobah')} qr/not valid number/, 'cannot update illegal value';
	lives_ok {$self->num_method_tests('no_plan_test', 2)} 'updated legal value';
	is($self->num_method_tests('no_plan_test'), 2, 'update worked');
	lives_ok {$self->num_method_tests('no_plan_test2', '+2')} 'updated extended';
	is($self->num_method_tests('no_plan_test2'), '+2', 'update worked');
	return($self);
};

sub two_tests : Test(2) {$_[0]->passN(2)};
sub no_plan_test : Test(no_plan) {$_[0]->passN(2)};
sub no_plan_test2 : Test(no_plan) {$_[0]->passN(2)};

package Bar; use base qw(Foo);
use Test::More;

sub no_plan_test : Test(+1) {pass("just passing"); $_[0]->SUPER::no_plan_test};

sub new {
	my $class = shift;
	my $self = $class->SUPER::new(@_);
	is($self->num_method_tests('no_plan_test'), '+1', 'extended method okay');
	return($self);
};


package main;
use Test::More tests => 19;
use Test::Exception;

my $tc = Bar->new;
is(Bar->expected_tests, 'no_plan', 'class expected_tests');
is($tc->expected_tests, 7, 'object expected_tests');
throws_ok {$tc->num_method_tests('two_tests')} qr/not called in a Test::Class/, 'num_method_tests dies outside test class';
$tc->runtests;