develooper Front page | perl.perl5.porters | Postings from September 2003

[PATCH] Test skeleton for debugger commands

Thread Next
From:
Andreas J Koenig
Date:
September 7, 2003 09:52
Subject:
[PATCH] Test skeleton for debugger commands
Message ID:
87fzj8k0cz.fsf@franz.ak.mind.de
The following patch implements a rudimentary skeleton that is able to
test some aspects of the debugger that have remained untested up to
now. There are two test scripts, tailored to catch the bug in patch
21010. I believe the framework is fairly flexible (well, borrowed from
similar tests:) but there will be more things to come, so I opened a
new directory for such tests.

I have no idea how portable it is, but everybody will agree that we
need something like this.

Enjoy,
-- 
andreas

--- perl-p-5.8.0@21061/MANIFEST~	2003-09-07 15:21:03.000000000 +0200
+++ perl-p-5.8.0@21061/MANIFEST	2003-09-07 18:37:29.000000000 +0200
@@ -2589,6 +2589,8 @@
 t/lib/Math/BigInt/BareCalc.pm	Bigint's simulation of Calc
 t/lib/Math/BigInt/Subclass.pm	Empty subclass of BigInt for test
 t/lib/Math/BigRat/Test.pm		Math::BigRat test helper
+t/lib/perl5db/de0.t                     Testing debugger commands
+t/lib/perl5db/dumpvar.t                 Testing the dumper used by the debugger
 t/lib/sample-tests/bailout		Test data for Test::Harness
 t/lib/sample-tests/bignum		Test data for Test::Harness
 t/lib/sample-tests/combined		Test data for Test::Harness
--- /dev/null	2003-09-06 13:07:17.000000000 +0200
+++ perl-p-5.8.0@21061/t/lib/perl5db/de0.t	2003-09-07 18:29:29.000000000 +0200
@@ -0,0 +1,64 @@
+#!./perl -- -*- mode: cperl; cperl-indent-level: 4 -*-
+
+use strict;
+
+chdir 't' if -d 't';
+@INC = '../lib';
+$|=1;
+undef $/;
+my @prgs = split "########\n", <DATA>;
+close DATA;
+print "1..", scalar @prgs, "\n";
+require "dumpvar.pl";
+
+our $tmpfile = "perl5db0";
+1 while -f ++$tmpfile;
+END { if ($tmpfile) { 1 while unlink $tmpfile; } }
+
+my $i = 0;
+$ENV{PERLDB_OPTS} = "TTY=0";
+my($ornament1,$ornament2);
+for (@prgs){
+    my($prog,$expected) = split(/\nEXPECT\n?/, $_);
+    open my $select, "| $^X -de0 2> $tmpfile" or die;
+    print $select $prog;
+    close $select;
+    my $got = do { open my($fh), $tmpfile or die; local $/; <$fh>; };
+    $got =~ s/^\s*Loading.*\nEditor.*\n\nEnter.*\n\nmain::\(-e:1\):\s0\n//;
+    unless (defined $ornament1) {
+        ($ornament1,$ornament2) = $got =~
+            /(.*?)0\s+'reserved example for calibrating the ornaments'\n(.*)/
+    }
+    $got =~ s/^\Q$ornament1\E//;
+    $got =~ s/\Q$ornament2\E\z//;
+    my $not = "";
+    my $why = "";
+    if ($got !~ /$expected/) {
+        $not = "not ";
+        $got = dumpvar::unctrl($got);
+        $why = " # prog[$prog]got[$got]expected[$expected]";
+    }
+    print $not, "ok ", ++$i, $why, "\n";
+}
+
+__END__
+x "reserved example for calibrating the ornaments"
+EXPECT
+0  'reserved example for calibrating the ornaments'
+########
+x "foo"
+EXPECT
+0  'foo'
+########
+x 1..3
+EXPECT
+0  1
+1  2
+2  3
+########
+x +{1..4}
+EXPECT
+0\s+HASH\(0x[\da-f]+\)
+\s+1 => 2
+\s+3 => 4
+########
--- /dev/null	2003-09-06 13:07:17.000000000 +0200
+++ perl-p-5.8.0@21061/t/lib/perl5db/dumpvar.t	2003-09-07 17:13:34.000000000 +0200
@@ -0,0 +1,58 @@
+#!./perl -- -*- mode: cperl; cperl-indent-level: 4 -*-
+
+use strict;
+
+chdir 't' if -d 't';
+@INC = '../lib';
+$|=1;
+undef $/;
+my @prgs = split "########\n", <DATA>;
+close DATA;
+print "1..", scalar @prgs, "\n";
+require "dumpvar.pl";
+
+my $i = 0;
+for (@prgs){
+    my($prog,$expected) = split(/\nEXPECT\n?/, $_);
+    open my $select, ">", \my $got or die;
+    select $select;
+    eval $prog;
+    my $not = "";
+    my $why = "";
+    if ($@) {
+        $not = "not ";
+        $why = " # prog[$prog]\$\@[$@]";
+    } elsif ($got ne $expected) {
+        $not = "not ";
+        $why = " # prog[$prog]got[$got]expected[$expected]";
+    }
+    close $select;
+    select STDOUT;
+    print $not, "ok ", ++$i, $why, "\n";
+}
+
+__END__
+"";
+EXPECT
+########
+dumpValue(1);
+EXPECT
+1
+########
+dumpValue("1\n2\n3");
+EXPECT
+'1
+2
+3'
+########
+dumpValue([1..3],1);
+EXPECT
+0  1
+1  2
+2  3
+########
+dumpValue({1..4},1);
+EXPECT
+1 => 2
+3 => 4
+########



END_OF_PATCH

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About