test suite and fix input_line_number()
[p5sagit/p5-mst-13.2.git] / t / lib / fields.t
index 7fad5d7..6f3ea5b 100755 (executable)
@@ -1,11 +1,10 @@
 #!./perl -w
 
-use strict;
-use vars qw($DEBUG);
-
 my $w;
 
 BEGIN {
+   chdir 't' if -d 't';
+   unshift @INC, '../lib' if -d '../lib';
    $SIG{__WARN__} = sub {
        if ($_[0] =~ /^Hides field 'b1' in base class/) {
            $w++;
@@ -15,6 +14,9 @@ BEGIN {
    };
 }
 
+use strict;
+use vars qw($DEBUG);
+
 package B1;
 use fields qw(b1 b2 b3);
 
@@ -80,7 +82,7 @@ my %expect = (
     'Foo::Bar::Baz' => 'b1:1,b2:2,b3:3,foo:4,bar:5,baz:6',
 );
 
-print "1..", int(keys %expect)+3, "\n";
+print "1..", int(keys %expect)+5, "\n";
 my $testno = 0;
 while (my($class, $exp) = each %expect) {
    no strict 'refs';
@@ -108,3 +110,17 @@ print "not " unless $@ && $@ =~ /^No such field "notthere"/;
 print "ok ", ++$testno, "\n";
 
 #fields::_dump();
+
+# check if 
+{
+    package Foo;
+    use fields qw(foo bar);
+    sub new { bless [], $_[0]; }
+
+    package main;
+    my Foo $a = Foo->new();
+    $a->{foo} = ['a', 'ok ' . ++$testno, 'c'];
+    $a->{bar} = { A => 'ok ' . ++$testno };
+    print $a->{foo}[1], "\n";
+    print $a->{bar}->{A}, "\n";
+}