~vcs-imports-ii/gnuchess/trunk

« back to all changes in this revision

Viewing changes to test/commands/test_command.tcl

  • Committer: aceballos
  • Date: 2017-06-12 21:52:45 UTC
  • Revision ID: svn-v4:6006247a-2d13-4e52-b961-62b44c6c37c8:trunk:157
Tags: v6.2.5-rc2
merge --reintegrate branches/readline; release 6.2.5-rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/tclsh
 
2
 
 
3
package require Expect
 
4
 
 
5
variable gnuchessplayer
 
6
variable n_pass
 
7
variable n_fail
 
8
variable failed_test_cases
 
9
 
 
10
proc pass { } {
 
11
    set ::n_pass [expr $::n_pass + 1]
 
12
    puts " ----> PASS"
 
13
}
 
14
 
 
15
proc fail {test_case_title} {
 
16
    set ::n_fail [expr $::n_fail + 1]
 
17
    lappend ::failed_test_cases $test_case_title
 
18
    puts " ----> FAIL"
 
19
}
 
20
 
 
21
proc test_setup { } {
 
22
}
 
23
 
 
24
proc test_cleanup { } {
 
25
    #send -i $::gnuchessplayer "quit"
 
26
    #close $::gnuchessplayer
 
27
}
 
28
 
 
29
proc test_case {title steps} {
 
30
    puts "---------------------------------------------------------------------"
 
31
    #test_setup
 
32
    if {[lindex $steps 0] == "xboard"} {
 
33
        spawn ../../src/gnuchess -x; set ::gnuchessplayer $spawn_id
 
34
        set steps [lreplace $steps 0 0]
 
35
    } else {
 
36
        spawn ../../src/gnuchess; set ::gnuchessplayer $spawn_id
 
37
    }
 
38
    set test_pass 1
 
39
    puts -nonewline $title
 
40
    foreach step $steps {
 
41
        if {[string first "I " $step] == 0} {
 
42
            send -i $::gnuchessplayer "[string range $step 2 end]\n"
 
43
        } elseif {[string first "O " $step] == 0} {
 
44
            expect {
 
45
                -i $::gnuchessplayer [string range $step 2 end] {}
 
46
                timeout {set test_pass 0}
 
47
            }
 
48
        } else {
 
49
            set test_pass 0
 
50
        }
 
51
    }
 
52
    if {$test_pass == 1} {
 
53
        pass
 
54
    } else {
 
55
        fail $title
 
56
    }
 
57
    #test_cleanup
 
58
    close
 
59
    #after 2000
 
60
}
 
61
 
 
62
# Test suite
 
