49
|
1 package IMPL::Test;
|
|
2 use strict;
|
|
3 use warnings;
|
|
4
|
84
|
5 require IMPL::Test::SkipException;
|
|
6
|
49
|
7 require Exporter;
|
|
8 our @ISA = qw(Exporter);
|
159
|
9 our @EXPORT_OK = qw(&test &shared &failed &cmparray &skip &run_plan);
|
49
|
10
|
|
11 require IMPL::Test::Unit;
|
159
|
12 require IMPL::Test::Plan;
|
|
13 require IMPL::Test::TAPListener;
|
49
|
14 use IMPL::Class::Member;
|
|
15
|
|
16 sub test($$) {
|
|
17 my ($name,$code) = @_;
|
|
18 my $class = caller;
|
|
19
|
|
20 $class->set_meta(
|
|
21 new IMPL::Test::Unit::TestInfo( $name, $code )
|
|
22 );
|
|
23 }
|
|
24
|
|
25 sub shared($) {
|
|
26 my ($propInfo) = @_;
|
|
27
|
|
28 my $class = caller;
|
|
29
|
|
30 die new IMPL::Exception("Only properties could be declared as shared",$propInfo->Name) unless eval {$propInfo->isa('IMPL::Class::PropertyInfo')};
|
|
31 die new IMPL::Exception("You can't mark the readonly property as shared",$propInfo->Name) unless $propInfo->canSet;
|
|
32 die new IMPL::Exception("Only public properties could be declared as shared",$propInfo->Name) unless $propInfo->Access == IMPL::Class::Member::MOD_PUBLIC;
|
|
33
|
|
34 $class->set_meta(new IMPL::Test::Unit::SharedData($propInfo->Name));
|
|
35 }
|
|
36
|
|
37 sub failed($;@) {
|
|
38 die new IMPL::Test::FailException(@_);
|
|
39 }
|
|
40
|
84
|
41 sub skip($;@) {
|
|
42 die new IMPL::Test::SkipException(@_);
|
|
43 }
|
|
44
|
49
|
45 sub cmparray {
|
|
46 my ($a,$b) = @_;
|
|
47
|
|
48 return 0 unless @$a == @$b;
|
|
49
|
|
50 for (my $i=0; $i < @$a; $i++ ) {
|
|
51 return 0 unless $a->[$i] eq $b->[$i];
|
|
52 }
|
|
53
|
|
54 return 1;
|
|
55 }
|
159
|
56
|
|
57 sub run_plan {
|
|
58 my (@units) = @_;
|
|
59
|
|
60 my $plan = new IMPL::Test::Plan(@units);
|
|
61
|
|
62 $plan->Prepare;
|
|
63 $plan->AddListener(new IMPL::Test::TAPListener);
|
|
64 $plan->Run;
|
|
65 }
|
49
|
66 1;
|