[TT# 1592][t] Improve test for open opcode delegation. All tests in the file pass...
[parrot.git] / t / op / io.t
blob09cce13ecfe6ea82595a5733d902938750b6a5e6
1 #!./parrot
2 # Copyright (C) 2008, Parrot Foundation.
3 # $Id$
5 =head1 NAME
7 t/op/io.t - Testing io opcodes
9 =head1 SYNOPSIS
11     % prove t/op/io.t
13 =head1 DESCRIPTION
15 Tests various io opcodes.
17 =cut
19 .const int TESTS = 5
21 .sub 'main' :main
22     .include 'test_more.pir'
24     plan(TESTS)
26     open_delegates_to_filehandle_pmc()
27     open_null_filename()
28     open_null_mode()
29     open_pipe_for_reading()
30     open_pipe_for_writing()
31 .end
33 .sub open_delegates_to_filehandle_pmc
34     load_bytecode 'P6object.pbc'
36     .local pmc p6meta, interp, classes, classid
37     p6meta = get_root_global ["parrot"], "P6metaclass"
38     p6meta.'new_class'('Testing')
40     interp = getinterp
41     classes = interp[0]
42     classid = classes['Testing']
43     $I0 = classes['FileHandle']
44     set classes['FileHandle'], classid
46     $P1 = open '/foo'
47     is($P1,42,'open opcode delegates to the open method on the FileHandle PMC')
49     # replace the original, so we don't break other tests
50     set classes['FileHandle'], $I0
52 .end
54 .sub 'open_null_filename'
55     push_eh open_null_filename_failed
56     null $S0
57     $P0 = open $S0, 'r'
58     nok(1, 'open with null filename')
59     .return ()
61   open_null_filename_failed:
62     ok(1, 'open with null filename')
63 .end
65 .sub 'open_null_mode'
66     push_eh open_null_mode_failed
67     null $S0
68     $P0 = open 'some_name', $S0
69     nok(1, 'open with null mode')
70     .return ()
72   open_null_mode_failed:
73     ok(1, 'open with null mode')
74 .end
76 .sub 'tt661_todo_test' :anon
77     # As of r41963, these tests need to be todo'ed at least on Win32. Add new
78     # platforms known to fail.
79     .include 'sysinfo.pasm'
80     $S0 = sysinfo .SYSINFO_PARROT_OS
81     if $S0 == 'MSWin32' goto tt661_todo
83     .return (0)
85   tt661_todo:
86     .return (1)
87 .end
89 .include 'iglobals.pasm'
91 .sub 'open_pipe_for_reading'
92     .local pmc interp
93     interp = getinterp
95     .local pmc conf
96     conf = interp[.IGLOBALS_CONFIG_HASH]
98     .local string command
99     command = conf['build_dir']
101     .local string aux
102     aux = conf['slash']
103     command .= aux
104     aux = conf['test_prog']
105     command .= aux
106     aux = conf['exe']
107     command .= aux
108     command .= ' -V'
110     .local pmc pipe
111     pipe = open command, 'rp'
112     unless pipe goto open_pipe_for_reading_failed
113     .local string line
114     line = readline pipe
115     line = substr line, 0, 14
116     is('This is Parrot', line, 'open pipe for reading')
117     .return ()
119   open_pipe_for_reading_failed:
120     nok(1, 'open pipe for reading')
121     .return ()
122 .end
124 .sub 'open_pipe_for_writing'
125     $I0 = tt661_todo_test()
126     if $I0 goto open_pipe_for_writing_todoed
127     .local pmc interp
128     interp = getinterp
130     .local pmc conf
131     conf = interp[.IGLOBALS_CONFIG_HASH]
133     .local string command
134     command = conf['build_dir']
136     .local string aux
137     aux = conf['slash']
138     command .= aux
139     .local string filename
140     filename .= command
141     filename .= 'examples/pasm/cat.pasm'
142     aux = conf['test_prog']
143     command .= aux
144     aux = conf['exe']
145     command .= aux
146     command .= ' '
147     command .= filename
149     .local pmc pipe
150     pipe = open command, 'wp'
151     unless pipe goto open_pipe_for_writing_failed
153     pipe.'puts'("ok 5 - open pipe for writing\n")
154     close pipe
155     .return ()
157   open_pipe_for_writing_failed:
158     nok(1, 'open pipe for writing')
159     .return ()
161   open_pipe_for_writing_todoed:
162     todo(0, 'Unimplemented in this platform, TT #661')
164 .end
166 .namespace ["Testing"]
168 .sub open :method
169     .param pmc args :slurpy
170     .return(42)
171 .end
174 # Local Variables:
175 #   mode: pir
176 #   fill-column: 100
177 # End:
178 # vim: expandtab shiftwidth=4 ft=pir: