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);
|
84
|
9 our @EXPORT_OK = qw(&test &shared &failed &cmparray &skip);
|
49
|
10
|
|
11 require IMPL::Test::Unit;
|
|
12 use IMPL::Class::Member;
|
|
13
|
|
14 sub test($$) {
|
|
15 my ($name,$code) = @_;
|
|
16 my $class = caller;
|
|
17
|
|
18 $class->set_meta(
|
|
19 new IMPL::Test::Unit::TestInfo( $name, $code )
|
|
20 );
|
|
21 }
|
|
22
|
|
23 sub shared($) {
|
|
24 my ($propInfo) = @_;
|
|
25
|
|
26 my $class = caller;
|
|
27
|
|
28 die new IMPL::Exception("Only properties could be declared as shared",$propInfo->Name) unless eval {$propInfo->isa('IMPL::Class::PropertyInfo')};
|
|
29 die new IMPL::Exception("You can't mark the readonly property as shared",$propInfo->Name) unless $propInfo->canSet;
|
|
30 die new IMPL::Exception("Only public properties could be declared as shared",$propInfo->Name) unless $propInfo->Access == IMPL::Class::Member::MOD_PUBLIC;
|
|
31
|
|
32 $class->set_meta(new IMPL::Test::Unit::SharedData($propInfo->Name));
|
|
33 }
|
|
34
|
|
35 sub failed($;@) {
|
|
36 die new IMPL::Test::FailException(@_);
|
|
37 }
|
|
38
|
84
|
39 sub skip($;@) {
|
|
40 die new IMPL::Test::SkipException(@_);
|
|
41 }
|
|
42
|
49
|
43 sub cmparray {
|
|
44 my ($a,$b) = @_;
|
|
45
|
|
46 return 0 unless @$a == @$b;
|
|
47
|
|
48 for (my $i=0; $i < @$a; $i++ ) {
|
|
49 return 0 unless $a->[$i] eq $b->[$i];
|
|
50 }
|
|
51
|
|
52 return 1;
|
|
53 }
|
|
54 1;
|