File: runtests.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 (70 lines) | stat: -rw-r--r-- 1,720 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#! /usr/bin/perl -T

use strict;
use warnings;

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


sub initialise1 :Test(setup) {
	my $self = shift;
	++$self->{initialise1};
};

sub initialise2 :Test(setup => 1) {
	my $self = shift;
	++$self->{initialise2};
	is($self->{initialise1}, $self->{initialise2}, "initialise2: methods ran in order");
};

sub test1 :Test(4) {
	my $self = shift;
	$self->{test}++;
	is($self->{initialise1}, 1, 'test1: initialise1 ran once');
	is($self->{initialise2}, 1, 'test1: initialise2 ran once');
	is($self->{test}, 1, 'test1: first test running');
	is($self->{teardown1}, undef, 'test1: teardown not run');
};


sub test2 : Test {
	fail("this failing tests should be overridden");
};


sub teardown1 :Test(teardown => 1) {
	my $self = shift;
	my $m = $self->current_method;
	is($self->{test}, $self->{initialise1}, "teardown1: setup run for every test");
};

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


sub test2 :Test(4) {
	my $self = shift;
	$self->{test}++;
	is($self->{initialise1}, 2, 'test2: initialise1 ran twice');
	is($self->{initialise2}, 2, 'test2: initialise2 ran twice');
	is($self->{test}, 2, 'test2: second test running');
	is($self->{teardown1}, 1, 'test2: teardown ran once');
};

sub teardown1 :Test(teardown => +3) {
	my $self = shift;
	my $m = $self->current_method;
	++$self->{teardown1};
	is($self->{test}, $self->{teardown1}, "teardown1: teardown run for every test");
	is($self->{initialise1}, $self->{teardown1}, "teardown1: teardown run for every initialise1");
	is($self->{initialise2}, $self->{teardown1}, "teardown1: teardown run for every initialise2");
	$self->SUPER::teardown1;
};

package main;
use Test::More tests => 18;

Bar->new->runtests;