annotate Lib/IMPL/Test.pm @ 178:658a80d19d33

new constructor syntax
author sourcer
date Wed, 12 Oct 2011 00:06:07 +0300
parents 76515373dac0
children 029c9610528c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
1 package IMPL::Test;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
4
84
e568c7c8b743 Minor changes to the test infrastructure
wizard
parents: 49
diff changeset
5 require IMPL::Test::SkipException;
e568c7c8b743 Minor changes to the test infrastructure
wizard
parents: 49
diff changeset
6
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
7 require Exporter;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
8 our @ISA = qw(Exporter);
165
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
9 our @EXPORT_OK = qw(&test &shared &failed &cmparray &skip &run_plan &assert);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
10
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
11 require IMPL::Test::Unit;
159
f8de52d3c112 IMPL::Test::Unit minor changes
wizard
parents: 84
diff changeset
12 require IMPL::Test::Plan;
f8de52d3c112 IMPL::Test::Unit minor changes
wizard
parents: 84
diff changeset
13 require IMPL::Test::TAPListener;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
14 use IMPL::Class::Member;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
15
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
16 sub test($$) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
17 my ($name,$code) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
18 my $class = caller;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
19
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
20 $class->set_meta(
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
21 new IMPL::Test::Unit::TestInfo( $name, $code )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
22 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
23 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
24
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
25 sub shared($) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
26 my ($propInfo) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
27
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
28 my $class = caller;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
29
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
30 die new IMPL::Exception("Only properties could be declared as shared",$propInfo->Name) unless eval {$propInfo->isa('IMPL::Class::PropertyInfo')};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
31 die new IMPL::Exception("You can't mark the readonly property as shared",$propInfo->Name) unless $propInfo->canSet;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
32 die new IMPL::Exception("Only public properties could be declared as shared",$propInfo->Name) unless $propInfo->Access == IMPL::Class::Member::MOD_PUBLIC;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
33
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
34 $class->set_meta(new IMPL::Test::Unit::SharedData($propInfo->Name));
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
35 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
36
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
37 sub failed($;@) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
38 die new IMPL::Test::FailException(@_);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
39 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
40
165
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
41 sub assert {
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
42 my ($condition,@params) = @_;
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
43
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
44 die new IMPL::Test::FailException(@params ? @params : ("Assertion failed" , _GetSourceLine( (caller)[1,2] )) ) unless $condition;
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
45 }
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
46
84
e568c7c8b743 Minor changes to the test infrastructure
wizard
parents: 49
diff changeset
47 sub skip($;@) {
e568c7c8b743 Minor changes to the test infrastructure
wizard
parents: 49
diff changeset
48 die new IMPL::Test::SkipException(@_);
e568c7c8b743 Minor changes to the test infrastructure
wizard
parents: 49
diff changeset
49 }
e568c7c8b743 Minor changes to the test infrastructure
wizard
parents: 49
diff changeset
50
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
51 sub cmparray {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
52 my ($a,$b) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
53
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
54 return 0 unless @$a == @$b;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
55
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
56 for (my $i=0; $i < @$a; $i++ ) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
57 return 0 unless $a->[$i] eq $b->[$i];
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
58 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
59
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
60 return 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
61 }
159
f8de52d3c112 IMPL::Test::Unit minor changes
wizard
parents: 84
diff changeset
62
165
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
63 sub _GetSourceLine {
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
64 my ($file,$line) = @_;
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
65
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
66 open my $hFile, $file or return "failed to open file: $file: $!";
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
67
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
68 my $text;
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
69 $text = <$hFile> for ( 1 .. $line);
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
70 chomp $text;
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
71 $text =~ s/^\s+//;
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
72 return "line $line: $text";
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
73 }
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
74
159
f8de52d3c112 IMPL::Test::Unit minor changes
wizard
parents: 84
diff changeset
75 sub run_plan {
f8de52d3c112 IMPL::Test::Unit minor changes
wizard
parents: 84
diff changeset
76 my (@units) = @_;
f8de52d3c112 IMPL::Test::Unit minor changes
wizard
parents: 84
diff changeset
77
f8de52d3c112 IMPL::Test::Unit minor changes
wizard
parents: 84
diff changeset
78 my $plan = new IMPL::Test::Plan(@units);
f8de52d3c112 IMPL::Test::Unit minor changes
wizard
parents: 84
diff changeset
79
f8de52d3c112 IMPL::Test::Unit minor changes
wizard
parents: 84
diff changeset
80 $plan->Prepare;
f8de52d3c112 IMPL::Test::Unit minor changes
wizard
parents: 84
diff changeset
81 $plan->AddListener(new IMPL::Test::TAPListener);
f8de52d3c112 IMPL::Test::Unit minor changes
wizard
parents: 84
diff changeset
82 $plan->Run;
f8de52d3c112 IMPL::Test::Unit minor changes
wizard
parents: 84
diff changeset
83 }
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
84 1;