Added test of field schema shortcut and table stringify.
[dbsrgits/SQL-Translator.git] / t / 13schema.t
1 #!/usr/bin/perl
2 # vim:set ft=perl:
3
4 $| = 1;
5
6 use strict;
7 use Test::More tests => 199;
8 use SQL::Translator::Schema::Constants;
9
10 require_ok( 'SQL::Translator::Schema' );
11
12 {
13     #
14     # Schema
15     #
16     my $schema = SQL::Translator::Schema->new( 
17         name => 'foo',
18         database => 'MySQL',
19     );
20     isa_ok( $schema, 'SQL::Translator::Schema' );
21
22     is( $schema->name, 'foo', 'Schema name is "foo"' );
23     is( $schema->name('bar'), 'bar', 'Schema name changed to "bar"' );
24
25     is( $schema->database, 'MySQL', 'Schema database is "MySQL"' );
26     is( $schema->database('PostgreSQL'), 'PostgreSQL', 
27         'Schema database changed to "PostgreSQL"' );
28
29     is( $schema->is_valid, undef, 'Schema not valid...' );
30     like( $schema->error, qr/no tables/i, '...because there are no tables' );
31
32     #
33     # $schema->add_*
34     #
35     my $foo_table = $schema->add_table(name => 'foo') or warn $schema->error;
36     isa_ok( $foo_table, 'SQL::Translator::Schema::Table', 'Table "foo"' );
37
38     my $bar_table = SQL::Translator::Schema::Table->new( name => 'bar' ) or 
39         warn SQL::Translator::Schema::Table->error;
40     $bar_table = $schema->add_table( $bar_table );
41     isa_ok( $bar_table, 'SQL::Translator::Schema::Table', 'Table "bar"' );
42     is( $bar_table->name, 'bar', 'Add table "bar"' );
43
44     $schema = $bar_table->schema( $schema );
45     isa_ok( $schema, 'SQL::Translator::Schema', 'Schema' );
46
47     is( $bar_table->name('foo'), undef, 
48         q[Can't change name of table "bar" to "foo"...]);
49     like( $bar_table->error, qr/can't use table name/i, 
50         q[...because "foo" exists] );
51
52     my $redundant_table = $schema->add_table(name => 'foo');
53     is( $redundant_table, undef, qq[Can't create another "foo" table...] );
54     like( $schema->error, qr/can't use table name/i, 
55         '... because "foo" exists' );
56
57     $redundant_table = $schema->add_table(name => '');
58     is( $redundant_table, undef, qq[Can't add an anonymouse table...] );
59     like( $schema->error, qr/No table name/i,
60         '... because if has no name ' );
61
62     $redundant_table = SQL::Translator::Schema::Table->new(name => '');
63     is( $redundant_table, undef, qq[Can't create an anonymouse table] );
64     like( SQL::Translator::Schema::Table->error, qr/No table name/i,
65         '... because if has no name ' );
66
67     #
68     # Table default new
69     #
70     is( $foo_table->name, 'foo', 'Table name is "foo"' );
71     is( "$foo_table", 'foo', 'Table stringifies to "foo"' );
72     is( $foo_table->is_valid, undef, 'Table "foo" is not yet valid' );
73
74     my $fields = $foo_table->get_fields;
75     is( scalar @{ $fields || [] }, 0, 'Table "foo" has no fields' );
76     like( $foo_table->error, qr/no fields/i, 'Error for no fields' );
77
78     is( $foo_table->comments, undef, 'No comments' );
79
80     #
81     # New table with args
82     #
83     my $person_table = $schema->add_table( 
84         name     => 'person', 
85         comments => 'foo',
86     );
87     is( $person_table->name, 'person', 'Table name is "person"' );
88     is( $person_table->is_valid, undef, 'Table is not yet valid' );
89     is( $person_table->comments, 'foo', 'Comments = "foo"' );
90     is( join(',', $person_table->comments('bar')), 'foo,bar', 
91         'Table comments = "foo,bar"' );
92     is( $person_table->comments, "foo\nbar", 'Table comments = "foo,bar"' );
93
94     #
95     # Field default new
96     #
97     my $f1 = $person_table->add_field(name => 'foo') or 
98         warn $person_table->error;
99     isa_ok( $f1, 'SQL::Translator::Schema::Field', 'Field' );
100     is( $f1->name, 'foo', 'Field name is "foo"' );
101     is( $f1->full_name, 'person.foo', 'Field full_name is "person.foo"' );
102     is( "$f1", 'foo', 'Field stringifies to "foo"' );
103     is( $f1->data_type, '', 'Field data type is blank' );
104     is( $f1->size, 0, 'Field size is "0"' );
105     is( $f1->is_primary_key, '0', 'Field is_primary_key is false' );
106     is( $f1->is_nullable, 1, 'Field can be NULL' );
107     is( $f1->default_value, undef, 'Field default is undefined' );
108     is( $f1->comments, '', 'No comments' );
109     is( $f1->table, 'person', 'Field table is person' );
110     is( $f1->schema->database, 'PostgreSQL', 'Field schema shortcut works' );
111
112     my $f2 = SQL::Translator::Schema::Field->new (
113         name     => 'f2',
114         comments => 'foo',
115     ) or warn SQL::Translator::Schema::Field->error;
116     $f2 = $person_table->add_field( $f2 );
117     isa_ok( $f1, 'SQL::Translator::Schema::Field', 'f2' );
118     is( $f2->name, 'f2', 'Add field "f2"' );
119     is( $f2->is_nullable(0), 0, 'Field cannot be NULL' );
120     is( $f2->is_nullable(''), 0, 'Field cannot be NULL' );
121     is( $f2->is_nullable('0'), 0, 'Field cannot be NULL' );
122     is( $f2->default_value(''), '', 'Field default is empty string' );
123     is( $f2->comments, 'foo', 'Field comment = "foo"' );
124     is( join(',', $f2->comments('bar')), 'foo,bar', 
125         'Field comment = "foo,bar"' );
126     is( $f2->comments, "foo\nbar", 'Field comment = "foo,bar"' );
127
128     $person_table = $f2->table( $person_table );
129     isa_ok( $person_table, 'SQL::Translator::Schema::Table', 'person_table' );
130
131     is( $f2->name('foo'), undef, q[Can't set field name of "f2" to "foo"...] );
132     like( $f2->error, qr/can't use field name/i, '...because name exists' );
133
134     my $redundant_field = $person_table->add_field(name => 'f2');
135     is( $redundant_field, undef, qq[Didn't create another "f2" field...] );
136     like( $person_table->error, qr/can't use field/i, 
137         '... because it exists' );
138
139     $redundant_field = $person_table->add_field(name => '');
140     is( $redundant_field, undef, qq[Didn't add a "" field...] );
141     like( $person_table->error, qr/No field name/i,
142         '... because it has no name' );
143
144     $redundant_field = SQL::Translator::Schema::Field->new(name => '');
145     is( $redundant_field, undef, qq[Didn't create a "" field...] );
146     like( SQL::Translator::Schema::Field->error, qr/No field name/i,
147         '... because it has no name' );
148
149     my @fields = $person_table->get_fields;
150     is( scalar @fields, 2, 'Table "foo" has 2 fields' );
151
152     is( $fields[0]->name, 'foo', 'First field is "foo"' );
153     is( $fields[1]->name, 'f2', 'Second field is "f2"' );
154
155     #
156     # Field methods
157     #
158     is( $f1->name('person_name'), 'person_name',
159         'Field name is "person_name"' );
160     is( $f1->data_type('varchar'), 'varchar', 'Field data type is "varchar"' );
161     is( $f1->size('30'), '30', 'Field size is "30"' );
162     is( $f1->is_primary_key(0), '0', 'Field is_primary_key is negative' );
163
164     $f1->extra( foo => 'bar' );
165     $f1->extra( { baz => 'quux' } );
166     my %extra = $f1->extra;
167     is( $extra{'foo'}, 'bar', 'Field extra "foo" is "bar"' );
168     is( $extra{'baz'}, 'quux', 'Field extra "baz" is "quux"' );
169
170     #
171     # New field with args
172     #
173     my $age       = $person_table->add_field(
174         name      => 'age',
175         data_type => 'float',
176         size      => '10,2',
177     );
178     is( $age->name, 'age', 'Field name is "age"' );
179     is( $age->data_type, 'float', 'Field data type is "float"' );
180     is( $age->size, '10,2', 'Field size is "10,2"' );
181     is( $age->size(10,2), '10,2', 'Field size still "10,2"' );
182     is( $age->size([10,2]), '10,2', 'Field size still "10,2"' );
183     is( $age->size(qw[ 10 2 ]), '10,2', 'Field size still "10,2"' );
184     is( join(':', $age->size), '10:2', 'Field size returns array' );
185
186     #
187     # Index
188     #
189     my @indices = $person_table->get_indices;
190     is( scalar @indices, 0, 'No indices' );
191     like( $person_table->error, qr/no indices/i, 'Error for no indices' );
192     my $index1 = $person_table->add_index( name => "foo" ) 
193         or warn $person_table->error;
194     isa_ok( $index1, 'SQL::Translator::Schema::Index', 'Index' );
195     is( $index1->name, 'foo', 'Index name is "foo"' );
196
197     is( $index1->is_valid, undef, 'Index name is not valid...' );
198     like( $index1->error, qr/no fields/i, '...because it has no fields' );
199
200     is( join(':', $index1->fields('foo,bar')), 'foo:bar', 
201         'Index accepts fields');
202
203     is( $index1->is_valid, undef, 'Index name is not valid...' );
204     like( $index1->error, qr/does not exist in table/i, 
205         '...because it used fields not in the table' );
206
207     is( join(':', $index1->fields(qw[foo age])), 'foo:age', 
208         'Index accepts fields');
209     is( $index1->is_valid, 1, 'Index name is now valid' );
210
211     is( $index1->type, NORMAL, 'Index type is "normal"' );
212
213     my $index2 = SQL::Translator::Schema::Index->new( name => "bar" ) 
214         or warn SQL::Translator::Schema::Index->error;
215     $index2    = $person_table->add_index( $index2 );
216     isa_ok( $index2, 'SQL::Translator::Schema::Index', 'Index' );
217     is( $index2->name, 'bar', 'Index name is "bar"' );
218
219     my $indices = $person_table->get_indices;
220     is( scalar @$indices, 2, 'Two indices' );
221     is( $indices->[0]->name, 'foo', '"foo" index' );
222     is( $indices->[1]->name, 'bar', '"bar" index' );
223
224     #
225     # Constraint
226     #
227     my @constraints = $person_table->get_constraints;
228     is( scalar @constraints, 0, 'No constraints' );
229     like( $person_table->error, qr/no constraints/i, 
230         'Error for no constraints' );
231     my $constraint1 = $person_table->add_constraint( name => 'foo' ) 
232         or warn $person_table->error;
233     isa_ok( $constraint1, 'SQL::Translator::Schema::Constraint', 'Constraint' );
234     is( $constraint1->name, 'foo', 'Constraint name is "foo"' );
235
236     $fields = join(',', $constraint1->fields('id') );
237     is( $fields, 'id', 'Constraint field = "id"' );
238
239     $fields = join(',', $constraint1->fields('id,id') );
240     is( $fields, 'id', 'Constraint field = "id"' );
241
242     $fields = join(',', $constraint1->fields('id', 'name') );
243     is( $fields, 'id,name', 'Constraint field = "id,name"' );
244
245     $fields = join(',', $constraint1->fields( 'id,name,id' ) );
246     is( $fields, 'id,name', 'Constraint field = "id,name"' );
247
248     $fields = join(',', $constraint1->fields( 'id, name' ) );
249     is( $fields, 'id,name', 'Constraint field = "id,name"' );
250
251     $fields = join(',', $constraint1->fields( [ 'id', 'name' ] ) );
252     is( $fields, 'id,name', 'Constraint field = "id,name"' );
253
254     $fields = join(',', $constraint1->fields( qw[ id name ] ) );
255     is( $fields, 'id,name', 'Constraint field = "id,name"' );
256
257     is( $constraint1->match_type, '', 'Constraint match type is empty' );
258     is( $constraint1->match_type('foo'), undef, 
259         'Constraint match type rejects bad arg...' );
260     like( $constraint1->error, qr/invalid match type/i,
261         '...because it is invalid');
262     is( $constraint1->match_type('FULL'), 'full', 
263         'Constraint match type = "full"' );
264
265     my $constraint2 = SQL::Translator::Schema::Constraint->new( name => 'bar' );
266     $constraint2    = $person_table->add_constraint( $constraint2 );
267     isa_ok( $constraint2, 'SQL::Translator::Schema::Constraint', 'Constraint' );
268     is( $constraint2->name, 'bar', 'Constraint name is "bar"' );
269
270     my $constraint3 = $person_table->add_constraint(
271         type       => 'check',
272         expression => 'foo bar',
273     ) or die $person_table->error;
274     isa_ok( $constraint3, 'SQL::Translator::Schema::Constraint', 'Constraint' );
275     is( $constraint3->type, CHECK_C, 'Constraint type is "CHECK"' );
276     is( $constraint3->expression, 'foo bar', 
277         'Constraint expression is "foo bar"' );
278
279     my $constraints = $person_table->get_constraints;
280     is( scalar @$constraints, 3, 'Three constraints' );
281     is( $constraints->[0]->name, 'foo', '"foo" constraint' );
282     is( $constraints->[1]->name, 'bar', '"bar" constraint' );
283
284     #
285     # View
286     #
287     my $view = $schema->add_view( name => 'view1' ) or warn $schema->error;
288     isa_ok( $view, 'SQL::Translator::Schema::View', 'View' );
289     my $view_sql = 'select * from table';
290     is( $view->sql( $view_sql ), $view_sql, 'View SQL is good' );
291
292     my $view2 = SQL::Translator::Schema::View->new(name => 'view2') or
293         warn SQL::Translator::Schema::View->error;
294     my $check_view = $schema->add_view( $view2 );
295     is( $check_view->name, 'view2', 'Add view "view2"' );
296
297     my $redundant_view = $schema->add_view(name => 'view2');
298     is( $redundant_view, undef, qq[Didn't create another "view2" view...] );
299     like( $schema->error, qr/can't create view/i, '... because it exists' );
300
301     #
302     # $schema->get_*
303     #
304     my $bad_table = $schema->get_table;
305     like( $schema->error, qr/no table/i, 'Error on no arg to get_table' );
306
307     $bad_table = $schema->get_table('baz');
308     like( $schema->error, qr/does not exist/i, 
309         'Error on bad arg to get_table' );
310
311     my $bad_view = $schema->get_view;
312     like( $schema->error, qr/no view/i, 'Error on no arg to get_view' );
313
314     $bad_view = $schema->get_view('bar');
315     like( $schema->error, qr/does not exist/i, 
316         'Error on bad arg to get_view' );
317
318     my $good_table = $schema->get_table('foo');
319     isa_ok( $good_table, 'SQL::Translator::Schema::Table', 'Table "foo"' );
320
321     my $good_view = $schema->get_view('view1');
322     isa_ok( $good_view, 'SQL::Translator::Schema::View', 'View "view1"' );
323     is( $view->sql( $view_sql ), $view_sql, 'View SQL is good' );
324
325     #
326     # $schema->get_*s
327     #
328     my @tables = $schema->get_tables;
329     is( scalar @tables, 3, 'Found 2 tables' );
330
331     my @views = $schema->get_views;
332     is( scalar @views, 2, 'Found 1 view' );
333 }
334
335 #
336 # Test ability to introspect some values
337 #
338
339     my $s        =  SQL::Translator::Schema->new( 
340         name     => 'foo',
341         database => 'PostgreSQL',
342     );
343     my $t = $s->add_table( name => 'person' ) or warn $s->erro;
344     my $f = $t->add_field( name => 'person_id' ) or warn $t->error;
345     $f->data_type('serial');
346
347     my $c          = $t->add_constraint(
348         type       => PRIMARY_KEY,
349         fields     => 'person_id',
350     ) or warn $t->error;
351
352     is( $f->is_primary_key, 1, 'Field is PK' );
353     is( $f->is_auto_increment, 1, 'Field is auto inc' );
354 }
355
356 #
357 # FK constraint validity
358 #
359 {
360     my $s = SQL::Translator::Schema->new;
361     my $t = $s->add_table( name => 'person' ) or warn $s->error;
362     my $c = $t->add_constraint or warn $t->error;
363
364     is( $c->is_valid, undef, 'Constraint on "person" not valid...');
365     like( $c->error, qr/no type/i, '...because it has no type' );
366
367     is( $c->type( FOREIGN_KEY ), FOREIGN_KEY, 'Constraint type now a FK' );
368
369     is( $c->is_valid, undef, 'Constraint on "person" not valid...');
370     like( $c->error, qr/no fields/i, '...because it has no fields' );
371
372     is( join('', $c->fields('foo')), 'foo', 'Fields now = "foo"' );
373
374     is( $c->is_valid, undef, 'Constraint on "person" not valid...');
375     like( $c->error, qr/non-existent field/i, 
376         q[...because field "foo" doesn't exist] );
377
378     my $fk = $t->add_field( name => 'pet_id' );
379     is( $fk->name, 'pet_id', 'Added field "pet_id"' );
380     is( join('', $c->fields('pet_id')), 'pet_id', 'Fields now = "pet_id"' );
381
382     $t->add_field( name => 'f1' );
383     $t->add_field( name => 'f2' );
384     is( join(',', $c->fields('f1,f2')), 'f1,f2', 'Fields now = "f1,f2"' );
385     is( $c->is_valid, undef, 'Constraint on "person" not valid...');
386     like( $c->error, qr/only one field/i, 
387         q[...because too many fields for FK] );
388
389     $c->fields('f1');
390
391     is( $c->is_valid, undef, 'Constraint on "person" not valid...');
392     like( $c->error, qr/no reference table/i, 
393         q[...because there's no reference table] );
394
395     is( $c->reference_table('foo'), 'foo', 'Reference table now = "foo"' );
396     is( $c->is_valid, undef, 'Constraint on "person" not valid...');
397     like( $c->error, qr/no table named/i, 
398         q[...because reference table "foo" doesn't exist] );
399
400     my $t2 = $s->add_table( name => 'pet' );
401     is( $t2->name, 'pet', 'Added "pet" table' );
402
403     is( $c->reference_table('pet'), 'pet', 'Reference table now = "pet"' );
404
405     is( $c->is_valid, undef, 'Constraint on "person" not valid...');
406     like( $c->error, qr/no reference fields/i,
407         q[...because there're no reference fields]);
408
409     is( join('', $c->reference_fields('pet_id')), 'pet_id', 
410         'Reference fields = "pet_id"' );
411
412     is( $c->is_valid, undef, 'Constraint on "person" not valid...');
413     like( $c->error, qr/non-existent field/i,
414         q[...because there's no "pet_id" field in "pet"]);
415
416     my $pet_id = $t2->add_field( name => 'pet_id' );
417     is( $pet_id->name, 'pet_id', 'Added field "pet_id"' );
418     
419     is( $c->is_valid, 1, 'Constraint now valid' );
420 }
421
422 #
423 # $table->primary_key test
424 #
425 {
426     my $s = SQL::Translator::Schema->new;
427     my $t = $s->add_table( name => 'person' );
428
429     is( $t->primary_key, undef, 'No primary key' );
430
431     is( $t->primary_key('person_id'), undef, 
432             q[Can't make PK on "person_id"...] );
433     like( $t->error, qr/invalid field/i, "...because it doesn't exist" );
434
435     $t->add_field( name => 'person_id' );
436     my $c = $t->primary_key('person_id');
437
438     isa_ok( $c, 'SQL::Translator::Schema::Constraint', 'Constraint' );
439
440     is( join('', $c->fields), 'person_id', 'Constraint now on "person_id"' );
441
442     $t->add_field( name => 'name' );
443     $c = $t->primary_key('name');
444     is( join(',', $c->fields), 'person_id,name', 
445         'Constraint now on "person_id" and "name"' );
446
447     is( scalar @{ $t->get_constraints }, 1, 'Found 1 constraint' );
448 }
449
450 #
451 # FK finds PK
452 #
453 {
454     my $s  = SQL::Translator::Schema->new;
455     my $t1 = $s->add_table( name => 'person' );
456     my $t2 = $s->add_table( name => 'pet' );
457     $t1->add_field( name => 'id' );
458     my $c1 = $t1->primary_key( 'id' ) or warn $t1->error;
459     is( $c1->type, PRIMARY_KEY, 'Made "person_id" PK on "person"' );
460
461     $t2->add_field( name => 'person_id' );
462     my $c2 = $t2->add_constraint(
463         type            => PRIMARY_KEY,
464         fields          => 'person_id',
465         reference_table => 'person',
466     );
467
468     is( join('', $c2->reference_fields), 'id', 'FK found PK "person.id"' );
469 }
470
471 #
472 # View
473 #
474 {
475     my $s      = SQL::Translator::Schema->new( name => 'ViewTest' );
476     my $name   = 'foo_view';
477     my $sql    = 'select name, age from person';
478     my $fields = 'name, age';
479     my $v      = $s->add_view(
480         name   => $name,
481         sql    => $sql,
482         fields => $fields,
483         schema => $s,
484     );
485
486     isa_ok( $v, 'SQL::Translator::Schema::View', 'View' );
487     isa_ok( $v->schema, 'SQL::Translator::Schema', 'Schema' );
488     is( $v->schema->name, 'ViewTest', qq[Schema name is "'ViewTest'"] );
489     is( $v->name, $name, qq[Name is "$name"] );
490     is( $v->sql, $sql, qq[Name is "$sql"] );
491     is( join(':', $v->fields), 'name:age', qq[Fields are "$fields"] );
492
493     my @views = $s->get_views;
494     is( scalar @views, 1, 'Number of views is 1' );
495
496     my $v1 = $s->get_view( $name );
497     isa_ok( $v1, 'SQL::Translator::Schema::View', 'View' );
498     is( $v1->name, $name, qq[Name is "$name"] );
499 }
500
501 #
502 # Trigger
503 #
504 {
505     my $s                   = SQL::Translator::Schema->new(name => 'TrigTest');
506     my $name                = 'foo_trigger';
507     my $perform_action_when = 'after';
508     my $database_event      = 'insert';
509     my $on_table            = 'foo';
510     my $action              = 'update modified=timestamp();';
511     my $t                   = $s->add_trigger(
512         name                => $name,
513         perform_action_when => $perform_action_when,
514         database_event      => $database_event,
515         on_table            => $on_table,
516         action              => $action,
517     ) or die $s->error;
518
519     isa_ok( $t, 'SQL::Translator::Schema::Trigger', 'Trigger' );
520     isa_ok( $t->schema, 'SQL::Translator::Schema', 'Schema' );
521     is( $t->schema->name, 'TrigTest', qq[Schema name is "'TrigTest'"] );
522     is( $t->name, $name, qq[Name is "$name"] );
523     is( $t->perform_action_when, $perform_action_when, 
524         qq[Perform action when is "$perform_action_when"] );
525     is( $t->database_event, $database_event, 
526         qq[Database event is "$database_event"] );
527     is( $t->on_table, $on_table, qq[Table is "$on_table"] );
528     is( $t->action, $action, qq[Action is "$action"] );
529
530     my @triggs = $s->get_triggers;
531     is( scalar @triggs, 1, 'Number of triggers is 1' );
532
533     my $t1 = $s->get_trigger( $name );
534     isa_ok( $t1, 'SQL::Translator::Schema::Trigger', 'Trigger' );
535     is( $t1->name, $name, qq[Name is "$name"] );
536 }
537
538 #
539 # Procedure
540 #
541 {
542     my $s          = SQL::Translator::Schema->new( name => 'ProcTest' );
543     my $name       = 'foo_proc';
544     my $sql        = 'select foo from bar';
545     my $parameters = 'foo, bar';
546     my $owner      = 'Nomar';
547     my $comments   = 'Go Sox!';
548     my $p          = $s->add_procedure(
549         name       => $name,
550         sql        => $sql,
551         parameters => $parameters,
552         owner      => $owner,
553         comments   => $comments,
554     ) or die $s->error;
555
556     isa_ok( $p, 'SQL::Translator::Schema::Procedure', 'Procedure' );
557     isa_ok( $p->schema, 'SQL::Translator::Schema', 'Schema' );
558     is( $p->schema->name, 'ProcTest', qq[Schema name is "'ProcTest'"] );
559     is( $p->name, $name, qq[Name is "$name"] );
560     is( $p->sql, $sql, qq[SQL is "$sql"] );
561     is( join(',', $p->parameters), 'foo,bar', qq[Params = 'foo,bar'] );
562     is( $p->comments, $comments, qq[Comments = "$comments"] );
563
564     my @procs = $s->get_procedures;
565     is( scalar @procs, 1, 'Number of procedures is 1' );
566
567     my $p1 = $s->get_procedure( $name );
568     isa_ok( $p1, 'SQL::Translator::Schema::Procedure', 'Procedure' );
569     is( $p1->name, $name, qq[Name is "$name"] );
570 }