annotate Lib/IMPL/Test.pm @ 329:50ff1595bd62

fixed bug when transforming list properties
author sergey
date Mon, 03 Jun 2013 18:03:54 +0400
parents 546957c50a36
children
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
285
546957c50a36 *IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents: 278
diff changeset
5 use IMPL::lang qw(equals_s);
278
4ddb27ff4a0b core refactoring
cin
parents: 275
diff changeset
6 use IMPL::Const qw(:access);
84
e568c7c8b743 Minor changes to the test infrastructure
wizard
parents: 49
diff changeset
7 require IMPL::Test::SkipException;
e568c7c8b743 Minor changes to the test infrastructure
wizard
parents: 49
diff changeset
8
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
9 require Exporter;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
10 our @ISA = qw(Exporter);
285
546957c50a36 *IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents: 278
diff changeset
11 our @EXPORT_OK = qw(&test &shared &failed &cmparray &skip &run_plan &assert &assertarray &GetCallerSourceLine);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
12
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
13 require IMPL::Test::Unit;
159
f8de52d3c112 IMPL::Test::Unit minor changes
wizard
parents: 84
diff changeset
14 require IMPL::Test::Plan;
f8de52d3c112 IMPL::Test::Unit minor changes
wizard
parents: 84
diff changeset
15 require IMPL::Test::TAPListener;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
16
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
17 sub test($$) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
18 my ($name,$code) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
19 my $class = caller;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
20
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
21 $class->set_meta(
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
22 new IMPL::Test::Unit::TestInfo( $name, $code )
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
26 sub shared($) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
27 my ($propInfo) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
28
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
29 my $class = caller;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
30
275
6253872024a4 *refactoring IMPL::Class
cin
parents: 194
diff changeset
31 die new IMPL::Exception("Only properties could be declared as shared",$propInfo->name) unless eval {$propInfo->isa('IMPL::Class::PropertyInfo')};
278
4ddb27ff4a0b core refactoring
cin
parents: 275
diff changeset
32 die new IMPL::Exception("You can't mark the readonly property as shared",$propInfo->name) unless $propInfo->setter;
4ddb27ff4a0b core refactoring
cin
parents: 275
diff changeset
33 die new IMPL::Exception("Only public properties could be declared as shared",$propInfo->name) unless $propInfo->access == ACCESS_PUBLIC;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
34
275
6253872024a4 *refactoring IMPL::Class
cin
parents: 194
diff changeset
35 $class->set_meta(new IMPL::Test::Unit::SharedData($propInfo->name));
49
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
38 sub failed($;@) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
39 die new IMPL::Test::FailException(@_);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
40 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
41
165
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
42 sub assert {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
43 my ($condition,@params) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
44
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
45 die new IMPL::Test::FailException(@params ? @params : ("Assertion failed" , _GetSourceLine( (caller)[1,2] )) ) unless $condition;
165
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
46 }
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
47
84
e568c7c8b743 Minor changes to the test infrastructure
wizard
parents: 49
diff changeset
48 sub skip($;@) {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
49 die new IMPL::Test::SkipException(@_);
84
e568c7c8b743 Minor changes to the test infrastructure
wizard
parents: 49
diff changeset
50 }
e568c7c8b743 Minor changes to the test infrastructure
wizard
parents: 49
diff changeset
51
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
52 sub cmparray {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
53 my ($a,$b) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
54
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
55 return 0 unless @$a == @$b;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
56
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
57 for (my $i=0; $i < @$a; $i++ ) {
285
546957c50a36 *IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents: 278
diff changeset
58 return 0 unless
546957c50a36 *IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents: 278
diff changeset
59 equals_s($a->[$i], $b->[$i]);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
60 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
61
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
62 return 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
63 }
159
f8de52d3c112 IMPL::Test::Unit minor changes
wizard
parents: 84
diff changeset
64
285
546957c50a36 *IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents: 278
diff changeset
65 sub assertarray {
546957c50a36 *IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents: 278
diff changeset
66 my ($a,$b) = @_;
546957c50a36 *IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents: 278
diff changeset
67
546957c50a36 *IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents: 278
diff changeset
68
546957c50a36 *IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents: 278
diff changeset
69 die IMPL::Test::FailException->new(
546957c50a36 *IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents: 278
diff changeset
70 "Assert arrays failed",
546957c50a36 *IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents: 278
diff changeset
71 _GetSourceLine( (caller)[1,2] ),
546957c50a36 *IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents: 278
diff changeset
72 join(', ', map defined($_) ? $_ : '<undef>', @$a),
546957c50a36 *IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents: 278
diff changeset
73 join(', ', map defined($_) ? $_ : '<undef>', @$b)
546957c50a36 *IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents: 278
diff changeset
74 )
546957c50a36 *IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents: 278
diff changeset
75 unless cmparray($a,$b);
546957c50a36 *IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents: 278
diff changeset
76 }
546957c50a36 *IMPL::Web::Handler::TTView Reworked template selection mechanism
cin
parents: 278
diff changeset
77
165
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
78 sub _GetSourceLine {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
79 my ($file,$line) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
80
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
81 open my $hFile, $file or return "failed to open file: $file: $!";
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
82
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
83 my $text;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
84 $text = <$hFile> for ( 1 .. $line);
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
85 chomp $text;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
86 $text =~ s/^\s+//;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
87 return "line $line: $text";
165
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
88 }
76515373dac0 Added Class::Template,
wizard
parents: 159
diff changeset
89
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 165
diff changeset
90 sub GetCallerSourceLine {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
91 my $line = shift || 0;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
92 return _GetSourceLine( (caller($line + 1))[1,2] )
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 165
diff changeset
93 }
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 165
diff changeset
94
159
f8de52d3c112 IMPL::Test::Unit minor changes
wizard
parents: 84
diff changeset
95 sub run_plan {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
96 my (@units) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
97
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
98 my $plan = new IMPL::Test::Plan(@units);
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
99
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
100 $plan->Prepare;
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
101 $plan->AddListener(new IMPL::Test::TAPListener);
4d0e1962161c Replaced tabs with spaces
cin
parents: 188
diff changeset
102 $plan->Run;
159
f8de52d3c112 IMPL::Test::Unit minor changes
wizard
parents: 84
diff changeset
103 }
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 3
diff changeset
104 1;