@@ -183,6 +183,19 @@ void runTests(string rdmdApp, string compiler, string model)
183
183
assert (res.status == 0 , res.output);
184
184
assert (res.output.canFind(" eval_works" )); // there could be a "DMD v2.xxx header in the output"
185
185
186
+ // Test automatic .writeln for --eval
187
+ import std.conv : text;
188
+ import std.typecons : tuple;
189
+ foreach (t; [tuple(` "eval_works"` , " eval_works" ),
190
+ tuple(" 2 + 2" , " 4" ),
191
+ tuple(" 2.write; 2 + 2" , " 24" )])
192
+ {
193
+ res = execute(rdmdArgs ~ [" --force" , " -de" , text(" --eval=" , t[0 ])]);
194
+ assert (res.status == 0 , res.output);
195
+ // there could be a "DMD v2.xxx header in the output" (NB: only seems to be the case for GDC)
196
+ assert (res.output.canFind(t[1 ]), text(" got:" , res.output, " expected:" , t[1 ]));
197
+ }
198
+
186
199
// compiler flags
187
200
res = execute(rdmdArgs ~ [" --force" , " -debug" ,
188
201
" --eval=debug {} else assert(false);" ]);
@@ -256,22 +269,24 @@ void runTests(string rdmdApp, string compiler, string model)
256
269
{
257
270
auto testLines = " foo\n bar\n doo" .split(" \n " );
258
271
259
- auto pipes = pipeProcess(rdmdArgs ~ [" --force" , " --loop=writeln(line);" ], Redirect.stdin | Redirect.stdout);
260
- foreach (input; testLines)
261
- pipes.stdin.writeln(input);
262
- pipes.stdin.close();
263
-
264
- while (! testLines.empty)
272
+ // Test --loop with automatic writeln
273
+ foreach (loopArg; [" --loop=writeln(line);" , " --loop=line" ])
265
274
{
266
- auto line = pipes.stdout.readln.strip;
267
- if (line.empty || line.startsWith(" DMD v" )) continue ; // git-head header
268
- assert (line == testLines.front, " Expected %s, got %s" .format(testLines.front, line));
269
- testLines.popFront;
270
- }
271
- auto status = pipes.pid.wait();
272
- assert (status == 0 );
273
- }
275
+ auto pipes = pipeProcess(rdmdArgs ~ [" --force" , loopArg], Redirect.stdin | Redirect.stdout);
276
+ foreach (input; testLines)
277
+ pipes.stdin.writeln(input);
278
+ pipes.stdin.close();
274
279
280
+ while (! testLines.empty)
281
+ {
282
+ auto line = pipes.stdout.readln.strip;
283
+ if (line.empty || line.startsWith(" DMD v" )) continue ; // git-head header
284
+ assert (line == testLines.front, " Expected %s, got %s" .format(testLines.front, line));
285
+ testLines.popFront;
286
+ }
287
+ auto status = pipes.pid.wait();
288
+ assert (status == 0 );
289
+ }}
275
290
// vs program file
276
291
res = execute(rdmdArgs ~ [" --force" ,
277
292
" --loop=assert(true);" , voidMain]);
0 commit comments