Debian Codegraph @

trip/addrtest3.rexx

raw
1 /*
2 * Additional test for ADDRESS WITH options for checking the STREAM resource.
3 * You need the programs "std" and "cat" to run this script.
4 * The test gives some lines of debugging output.
5 *
6 * The test returns 1 and prints some lines to standard error in case of
7 * an error.
8 * The test returns 0 without any line written to stdardard error on success.
9 *
10 * A good testing environment does the following test; remove the redirection
11 * element in case of errors and check the output:
12 * "rexx addrtest3 >/dev/null"
13 *
14 * Don't pass arguments to the script. Arguments are used internally for
15 * recursive calls.
16 */
17
18 if countstr( "/", stream( ".", "C", "Query exists" ) ) > 0 then
19 Std = "./std"
20 else
21 Std = ".\std"
22
23 if arg(1) = "stdout" then do
24 ADDRESS SYSTEM Std WITH OUTPUT STREAM 'stdout' ERROR STREAM 'stdout'
25 exit 0
26 end
27
28 if arg(1) = "stderr" then do
29 ADDRESS SYSTEM Std WITH OUTPUT STREAM 'stderr' ERROR STREAM '<stderr>'
30 exit 0
31 end
32
33 if arg(1) = "mixed" then do
34 ADDRESS SYSTEM Std WITH OUTPUT STREAM 'stdout' ERROR STREAM 'stderr'
35 exit 0
36 end
37
38 /*
39 * Normal main routine
40 *
41 * First, initialize some useful values and files.
42 */
43 parse source . . myself
44 Junk = "junk.tst" /* Never change without changing below too */
45 if stream( Junk, "C", "Query exists" ) \= "" then
46 call stream Junk, "C", "Open Write Replace" /* Auto-close on ADDRESS */
47
48 expected1 = "Line to stdout"
49 expected2 = "Line to stderr"
50
51 /*
52 * Next, do a basic test.
53 */
54 call info 'ADDRESS SYSTEM Std WITH OUTPUT STEM o. ERROR STEM e.'
55 ADDRESS SYSTEM Std WITH OUTPUT STEM o. ERROR STEM e.
56 say "o.0="o.0
57 say "o.1="o.1
58 say "e.0="e.0
59 say "e.1="e.1
60 if o.0 \= 1 | o.1 \= expected1 | e.0 \= 1 | e.1 \= expected2 then
61 call oops lastaction
62 drop e. o.
63
64 /*
65 * Next, check the default streams for proper running.
66 */
67 call info 'ADDRESS REGINA myself "mixed" WITH OUTPUT STEM o. ERROR STEM e.'
68 ADDRESS REGINA myself "mixed" WITH OUTPUT STEM o. ERROR STEM e.
69 say "o.0="o.0
70 say "o.1="o.1
71 say "e.0="e.0
72 say "e.1="e.1
73 if o.0 \= 1 | o.1 \= expected1 | e.0 \= 1 | e.1 \= expected2 then
74 call oops lastaction
75 drop e. o.
76
77 call info 'ADDRESS REGINA myself "stdout" WITH OUTPUT STEM o. ERROR STEM e.'
78 ADDRESS REGINA myself "stdout" WITH OUTPUT STEM o. ERROR STEM e.
79 say "o.0="o.0
80 say "o.1="o.1
81 say "o.2="o.2
82 say "e.0="e.0
83 if o.0 \= 2 | o.1 \= expected2 | o.2 \= expected1 | e.0 \= 0 then
84 call oops lastaction
85 drop e. o.
86
87 call info 'ADDRESS REGINA myself "stderr" WITH OUTPUT STEM o. ERROR STEM e.'
88 ADDRESS REGINA myself "stderr" WITH OUTPUT STEM o. ERROR STEM e.
89 say "o.0="o.0
90 say "e.0="e.0
91 say "e.1="e.1
92 say "e.2="e.2
93 if o.0 \= 0 | e.0 \= 2 | e.1 \= expected2 | e.2 \= expected1 then
94 call oops lastaction
95 drop e. o.
96
97 call info 'ADDRESS COMMAND WITH OUTPUT STREAM "junk.tst" ERROR STREAM Junk'
98 ADDRESS COMMAND WITH OUTPUT STREAM 'junk.tst' ERROR STREAM Junk
99 call info 'ADDRESS COMMAND "'Std'" (with some implicite redirections)'
100 ADDRESS COMMAND Std
101 line1 = Linein( Junk )
102 line2 = Linein( Junk )
103 Say "Line 1 from '"Junk"' is: '"line1"'"
104 Say "Line 2 from '"Junk"' is: '"line2"'"
105 If line1 \= expected2 | line2 \= expected1 then
106 call oops lastaction
107 ADDRESS COMMAND WITH OUTPUT NORMAL ERROR NORMAL
108
109 /*
110 * junk.tst currently contains the two expected lines.
111 */
112 call info 'ADDRESS SYSTEM "cat" WITH INPUT STREAM Junk OUTPUT APPEND STREAM Junk'
113 ADDRESS SYSTEM "cat" WITH INPUT STREAM Junk OUTPUT APPEND STREAM Junk
114 line1 = Linein( Junk )
115 line2 = Linein( Junk )
116 line3 = Linein( Junk )
117 line4 = Linein( Junk )
118 Say "Line 1 from '"Junk"' is: '"line1"'"
119 Say "Line 2 from '"Junk"' is: '"line2"'"
120 Say "Line 3 from '"Junk"' is: '"line3"'"
121 Say "Line 4 from '"Junk"' is: '"line4"'"
122 If line1 \= expected2 | line2 \= expected1 then
123 call oops lastaction
124 If line3 \= expected2 | line4 \= expected1 then
125 call oops lastaction
126
127 /*
128 * Reset address to default
129 */
130 Address System WITH INPUT NORMAL OUTPUT NORMAL ERROR NORMAL
131
132 exit 0
133
134 info:
135 say ""
136 lastaction = arg(1)
137 say "Action:" lastaction
138 return
139
140 oops: procedure
141 call lineout "<stderr>", "----------------------------------------"
142 call lineout "<stderr>", "Something's wrong in test" arg(1)
143 call lineout "<stderr>", "----------------------------------------"
144 call lineout "<stderr>", ""
145 exit 1
146 return
147
148 extcall: procedure
149 if arg() > 1 then
150 address REXX arg(1) WITH error stem err.
151 else
152 address REXX arg(1) arg(2) WITH error stem err.
153 if err.0 = 0 then
154 return
155 do i = 1 to err.0
156 call lineout "<stderr>", err.i
157 end
158 exit 1
159 return
160
161 DoExit0:
162 exit 0