/
fc-solve-output-Test-Trap.t
414 lines (348 loc) · 9.87 KB
/
fc-solve-output-Test-Trap.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 37;
use Test::Trap
qw( trap $trap :flow:stderr(systemsafe):stdout(systemsafe):warn );
use FC_Solve::Paths
qw( bin_board bin_exe_raw is_freecell_only is_without_dbm normalize_lf offload_arg samp_board $FC_SOLVE__RAW );
use Path::Tiny qw/ path tempdir tempfile cwd /;
my $MID24_BOARD = samp_board('24-mid.board');
{
trap
{
system( $FC_SOLVE__RAW,
qw/-s -i -p -t -sam -sel -to j/,
samp_board('24-mod-to-test-fc-to-empty-s.board')
);
};
my $needle = qr#^Iteration: 1\r?\nDepth: 1\r?\n#ms;
# TEST
like( $trap->stdout(), $needle,
"Found some derived states with the new move-freecells-to-empty-cols",
);
}
{
trap
{
system( $FC_SOLVE__RAW, "--reset_junk_at_end", $MID24_BOARD );
};
my $needle =
qq#Unknown option "--reset_junk_at_end". Type "$FC_SOLVE__RAW --help" for usage information.#;
# TEST
like( $trap->stderr(), qr/^\Q$needle\E\r?$/ms,
"Unknown option was recognized, for one that has a valid prefix.",
);
# TEST
unlike( $trap->stdout(), qr/\S/,
"Empty standard output due to unrecognized option.",
);
}
{
trap
{
system( $FC_SOLVE__RAW, '--read-from-file4,amateur-star.sh',
'--stacks-num', '7', $MID24_BOARD );
};
my $needle =
qq#Unknown option "--read-from-file4,amateur-star.sh". Type "$FC_SOLVE__RAW --help" for usage information.#;
# TEST
like( $trap->stderr(), qr/^\Q$needle\E\r?$/ms,
"Option without space is not accepted." );
}
{
my $dir = tempdir();
my $fh = $dir->child("foo.txt");
$fh->spew_utf8("-invalidopt 25\n");
trap
{
system( $FC_SOLVE__RAW, '--read-from-file',
( $fh->absolute->stringify ), $MID24_BOARD );
};
my $needle =
qq#Unknown option "-invalidopt". Type "$FC_SOLVE__RAW --help" for usage information.#;
# TEST
like( $trap->stderr(), qr/^\Q$needle\E\r?$/ms,
"Option without space is not accepted." );
}
{
trap
{
system( bin_exe_raw( ['freecell-solver-fc-pro-range-solve'] ),
'1', '3', '1', '-l', 'as', );
};
my @lines = split( /\n/, $trap->stdout() );
# TEST
is_deeply(
[
grep {
/\A\[\[Num FCS Moves\]\]=([0-9]+)\r?\z/
? ( not( $1 > 0 ) )
: 1;
}
grep { /\A\[\[Num FCS Moves\]\]/ } @lines
],
[],
"All FCS Move counts are valid",
);
# TEST
is_deeply(
[
grep {
/\A\[\[Num FCPro Moves\]\]=([0-9]+)\r?\z/
? ( not( $1 > 0 ) )
: 1;
}
grep { /\A\[\[Num FCPro Moves\]\]/ } @lines
],
[],
"All FCPro Move counts are valid.",
);
}
{
trap
{
system( bin_exe_raw( ['summary-fc-solve'] ), 1591, 1592, 1593,
qw(-- --method random-dfs -to [0123456789] -sp r:tf -opt -opt-to 0123456789ABCDE -seed 24 -mi 10000)
);
};
my $out = $trap->stdout();
# TEST
like(
$out,
qr/^1591 = Verdict: Intractable.*?^1592 = Verdict: Solved.*?^1593 = Verdict: Solved/ms,
"All deals in summary-fc-solve are either intractable or solved.",
);
# TEST
unlike(
$out,
qr/Verdict: Unsolved/,
'No deal is unsolved, because that makes no sense.',
);
}
{
my $status;
trap
{
$status = system( $FC_SOLVE__RAW,
qw#
--flare-name prefix_of_a_long_name --method soft-dfs -to 0123456789 -sp r:tf -opt -opt-to 0123456789ABCDE
-nf --flare-name another_long_name --method soft-dfs -to 0123467 -sp r:tf -opt -opt-to 0123456789ABCDE
--flares-plan
#, 'Run:100@prefix,Run:200@another_long_name',
bin_board('24.board'),
);
};
my $needle = q#Flares Plan: Unknown flare name.#;
# TEST
like(
$trap->stderr(),
qr/^\Q$needle\E\r?$/ms,
q#Cannot use a prefix of a flare's name as the name in the flares plan.#,
);
# TEST
ok( scalar( $status != 0 ), 'Exited with a non-zero exit code.', );
# TEST
is( $trap->stdout(), '', 'Empty standard output on flares plan error.' );
}
# TEST:$num_boards=2;
foreach my $board_fn (
qw(24-with-stray-d-char.board
24-with-stray-d-char-in-freecells.board)
)
{
trap
{
system( $FC_SOLVE__RAW, "-mi", 1000,
samp_board('24-with-stray-d-char.board') );
};
my $needle = q#Not enough input.#;
# TEST*$num_boards
like( $trap->stderr(), qr/^\Q$needle\E\r?$/ms, "Invalid card format.", );
# TEST*$num_boards
unlike( $trap->stdout(), qr/\S/,
"Empty standard output due to invalid card format.",
);
}
{
SKIP:
{
if ( is_without_dbm() )
{
Test::More::skip( "without the dbm fc_solvers", 3 );
}
my $status;
trap
{
$status = system(
bin_exe_raw( ['depth-dbm-fc-solver'] ),
offload_arg(), bin_board('empty.board'),
);
};
my $out = $trap->stdout();
# TEST
is( $out, '',
"No output for depth-dbm-fc-solver on empty and invalid board",
);
# TEST
like(
$trap->stderr(),
qr/\AInvalid input board/,
"Correct stderr for depth-dbm-fc-solver on empty and invalid board",
);
# TEST
ok( scalar( $status != 0 ), "Exit code is non-zero." );
}
}
{
SKIP:
{
if ( is_without_dbm() )
{
Test::More::skip( "without the dbm fc_solvers", 1 );
}
my $status;
trap
{
$status = system(
bin_exe_raw( ['depth-dbm-fc-solver'] ), '--num-threads',
3, '--batch-size',
20, offload_arg(),
bin_board('1107600547.board'),
);
};
my $out = $trap->stdout();
# TEST
like(
$out,
qr/\nCould not solve successfully\.\r?\nhandle_and_destroy_instance_solution end\r?\n?\z/,
"1107600547 run finished.",
);
}
}
{
SKIP:
{
if ( is_without_dbm() )
{
Test::More::skip( "without the dbm fc_solvers", 2 );
}
# TEST:$solver=2;
foreach my $solver ( 'depth-dbm-fc-solver', 'dbm-fc-solver' )
{
my $status;
trap
{
$status = system(
bin_exe_raw( [$solver] ),
offload_arg(), bin_board('11982.board'),
);
};
my $out = $trap->stdout();
my $err = $trap->stderr();
my @stats = $out =~
/(\r?\n>>>Queue Stats: inserted=[0-9]+ items_in_queue=[0-9]+ extracted=[0-9]+\r?\n)/g;
# TEST*$solver
like(
$stats[-1],
qr/ items_in_queue=0 /,
"queue is reported as empty in the $solver run for an impossible deal.",
) or diag("solver=<<$solver>> out=<<$out>> err=<<$err>>");
}
}
}
{
SKIP:
{
if ( is_freecell_only() )
{
Test::More::skip( "without freecell", 1 );
}
trap
{
system( $FC_SOLVE__RAW, '-g', 'notexist', bin_board('24.board'), );
};
# TEST
like(
$trap->stderr(),
qr/\AUnknown game \"notexist\"!/ms,
"-g notexist returns the right error.",
);
}
}
{
trap
{
system( $FC_SOLVE__RAW, '-l' );
};
# TEST
like(
$trap->stderr(),
qr/\AThe command line parameter "-l" requires an argument/ms,
"Command line parameter without argument displays its name",
);
}
{
foreach my $exe (
'freecell-solver-fc-pro-range-solve',
'freecell-solver-fork-solve',
'freecell-solver-multi-thread-solve',
'freecell-solver-range-parallel-solve'
)
{
SKIP:
{
my $full_exe = bin_exe_raw( [$exe] );
if ( not -e $full_exe )
{
Test::More::skip( "[$exe] not found.", 3 );
}
# TEST:$exe=4;
trap
{
system( $full_exe, '1', '2', '1', '-l', 'cm', );
};
my $out = normalize_lf( scalar $trap->stdout() );
# TEST*$exe
like( $out, qr#^Reached Board No\. 1 at#ms, "[$exe] board no. 1" );
# TEST*$exe
like( $out, qr#^Reached Board No\. 2 at#ms, "[$exe] board no. 2" );
# TEST*$exe
unlike(
$out,
qr#Reached Board No\. 3#ms,
"[$exe] board no. 3 is not present"
);
}
}
}
{
SKIP:
{
if ( is_freecell_only() )
{
Test::More::skip( "without freecell", 1 );
}
trap
{
system( bin_exe_raw( ['freecell-solver-fc-pro-range-solve'] ),
'1', '2', '1', '--freecells-num', 0, );
};
my $out = normalize_lf( scalar $trap->stdout() );
# TEST
like(
$out,
qr/^Unsolved Board No\. 1 at [0-9]+\.[0-9]+\n\[\[Num Iters\]\]=[^\n]*\n\[\[Num FCS Moves\]\]=-2\n/ms,
'--freecells-num is respected without a variant',
);
}
}
__END__
=head1 COPYRIGHT AND LICENSE
This file is part of Freecell Solver. It is subject to the license terms in
the COPYING.txt file found in the top-level directory of this distribution
and at http://fc-solve.shlomifish.org/docs/distro/COPYING.html . No part of
Freecell Solver, including this file, may be copied, modified, propagated,
or distributed except according to the terms contained in the COPYING file.
Copyright (c) 2008 Shlomi Fish
=cut