File: 19-subrequest.t

package info (click to toggle)
libhtml-mason-perl 1%3A1.26-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,636 kB
  • ctags: 1,260
  • sloc: perl: 13,880; sh: 154; makefile: 47
file content (316 lines) | stat: -rw-r--r-- 7,851 bytes parent folder | download
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#!/usr/bin/perl -w

use strict;
use HTML::Mason::Tests;

my $tests = make_tests();
$tests->run;

sub make_tests
{
    my $group = HTML::Mason::Tests->tests_class->new( name => 'subrequest',
						      description => 'subrequest-related features' );

#------------------------------------------------------------

    $group->add_support( path => '/support/subrequest_error_test',
			 component => <<'EOF',
<& /shared/display_req_obj &>
% die "whoops!";
EOF
		       );

#------------------------------------------------------------


    $group->add_support( path => '/support/dir/autohandler',
			 component => <<'EOF',
I am the autohandler.
EOF
		       );

#------------------------------------------------------------

    $group->add_support( path => '/support/dir/comp',
			 component => <<'EOF',
I am the called comp (no autohandler).
EOF
		       );

#------------------------------------------------------------

    $group->add_test( name => 'subrequest',
		      description => 'tests the official subrequest mechanism',
		      component => <<'EOF',
<%def .helper>
Executing subrequest
% print "I can print before the subrequest\n";
% my $buf;
% my $req = $m->make_subrequest(comp=>'/shared/display_req_obj', out_method => \$buf);
% $req->exec();
<% $buf %>
% print "I can still print after the subrequest\n";
</%def>

Calling helper
<& .helper &>
EOF
		      expect => <<'EOF',

Calling helper

Executing subrequest
I can print before the subrequest
My depth is 1.

The top-level component is /shared/display_req_obj.

My stack looks like:
-----
/shared/display_req_obj
-----


I can still print after the subrequest
EOF
		    );


#------------------------------------------------------------

    $group->add_test( name => 'subrequest_with_autohandler',
		      description => 'tests the subrequest mechanism with an autohandler',
		      component => <<'EOF',
Executing subrequest
% my $buf;
% my $req = $m->make_subrequest(comp=>'/subrequest/support/dir/comp', out_method => \$buf);
% $req->exec();
<% $buf %>
EOF
		      expect => <<'EOF',
Executing subrequest
I am the autohandler.
EOF
		    );


#------------------------------------------------------------

    $group->add_support( path => '/subrequest2/autohandler',
			 component => <<'EOF',
I am the autohandler for <% $m->base_comp->name %>.
% $m->call_next;
<%flags>
inherit => undef
</%flags>
EOF
		       );

#------------------------------------------------------------

    $group->add_support( path => '/subrequest2/bar',
			 component => <<'EOF',
I am bar.
EOF
		       );

#------------------------------------------------------------

    $group->add_test( name => 'subreq_exec_order',
		      path => '/subrequest2/subreq_exec_order',
		      call_path => '/subrequest2/subreq_exec_order',
		      description => 'Test that output from a subrequest comes out when we expect it to.',
		      component => <<'EOF',
% $m->subexec('/subrequest/subrequest2/bar');
I am subreq_exec_order.
EOF
		      expect => <<'EOF',
I am the autohandler for subreq_exec_order.
I am the autohandler for bar.
I am bar.
I am subreq_exec_order.
EOF
		    );

#------------------------------------------------------------

    $group->add_support( path => '/support/autoflush_subrequest',
			 component => <<'EOF',
here is the child
% $m->clear_buffer;
EOF
		       );

#------------------------------------------------------------

    $group->add_test( name => 'autoflush_subrequest',
		      description => 'make sure that a subrequest respects its parent autoflush setting',
		      interp_params => { autoflush => 1 },
		      component => <<'EOF',
My child says:
% $m->subexec('/subrequest/support/autoflush_subrequest');
EOF
		      expect => <<'EOF',
My child says:
here is the child
EOF
		    );

#------------------------------------------------------------

    $group->add_test( name => 'no_autoflush_subrequest',
		      description => 'make sure that a subrequest respects its parent autoflush setting',
		      interp_params => { autoflush => 0 },
		      component => <<'EOF',
My child says:
% $m->subexec('/subrequest/support/autoflush_subrequest');
EOF
		      expect => <<'EOF',
My child says:
EOF
		    );

#------------------------------------------------------------

    $group->add_support( path => '/support/return/scalar',
			 component => <<'EOF',
% die "wantarray should be false" unless defined(wantarray) and !wantarray;
% return 'foo';
EOF
		       );

#------------------------------------------------------------

    $group->add_test( name => 'return_scalar',
		      description => 'tests that exec returns scalar return value of top component',
		      component => <<'EOF',
% my $req = $m->make_subrequest(comp=>'/subrequest/support/return/scalar');
% my $value = $req->exec();
return value is <% $value %>
EOF
		      expect => <<'EOF',
return value is foo
EOF
		    );


#------------------------------------------------------------

    $group->add_support( path => '/support/return/list',
			 component => <<'EOF',
% die "wantarray should be true" unless wantarray;
% return (1, 2, 3);
EOF
		       );

#------------------------------------------------------------

    $group->add_test( name => 'return_list',
		      description => 'tests that exec returns list return value of top component',
		      component => <<'EOF',
% my $req = $m->make_subrequest(comp=>'/subrequest/support/return/list');
% my @value = $req->exec();
return value is <% join(",", @value) %>
EOF
		      expect => <<'EOF',
return value is 1,2,3
EOF
		    );


#------------------------------------------------------------

    $group->add_support( path => '/support/return/nothing',
			 component => <<'EOF',
wantarray is <% defined(wantarray) ? "defined" : "undefined" %>
EOF
		       );

#------------------------------------------------------------

    $group->add_test( name => 'return_nothing',
		      description => 'tests exec in non-return context',
		      component => <<'EOF',
% my $req = $m->make_subrequest(comp=>'/subrequest/support/return/nothing');
% $req->exec();
EOF
		      expect => <<'EOF',
wantarray is undefined
EOF
		    );


#------------------------------------------------------------

    $group->add_support( path => '/support/output',
			 component => <<'EOF',
More output
EOF
		       );

#------------------------------------------------------------

    $group->add_test( name => 'kwindla',
		      description => 'tests bug report from Kwindla Kramer',
		      component => <<'EOF',
Some output
% $m->clear_buffer;
% my $req = $m->make_subrequest( comp => '/subrequest/support/output' );
% $req->exec();
% $m->flush_buffer;
% $m->abort;
EOF
		      expect => <<'EOF',
More output
EOF
		    );


#------------------------------------------------------------

    $group->add_test( name => 'in_package',
		      description => 'use in_package with subrequest',
                      interp_params => { in_package => 'Test::Package' },
		      component => <<'EOF',
Before subreq
% $m->subexec( '/subrequest/support/output' );
After subreq
EOF
		      expect => <<'EOF',
Before subreq
More output
After subreq
EOF
		    );


#------------------------------------------------------------

    $group->add_test( name => 'relative_path_call',
		      description => 'call subrequest with relative path',
		      component => <<'EOF',
% $m->subexec( 'support/output' );
EOF
		      expect => <<'EOF',
More output
EOF
		    );


#------------------------------------------------------------

    $group->add_test( name => 'comp_object_call',
		      description => 'call subrequest with component object',
		      component => <<'EOF',
% $m->subexec( $m->interp->load('/subrequest/support/output') );
EOF
		      expect => <<'EOF',
More output
EOF
		    );


#------------------------------------------------------------

    return $group;
}