cvsuser 03/07/09 01:33:17
Modified: classes parrotio.pmc
io io.c
t/op hacks.t
t/pmc io.t
Log:
add clone and get_bool vtables; move IO tests to pmc
Revision Changes Path
1.4 +15 -2 parrot/classes/parrotio.pmc
Index: parrotio.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/parrotio.pmc,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -r1.3 -r1.4
--- parrotio.pmc 3 Jul 2003 07:21:20 -0000 1.3
+++ parrotio.pmc 9 Jul 2003 08:33:11 -0000 1.4
@@ -1,7 +1,7 @@
/* ParrotIO.pmc
* Copyright: (When this is determined...it will go here)
* CVS Info
- * $Id: parrotio.pmc,v 1.3 2003/07/03 07:21:20 leo Exp $
+ * $Id: parrotio.pmc,v 1.4 2003/07/09 08:33:11 leo Exp $
* Overview:
* These are the vtable functions for Parrot IO
* Data Structure and Algorithms:
@@ -29,5 +29,18 @@
ParrotIO *io = PMC_data(SELF);
if (io && !(io->flags & PIO_F_SHARED))
PIO_close(interpreter, SELF);
+ }
+
+ void clone (PMC *dest) {
+ VTABLE_init(INTERP, dest);
+ /* For now both PMCs refer to the same ParrotIO object.
+ * If we have different IO layers, we might copy these structures
+ */
+ PMC_data(dest) = PMC_data(SELF);
+ dest->cache.struct_val = SELF->cache.struct_val;
+ }
+
+ INTVAL get_bool() {
+ return !PIO_eof(INTERP, SELF);
}
}
1.44 +15 -13 parrot/io/io.c
Index: io.c
===================================================================
RCS file: /cvs/public/parrot/io/io.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -w -r1.43 -r1.44
--- io.c 9 Jul 2003 07:32:20 -0000 1.43
+++ io.c 9 Jul 2003 08:33:13 -0000 1.44
@@ -1,7 +1,7 @@
/* io.c
* Copyright: (When this is determined...it will go here)
* CVS Info
- * $Id: io.c,v 1.43 2003/07/09 07:32:20 leo Exp $
+ * $Id: io.c,v 1.44 2003/07/09 08:33:13 leo Exp $
* Overview:
* This is the Parrot IO subsystem API. Generic IO stuff
* goes here, each specific layer goes in its own file...
@@ -603,10 +603,11 @@
PIO_write(theINTERP, PMC *pmc, void *buffer, size_t len)
{
ParrotIOLayer *l = pmc->cache.struct_val;
+ ParrotIO *io = PMC_data(pmc);
+ if (io->flags & PIO_F_WRITE)
while (l) {
if (l->api->Write) {
- ParrotIO *io = PMC_data(pmc);
return (*l->api->Write) (interpreter, l, io, buffer, len);
}
l = PIO_DOWNLAYER(l);
@@ -680,10 +681,11 @@
PIO_puts(theINTERP, PMC *pmc, const char *s)
{
ParrotIOLayer *l = pmc->cache.struct_val;
+ ParrotIO *io = PMC_data(pmc);
+ if (io->flags & PIO_F_WRITE)
while (l) {
if (l->api->PutS) {
- ParrotIO *io = PMC_data(pmc);
return (*l->api->PutS) (interpreter, l, io, s);
}
l = PIO_DOWNLAYER(l);
1.9 +2 -129 parrot/t/op/hacks.t
Index: hacks.t
===================================================================
RCS file: /cvs/public/parrot/t/op/hacks.t,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -w -r1.8 -r1.9
--- hacks.t 8 Jul 2003 13:01:26 -0000 1.8
+++ hacks.t 9 Jul 2003 08:33:16 -0000 1.9
@@ -1,135 +1,8 @@
#! perl -w
-use Parrot::Test tests => 10;
+use Parrot::Test tests => 1;
use Test::More;
-# It would be very embarrassing if these didn't work...
-open FOO, ">temp.file";
-print FOO "2\n1\n";
-close FOO;
-output_is(<<'CODE', <<'OUTPUT', "open and readline");
- open P0, "temp.file"
- set S0, ""
- set S1, ""
- readline S0, P0
- readline S1, P0
- print S1
- print S0
- end
-CODE
-1
-2
-OUTPUT
-
-open FOO, ">temp.file"; # Clobber previous contents
-close FOO;
-
-output_is(<<'CODE', <<'OUTPUT', "open & print");
- set I0, -12
- set N0, 2.2
- set S0, "Foo"
- new P0, .PerlString
- set P0, "Bar\n"
-
- open P1, "temp.file"
- print P1, I0
- print P1, N0
- print P1, S0
- print P1, P0
- close P1
-
- open P2, "temp.file"
- readline S1, P2
- close P2
-
- print S1
- end
-CODE
--122.200000FooBar
-OUTPUT
-
-open FOO, ">temp.file"; # Clobber previous contents
-close FOO;
-
-# This one passes, but for the wrong reason
-output_is(<<'CODE', <<'OUTPUT', "3-arg open");
- open P1, "temp.file", "<"
- print "Foobar\n"
- close P1
-
- open P3, "temp.file", "<"
- readline S1, P3
- close P3
-
- print S1
- end
-CODE
-Foobar
-OUTPUT
-
-unlink("temp.file");
-
-output_is(<<'CODE', <<'OUTPUT', 'open and close');
- open P1, "temp.file"
- print P1, "Hello, World!\n"
- close P1
- print "done\n"
- end
-CODE
-done
-OUTPUT
-
-$/=undef; # slurp mode
-open FOO, "temp.file";
-
-is(<FOO>, <<'OUTPUT', 'file contents');
-Hello, World!
-OUTPUT
-
-close FOO;
-
-output_is(<<'CODE', '', 'append');
- open P1, "temp.file", ">>"
- print P1, "Parrot flies\n"
- close P1
- end
-CODE
-
-open FOO, "temp.file";
-
-is(<FOO>, <<'OUTPUT', 'append file contents');
-Hello, World!
-Parrot flies
-OUTPUT
-
-close FOO;
-
-output_is(<<'CODE', '', 'write to file');
- open P1, "temp.file", ">"
- print P1, "Parrot overwrites\n"
- close P1
- end
-CODE
-
-open FOO, "temp.file";
-
-is(<FOO>, <<'OUTPUT', 'file contents');
-Parrot overwrites
-OUTPUT
-
-unlink("temp.file");
-
-output_is(<<'CODE', '012', 'standard file descriptors');
- getstdin P0
- getfd I0, P0
- print I0
- getstdout P1
- getfd I1, P1
- print I1
- getstderr P2
- getfd I2, P2
- print I2
- end
-CODE
+is(1, 1, "tests moved to pmc/io");
1; # HONK
1.4 +179 -1 parrot/t/pmc/io.t
Index: io.t
===================================================================
RCS file: /cvs/public/parrot/t/pmc/io.t,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -r1.3 -r1.4
--- io.t 30 Jun 2003 10:20:07 -0000 1.3
+++ io.t 9 Jul 2003 08:33:17 -0000 1.4
@@ -1,6 +1,6 @@
#! perl -w
-use Parrot::Test tests => 4;
+use Parrot::Test tests => 16;
use Test::More;
output_is(<<'CODE', <<'OUTPUT', "open/close");
@@ -61,4 +61,182 @@
ok
OUTPUT
+unlink "no_such_file" if (-e "no_such_file");
+
+output_is(<<'CODE', <<'OUTPUT', "get_bool");
+ open P0, "no_such_file", "<"
+ unless P0, ok1
+ print "Huh: 'no_such_file' exists? - not "
+ok1:
+ print "ok 1\n"
+ open P0, "temp.file", "<"
+ if P0, ok2
+ print "not "
+ok2: print "ok 2\n"
+ read S0, P0, 1024
+ read S0, P0, 1024
+ unless P0, ok3
+ print "not "
+ok3: print "ok 3\n"
+ defined I0, P0
+ if I0, ok4
+ print "not "
+ok4: print "ok 4\n"
+ close P0
+ defined I0, P0 # closed file is still defined
+ if I0, ok5
+ print "not "
+ok5: print "ok 5\n"
+ unless P0, ok6 # but false
+ print "not "
+ok6: print "ok 6\n"
+ end
+CODE
+ok 1
+ok 2
+ok 3
+ok 4
+ok 5
+ok 6
+OUTPUT
+
+output_is(<<'CODE', <<'OUTPUT', "clone");
+ open P0, "temp.file", "<"
+ clone P1, P0
+ read S0, P1, 1024
+ print S0
+ end
+CODE
+a line
+OUTPUT
+
+# It would be very embarrassing if these didnt work...
+open FOO, ">temp.file";
+print FOO "2\n1\n";
+close FOO;
+output_is(<<'CODE', <<'OUTPUT', "open and readline");
+ open P0, "temp.file"
+ set S0, ""
+ set S1, ""
+ readline S0, P0
+ readline S1, P0
+ print S1
+ print S0
+ end
+CODE
+1
+2
+OUTPUT
+
+open FOO, ">temp.file"; # Clobber previous contents
+close FOO;
+
+output_is(<<'CODE', <<'OUTPUT', "open & print");
+ set I0, -12
+ set N0, 2.2
+ set S0, "Foo"
+ new P0, .PerlString
+ set P0, "Bar\n"
+
+ open P1, "temp.file"
+ print P1, I0
+ print P1, N0
+ print P1, S0
+ print P1, P0
+ close P1
+
+ open P2, "temp.file"
+ readline S1, P2
+ close P2
+
+ print S1
+ end
+CODE
+-122.200000FooBar
+OUTPUT
+
+open FOO, ">temp.file"; # Clobber previous contents
+close FOO;
+
+# write to file opened for reading
+output_is(<<'CODE', <<'OUTPUT', "3-arg open");
+ open P1, "temp.file", "<"
+ print P1, "Foobar\n"
+ close P1
+
+ open P3, "temp.file", "<"
+ readline S1, P3
+ close P3
+
+ print S1
+ print "writing to file opened for reading\n"
+ end
+CODE
+writing to file opened for reading
+OUTPUT
+
+unlink("temp.file");
+
+output_is(<<'CODE', <<'OUTPUT', 'open and close');
+ open P1, "temp.file"
+ print P1, "Hello, World!\n"
+ close P1
+ print "done\n"
+ end
+CODE
+done
+OUTPUT
+
+$/=undef; # slurp mode
+open FOO, "temp.file";
+
+is(<FOO>, <<'OUTPUT', 'file contents');
+Hello, World!
+OUTPUT
+
+close FOO;
+
+output_is(<<'CODE', '', 'append');
+ open P1, "temp.file", ">>"
+ print P1, "Parrot flies\n"
+ close P1
+ end
+CODE
+
+open FOO, "temp.file";
+
+is(<FOO>, <<'OUTPUT', 'append file contents');
+Hello, World!
+Parrot flies
+OUTPUT
+
+close FOO;
+
+output_is(<<'CODE', '', 'write to file');
+ open P1, "temp.file", ">"
+ print P1, "Parrot overwrites\n"
+ close P1
+ end
+CODE
+
+open FOO, "temp.file";
+
+is(<FOO>, <<'OUTPUT', 'file contents');
+Parrot overwrites
+OUTPUT
+
+unlink("temp.file");
+
+output_is(<<'CODE', '012', 'standard file descriptors');
+ getstdin P0
+ getfd I0, P0
+ print I0
+ getstdout P1
+ getfd I1, P1
+ print I1
+ getstderr P2
+ getfd I2, P2
+ print I2
+ end
+CODE
unlink("temp.file");