63
proc run { } {
 
64
 
 
65
    ############################################################################
 
66
    # Test cases for individual commands
 
67
    ############################################################################
 
68
 
 
69
    test_case "Name and version" [list "O GNU Chess 6.2"]
 
70
    test_case "Invalid move" [list "I " "O Invalid move:" "O White"  "I e5" "O Invalid move:" "O White"]
 
71
    test_case "Command: ?" [list "I ?" "O White (1)"]
 
72
    test_case "Command: accepted" [list "I accepted" "O White (1)"]
 
73
    test_case "Command: activate" [list "I activate" "O currently not supported" "O White (1)"]
 
74
    test_case "Command: analyze" [list "I analyze" "O White (1)" "O 1 +" "O 2 +"]
 
75
    test_case "Command: bk" [list "I bk" "O %)" "O White (1)"]
 
76
    test_case "Command: bk" [list "I bk" "O %)" "O White (1)"]
 
77
    test_case "Command: black" [list "I black" "O currently not supported" "O White (1)"]
 
78
    test_case "Command: white" [list "I white" "O currently not supported" "O White (1)"]
 
79
    test_case "Command: book" [list "I book" "O Incorrect book option" "O White (1)"]
 
80
    # TODO book commands
 
81
    test_case "Command: depth 1" [list "I depth 1" "O Search to a depth of 1" "O White (1)"]
 
82
    test_case "Command: depth 5" [list "I depth 5" "O Search to a depth of 5" "O White (1)"]
 
83
    test_case "Command: easy" [list "I easy" "O White (1)"]
 
84
    test_case "Command: hard" [list "I hard" "O White (1)"]
 
85
    # TODO Add more complex cases for hard and post
 
86
    test_case "Command: edit" [list "xboard" "I edit" "O not implemented"]
 
87
    test_case "Command: edit" [list "I xboard" "I edit" "O not implemented"]
 
88
    test_case "Command: epdload" [list "I epdload" "O Error reading file ''" "O White (1)"]
 
89
    test_case "Command: epdload" [list "I epdload ./Polgar-Karpov.epd" \
 
90
                               "O white" \
 
91
                               "O . . r . . n k ." \
 
92
                               "O . . . . q p p ." \
 
93
                               "O . . . . p . . ." \
 
94
                               "O p . . n N . P ." \
 
95
                               "O P p N P . . . ." \
 
96
                               "O . P r R . Q . ." \
 
97
                               "O . . . . . P . ." \
 
98
                               "O . . . . R . K ." \
 
99
                               "O White (1)"]
 
100
    test_case "Command: load" [list "I load ./Polgar-Karpov.epd" \
 
101
                               "O white" \
 
102
                               "O . . r . . n k ." \
 
103
                               "O . . . . q p p ." \
 
104
                               "O . . . . p . . ." \
 
105
                               "O p . . n N . P ." \
 
106
                               "O P p N P . . . ." \
 
107
                               "O . P r R . Q . ." \
 
108
                               "O . . . . . P . ." \
 
109
                               "O . . . . R . K ." \
 
110
                               "O White (1)"]
 
111
    test_case "Command: epdsave" [list "I epdsave" "O Invalid filename" "O White (1)"]
 
112
    file delete -force ./tmp.epd
 
113
    test_case "Command: epdsave" [list "I epdload ./Polgar-Karpov.epd" "O . . . . R . K ." "I depth 1" "I Kh1" "O . . . . R . . K" "O White (2)" "I epdsave ./tmp.epd" "O White (2)" "I epdload ./tmp.epd" "O . . . . R . . K"]
 
114
    file delete -force ./tmp.epd
 
115
    test_case "Command: save" [list "I load ./Polgar-Karpov.epd" "O . . . . R . K ." "I depth 1" "I Kh1" "O . . . . R . . K" "O White (2)" "I save ./tmp.epd" "O White (2)" "I epdload ./tmp.epd" "O . . . . R . . K"]
 
116
    file delete -force ./tmp.epd
 
117
    test_case "Command: exit" [list "I exit" "O "]
 
118
    test_case "Command: force" [list "I force" "O White (1)" "I e4" "O . . . . P . . ." "O Black (1)"]
 
119
    test_case "Command: manual" [list "I manual" "O White (1)" "I e4" "O . . . . P . . ." "O Black (1)"]
 
120
    test_case "Command: go" [list "I go" "O Thinking..." "O Black (1)" "I go" "O Thinking..." "O White (2)"]
 
121
    # TODO Add more complex cases for go
 
122
    test_case "Command: graphic" [list "I graphic" "O Graphic mode is enabled." "O White (1)"]
 
123
    test_case "Command: nographic" [list "I nographic" "O Graphic mode is disabled." "O White (1)"]
 
124
    test_case "Command: hash" [list "I hash" "O Hashing is on." "O White (1)" "I hash off" "O Hashing is off." "O White (1)" "I hash" "O Hashing is off." "O White (1)" "I hash on" "O Hashing is on." "O White (1)"]
 
125
    test_case "Command: help" [list "I help" "O List of commands: (help COMMAND to get more help)" "O White (1)" "I help help" "O help" "O Produces a help blurb corresponding to this list of commands." "O White (1)"]
 
126
    # TODO FIX test_case "Command: hint" [list "I hint" "O Hint:" "O White (1)"]
 
127
    test_case "Command: ics" [list "I ics" "O " "O White (1)"]
 
128
    test_case "Command: pgnload" [list "I pgnload ./Polgar-Karpov.pgn" \
 
129
                               "O white" \
 
130
                               "O . . r . . n k ." \
 
131
                               "O . . . . q p p ." \
 
132
                               "O . . . . p . . ." \
 
133
                               "O p . . n N . P ." \
 
134
                               "O P p N P . . . ." \
 
135
                               "O . P r R . Q . ." \
 
136
                               "O . . . . . P . ." \
 
137
                               "O . . . . R . K ." \
 
138
                               "O White (1)"]
 
139
    file delete -force ./tmp.pgn
 
140
    # TODO FIX test_case "Command: pgnsave" [list "I pgnload ./Polgar-Karpov.pgn" "O . . . . R . K ." "I depth 1" "I Kh1" "O . . . . R . . K" "O White (35)" "I pgnsave ./tmp.pgn" "O White (35)" "I pgnload ./tmp.pgn" "O . . . . R . . K"]
 
141
    file delete -force ./tmp.pgn
 
142
    test_case "Command: pgnreplay" [list "I pgnreplay ./Polgar-Karpov.pgn" \
 
143
                               "O white" \
 
144
                               "O . . r . . n k ." \
 
145
                               "O . . . . q p p ." \
 
146
                               "O . . . . p . . ." \
 
147
                               "O p . . n N . P ." \
 
148
                               "O P p N P . . . ." \
 
149
                               "O . P r R . Q . ." \
 
150
                               "O . . . . . P . ." \
 
151
                               "O . . . . R . K ." \
 
152
                               "O white  KQkq" \
 
153
                               "O r n b q k b n r" \
 
154
                               "O p p p p p p p p" \
 
155
                               "O . . . . . . . ." \
 
156
                               "O . . . . . . . ." \
 
157
                               "O . . . . . . . ." \
 
158
                               "O . . . . . . . ." \
 
159
                               "O P P P P P P P P" \
 
160
                               "O R N B Q K B N R" \
 
161
                               "O White (1)" \
 
162
                           "I first" \
 
163
                               "O white  KQkq" \
 
164
                               "O r n b q k b n r" \
 
165
                               "O p p p p p p p p" \
 
166
                               "O . . . . . . . ." \
 
167
                               "O . . . . . . . ." \
 
168
                               "O . . . . . . . ." \
 
169
                               "O . . . . . . . ." \
 
170
                               "O P P P P P P P P" \
 
171
                               "O R N B Q K B N R" \
 
172
                               "O White (1)" \
 
173
                           "I next" \
 
174
                               "O 1. e4" \
 
175
                               "O black  KQkq  e3" \
 
176
                               "O r n b q k b n r" \
 
177
                               "O p p p p p p p p" \
 
178
                               "O . . . . . . . ." \
 
179
                               "O . . . . . . . ." \
 
180
                               "O . . . . P . . ." \
 
181
                               "O . . . . . . . ." \
 
182
                               "O P P P P . P P P" \
 
183
                               "O R N B Q K B N R" \
 
184
                               "O Black (1)" \
 
185
                           "I n" \
 
186
                               "O 1. c6" \
 
187
                               "O white  KQkq" \
 
188
                               "O r n b q k b n r" \
 
189
                               "O p p . p p p p p" \
 
190
                               "O . . p . . . . ." \
 
191
                               "O . . . . . . . ." \
 
192
                               "O . . . . P . . ." \
 
193
                               "O . . . . . . . ." \
 
194
                               "O P P P P . P P P" \
 
195
                               "O R N B Q K B N R" \
 
196
                               "O White (2)" \
 
197
                           "I last" \
 
198
                               "O 33. Qe7" \
 
199
                               "O white" \
 
200
                               "O . . r . . n k ." \
 
201
                               "O . . . . q p p ." \
 
202
                               "O . . . . p . . ." \
 
203
                               "O p . . n N . P ." \
 
204
                               "O P p N P . . . ." \
 
205
                               "O . P r R . Q . ." \
 
206
                               "O . . . . . P . ." \
 
207
                               "O . . . . R . K ." \
 
208
                               "O White (34)" \
 
209
                           "I previous" \
 
210
                               "O 33. hxg5" \
 
211
                               "O black" \
 
212
                               "O . . r . . n k ." \
 
213
                               "O . . q . . p p ." \
 
214
                               "O . . . . p . . ." \
 
215
                               "O p . . n N . P ." \
 
216
                               "O P p N P . . . ." \
 
217
                               "O . P r R . Q . ." \
 
218
                               "O . . . . . P . ." \
 
219
                               "O . . . . R . K ." \
 
220
                               "O Black (33)" \
 
221
                           "I p" \
 
222
                               "O 32. hxg5" \
 
223
                               "O white" \
 
224
                               "O . . r . . n k ." \
 
225
                               "O . . q . . p p ." \
 
226
                               "O . . . . p . . ." \
 
227
                               "O p . . n N . p ." \
 
228
                               "O P p N P . . . P" \
 
229
                               "O . P r R . Q . ." \
 
230
                               "O . . . . . P . ." \
 
231
                               "O . . . . R . K ." \
 
232
                               "O White (33)"]
 
233
    test_case "Command: level" [list "I level 40 1 2" \
 
234
                               "O Time Control: 40 moves in 60.00 secs" \
 
235
                               "O Fischer increment of 2 seconds" \
 
236
                               "O White (1)"]
 
237
    test_case "Command: list & name & result" [list "I list ?" \
 
238
                               "O name    - list known players alphabetically" \
 
239
                               "O score   - list by GNU best result first" \
 
240
                               "O reverse - list by GNU worst result first" \
 
241
                               "O White (1)" \
 
242
                               "I name Stuart" "I result" "I name Simon" "I result" \
 
243
                               "I list name" "O Simon" "O Stuart" "O White (1)"]
 
244
    file delete -force ./log.000
 
245
    file delete -force ./log.001
 
246
    file delete -force ./game.000
 
247
    file delete -force ./game.001
 
248
    file delete -force ./players.dat
 
249
    test_case "Command: memory" [list "I memory" "O Current HashSize is 256 MB" "O White (1)" \
 
250
                                      "I memory 128" "O Current HashSize is 128 MB"]
 
251
                                      # TODO FIX "I memory 128" "O Current HashSize is 128 MB" "O White (1)"]
 
252
    test_case "Command: new" [list "I new" "O White (1)" "I depth 1" "I e4" "O White (2)" "I new" "O White (1)"]
 
253
    # TODO FIX test_case "Command: post & nopost" [list "I post" "O 1 +" "O White (1)" "I nopost" "O White (1)"]
 
254
    test_case "Command: post & nopost" [list "I depth 1" "I post" "O White (1)" "I e4" "O White (2)" "I nopost" "O White (2)"]
 
255
    test_case "Command: null" [list "I null" "O Null-move heuristic is on." "O White (1)" "I null off" "O Null-move heuristic is off." "O White (1)" "I null" "O Null-move heuristic is off." "O White (1)" "I null on" "O Null-move heuristic is on." "O White (1)"]
 
256
    test_case "Command: otim" [list "I otim 1" "O White (1)"]
 
257
    test_case "Command: ping" [list "I ping" "O pong" "O White (1)"]
 
258
    # TODO FIX test_case "Command: protover" [list "xboard" "I protover" "O feature"]
 
259
    test_case "Command: quit" [list "I quit" "O "]
 
260
    test_case "Command: random" [list "I random" "O currently not supported" "O White (1)"]
 
261
    test_case "Command: rating" [list "I rating" "O my rating = 0, opponent rating = 0" "O White (1)"]
 
262
    test_case "Command: rejected" [list "I rejected" "O "]
 
263
    # FIX test_case "Command: remove" [list "I e4" \
 
264
                               #"O . . . . P . . ." \
 
265
                               #"O . . . . . . . ." \
 
266
                               #"O P P P P . P P P" \
 
267
                               #"O R N B Q K B N R" \
 
268
                               #"O White (2)" \
 
269
                           #"I remove" \
 
270
                               #"O . . . . . . . ." \
 
271
                               #"O . . . . . . . ." \
 
272
                               #"O P P P P . P P P" \
 
273
                               #"O R N B Q K B N R" \
 
274
                               #"O White (1)"]
 
275
    test_case "Command: setboard" [list "I setboard 2r2nk1/4qpp1/4p3/p2nN1P1/PpNP4/1PrR1Q2/5P2/4R1K1 w - - bm 1; id 1;" "O White (1)" "I show board" \
 
276
                               "O white" \
 
277
                               "O . . r . . n k ." \
 
278
                               "O . . . . q p p ." \
 
279
                               "O . . . . p . . ." \
 
280
                               "O p . . n N . P ." \
 
281
                               "O P p N P . . . ." \
 
282
                               "O . P r R . Q . ." \
 
283
                               "O . . . . . P . ." \
 
284
                               "O . . . . R . K ." \
 
285
                               "O White (1)"]
 
286
    test_case "Command: show" [list \
 
287
                           "I show board" \
 
288
                               "O white  KQkq" \
 
289
                               "O r n b q k b n r" \
 
290
                               "O p p p p p p p p" \
 
291
                               "O . . . . . . . ." \
 
292
                               "O . . . . . . . ." \
 
293
                               "O . . . . . . . ." \
 
294
                               "O . . . . . . . ." \
 
295
                               "O P P P P P P P P" \
 
296
                               "O R N B Q K B N R" \
 
297
                               "O White (1)" \
 
298
                           "I show rating" \
 
299
                               "O My rating =" \
 
300
                               "O Opponent rating =" \
 
301
                               "O White (1)" \
 
302
                           "I show time" \
 
303
                               "O White (1)" \
 
304
                           "I show moves" \
 
305
                               "O Na3" "O No. of moves generated =" \
 
306
                           "I show escape" \
 
307
                               "O No. of moves generated =" \
 
308
                           "I show noncapture" \
 
309
                               "O Na3" "O No. of moves generated =" \
 
310
                           "I show capture" \
 
311
                               "O No. of moves generated =" \
 
312
                           "I show eval" \
 
313
                               "O currently not supported" \
 
314
                           "I show score" \
 
315
                               "O currently not supported" \
 
316
                           "I e4" "I show game" \
 
317
                               "O White   Black" "O 1.  e4" "O White (2)" \
 
318
                           "I show pin" \
 
319
                               "O currently not supported"]
 
320
    test_case "Command: solve" [list "I depth 1" "I solve ./Polgar-Karpov.epd" "O Best move =" "O My move is :" "O Incorrect" "O Correct=" "O White (1)"]
 
321
    test_case "Command: solveepd" [list "I depth 1" "I solveepd ./Polgar-Karpov.epd" "O Best move =" "O My move is :" "O Incorrect" "O Total=" "O White (1)"]
 
322
    test_case "Command: st" [list "I st 1" "O White (1)"]
 
323
    test_case "Command: switch" [list "I switch" "O currently not supported" "O White (1)"]
 
324
    test_case "Command: test" [list "I test" "O currently not supported" "O White (1)"]
 
325
    test_case "Command: time" [list "I time 1" "O White (1)"]
 
326
    test_case "Command: undo" [list "I depth 1" "I e4" \
 
327
                               "O . . . . P . . ." \
 
328
                               "O . . . . . . . ." \
 
329
                               "O P P P P . P P P" \
 
330
                               "O R N B Q K B N R" \
 
331
                               "O White (2)" \
 
332
                           "I undo" \
 
333
                               "O . . . . P . . ." \
 
334
                               "O . . . . . . . ." \
 
335
                               "O P P P P . P P P" \
 
336
                               "O R N B Q K B N R" \
 
337
                               "O Black (1)" \
 
338
                           "I undo" \
 
339
                               "O . . . . . . . ." \
 
340
                               "O . . . . . . . ." \
 
341
                               "O P P P P P P P P" \
 
342
                               "O R N B Q K B N R" \
 
343
                               "O White (1)"]
 
344
    test_case "Command: usage" [list "I usage" "O Usage:" "O Options:" "O bug-gnu-chess@gnu.org" "O White (1)"]
 
345
    test_case "Command: usermove" [list "I usermove e4" "O White (2)"]
 
346
    test_case "Command: variant" [list "I variant" "O White (1)"]
 
347
    test_case "Command: version" [list "I version" "O GNU Chess 6" "O White (1)"]
 
348
    test_case "Command: xboard" [list "I depth 1" "I e4" "O move" "I new" "I xboard off" "I e4" "O My move is :" "O White (2)" "I new" "O White (1)" "I xboard on" "I e4" "O move"]
 
349
 
 
350
    # Print results
 
351
    puts "====================================================================="
 
352
    puts "\nTests results:\n\tPASS: $::n_pass\n\tFAIL: $::n_fail"
 
353
    if {$::n_fail == 0} {
 
354
        puts "  OK\n"
 
355
    } else {
 
356
        puts "  FAILURE\n"
 
357
        foreach title $::failed_test_cases {
 
358
            puts "\t$title"
 
359
        }
 
360
    }
 
361
}
 
362
 
 
363
set n_pass 0
 
364
set n_fail 0
 
365
set failed_test_cases [list]
 
366
set timeout 2
 
367
run