File: test-cli.in

package info (click to toggle)
freesasa 2.1.2-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,740 kB
  • sloc: ansic: 11,281; cpp: 1,342; sh: 397; perl: 169; makefile: 119; yacc: 87; lex: 54
file content (486 lines) | stat: -rw-r--r-- 20,570 bytes parent folder | download | duplicates (3)
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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
#!/bin/bash

# The tests here mainly check that errors are caught and that
# execution is successful in normal cases. For some cases the output
# is compared with reference output, but the correctness of
# calculations is generally handled by the unit tests.

# Making this a .in-file was necessary to get 'make distcheck' to work

cli=../src/freesasa
datadir=@top_srcdir@/tests/data
sharedir=@top_srcdir@/share/
dump=tmp/test-cli.dump # will only contain the latest output
nofile=nonexistent-file
nodir=nonexistent-dir/file
smallpdb=$datadir/rsa/GLY.pdb
#global errors
errors=0
use_xml=0
if [[ "x@USE_XML@" = "xyes" ]] ; then
    use_xml=1
fi
use_xmllint=0
if [[ "x@XMLLINT@" = "xxmllint" ]] ; then
    use_xmllint=1
fi
use_json=0
if [[ "x@USE_JSON@" = "xyes" ]] ; then
    use_json=1
fi
use_jsonlint=0
if [[ "x@JSONLINT@" = "xjsonlint" ]] ; then
    use_jsonlint=1
fi


function assert_pass
{
    eval $1
    if [[ $? -ne 0 ]]; then
        echo Error: \"$1\" failed
        let errors=errors+1
    #else
    #    echo \"$1\" successful
    fi
}

function assert_fail
{
    eval $1 2>/dev/null
    if [[ $? -eq 0 ]]; then
        echo Error: \"$1\" did not fail as expected
        let errors=errors+1
    #else
    #    echo \"$1\" failed as expected;
    fi
}

function assert_equal_opt
{
    tmp1=tmp/tmp1
    tmp2=tmp/tmp2
    eval $1 $2 > $tmp1 2>/dev/null
    eval $1 $3 > $tmp2 2>/dev/null
    diff -B $tmp1 $tmp2
    if [[ $? -ne 0 ]]; then
        echo Error: \"$1\" gives different results with arguments \"$2\" and \"$3\"
        let errors=errors+1
    #else
    #    echo \"$1\" gives same result with arguments \"$2\" and \"$3\". Success.
    fi
}

function assert_equal_total
{
    tmp1=tmp/tmp1
    tmp2=tmp/tmp2

    eval $1 $2 | grep "Total" > $tmp1 2>/dev/null
    if [[ $? -ne 0 ]]; then
        echo Error: \"$1 $2\" fails
        let errors=errors+1
    fi

    eval $1 $3 | grep "Total" > $tmp2 2>/dev/null
    if [[ $? -ne 0 ]]; then
        echo Error: \"$1 $3\" fails
        let errors=errors+1
    fi

    diff $tmp1 $tmp2
    if [[ $? -ne 0 ]]; then
        echo Error: \"$1\" gives different results with arguments \"$2\" and \"$3\"
        let errors=errors+1
    #else
    #    echo \"$1\" gives same result with arguments \"$2\" and \"$3\". Success.
    fi
}

if [[ ! -d tmp ]]; then mkdir tmp; fi

rm -f tmp/*
echo
echo "== Basic file errors =="
assert_fail "$cli > $dump"
assert_fail "$cli $nofile > $dump"
assert_fail "$cli < $nofile > $dump"
assert_fail "$cli -c $nofile < $smallpdb > $dump"
assert_fail "$cli < $smallpdb > $nodir"
assert_fail "$cli -e $nodir $smallpdb"
assert_fail "$cli -o $nodir $smallpdb"
# can only have one output
assert_fail "$cli -o $dump -o $dump $smallpdb"
# deprecated
assert_fail "$cli --B-value-file $nodir < $smallpdb > $dump"
assert_fail "$cli --residue-type-file $nodir < $smallpdb > $dump"
assert_fail "$cli --residue-file $nodir < $smallpdb > $dump"

echo
echo "== General options =="
# unknown options
assert_fail "$cli --blablabla $smallpdb"
assert_fail "$cli -x $smallpdb"
# no option argument
assert_fail "$cli $smallpdb -o"
# help message
assert_pass "$cli -h > $dump 2> /dev/null"
assert_pass "$cli --deprecated > $dump 2> /dev/null"
# check that it's a valid version number
version=`$cli -v | head -n 1`
assert_pass "echo $version | perl -ne 'if (m/FreeSASA (\d+\.)*\d(-beta)?$/) {exit 0} else  {exit 1}'"
# check that running with several output options doesn't crash
assert_pass "$cli -o $dump -e tmp/err -n 1 $smallpdb"

echo
echo "== Testing S&R =="
assert_pass "$cli -S <  $datadir/1ubq.pdb > $dump"
echo
#check that output message has required components, also verifies that basics of computation still work
assert_pass "grep 'source\s\s*: stdin' $dump"
$cli -S  $datadir/1ubq.pdb > $dump
assert_pass "grep 'source\s\s*: $datadir/1ubq.pdb' $dump"
assert_pass "grep 'atoms\s\s*: 602' $dump"
assert_pass "grep 'probe-radius\s\s*: [[:digit:]]' $dump"
assert_pass "grep 'threads\s\s*: [[:digit:]]' $dump"
assert_pass "grep 'testpoints\s\s*: [[:digit:]]' $dump"
assert_pass "grep 'algorithm\s\s*: \w' $dump"
assert_pass "grep 'Total\s\s*:\s\s*4834.72' $dump"
assert_pass "grep 'Polar\s\s*:\s\s*2515.82' $dump"
assert_pass "grep 'Apolar\s\s*:\s\s*2318.90' $dump"
# The above formulation of log output gives freedom in ordering and
# whitespace, and also version. Allows non-essential details to change
# without breaking the test. Will not be performed for variant
# parameter values, those should be covered by tests.
assert_pass "$cli -S -Y $datadir/1d3z.pdb -w > $dump"
assert_pass "grep 'atoms\s\s*: 1231' $dump"
assert_pass "grep 'Total\s\s*:\s\s*5035.61' $dump"
assert_pass "$cli -S -H -w $datadir/1ubq.pdb > $dump" # suppress warnings here
assert_pass "grep 'atoms\s\s*: 660' $dump"
assert_pass "grep 'Total\s\s*:\s\s*5656.65' $dump"
assert_pass "$cli -S -n 50 < $datadir/1ubq.pdb > $dump"
assert_fail "$cli -S -n 0 < $datadir/1ubq.pdb > $dump"
assert_fail "$cli -S -n \"-1\" < $datadir/1ubq.pdb > $dump"
assert_fail "$cli -S -t 1000 < $datadir/1ubq.pdb > $dump"
assert_pass "$cli -S -t 16 < $smallpdb > $dump"

echo
echo "== Testing -m -M and -C options =="
# using flags -S and -n 10 to speed things up
assert_pass "$cli -n 2 -S -M $datadir/1d3z.pdb > $dump"
n_mod=`grep 1d3z.pdb $dump | wc -l`
assert_pass "test $n_mod -eq 10"
assert_pass "$cli -n 2 -S -C $datadir/1d3z.pdb > $dump"
n_mod=`grep 1d3z.pdb $dump | wc -l`
assert_pass "test $n_mod -eq 1"
assert_pass "$cli -n 2 -S -M -C $datadir/1d3z.pdb > $dump"
n_mod=`grep 1d3z.pdb $dump | wc -l`
assert_pass "test $n_mod -eq 10"
assert_pass "$cli -n 2 -S -M $datadir/2jo4.pdb > $dump"
n_mod=`grep 2jo4.pdb $dump | wc -l`
assert_pass "test $n_mod -eq 10"
assert_pass "$cli -n 2 -S -C $datadir/2jo4.pdb > $dump"
n_mod=`grep 2jo4.pdb $dump | wc -l`
assert_pass "test $n_mod -eq 4"
assert_pass "$cli -n 2 -S -M -C  $datadir/2jo4.pdb > $dump"
n_mod=`grep 2jo4.pdb $dump | wc -l`
assert_pass "test $n_mod -eq 40"
assert_fail "$cli -mM $datadir/2jo4.pdb > $dump"

echo
echo "== Testing L&R =="
assert_pass "$cli -L < $smallpdb > $dump"
assert_pass "$cli -L -n 10 < $smallpdb > $dump"
assert_fail "$cli -L -n 0 < $smallpdb > $dump"
assert_fail "$cli -L -n \"-1\" < $smallpdb > $dump"
assert_fail "$cli -L -t 1000 < $datadir/1ubq.pdb > $dump"
assert_pass "$cli -L -t 16 < $smallpdb > $dump"

echo
echo "== Testing option --chain-groups =="
assert_pass "$cli -g S -S -n 10 $smallpdb > $dump"
assert_fail "$cli -g B -S -n 10 $smallpdb > $dump"
assert_pass "$cli -g AB -S -n 10 $datadir/2jo4.pdb > $dump"
assert_fail "$cli -g E -S -n 10 $datadir/2jo4.pdb > $dump"
assert_pass "$cli -g AB+CD -S -n 10 $datadir/2jo4.pdb > $dump"
assert_fail "$cli -g A-B -S -n 10 $datadir/2jo4.pdb > $dump"
assert_fail "$cli -g AB -S -n 10 $smallpdb > $dump"
assert_fail "$cli -g A+B -S -n 10 $smallpdb > $dump"

echo
echo "== Testing probe radius =="
assert_fail "$cli -S -n 10 -p=-1 < $datadir/1ubq.pdb > $dump"
assert_pass "$cli -S -n 10 -p 1 < $datadir/1ubq.pdb > $dump"
assert_pass "$cli -S -p 1.4 --format=pdb < $datadir/1ubq.pdb | grep -v REMARK > tmp/bfactor.pdb"
assert_pass "diff tmp/bfactor.pdb $datadir/1ubq.B.pdb"

echo
echo "== Testing option --unknown =="
assert_pass "$cli --unknown=guess -Y -w -n 2  $datadir/1d3z.pdb > $dump"
assert_pass "grep 1231 $dump"
assert_pass "$cli --unknown=skip -Y -w -n 2 $datadir/1d3z.pdb > $dump"
assert_pass "grep 602 $dump"
assert_fail "$cli --unknown=halt -Y -w -n 2 $datadir/1d3z.pdb > $dump"
# misspelling should fail
assert_fail "$cli --unknown=haltt -Y -w -n 2 $datadir/1d3z.pdb > $dump"

echo
echo "== Testing option --cif =="
assert_equal_total "$cli" "$datadir/1ubq.pdb" "$datadir/1ubq.cif --cif"
assert_equal_total "$cli" "$datadir/1d3z.pdb" "$datadir/1d3z.cif --cif"
assert_equal_total "$cli" "$datadir/2jo4.pdb" "$datadir/2jo4.cif --cif"
assert_equal_total "$cli" "$datadir/5hdn.pdb" "$datadir/5hdn.cif --cif"
assert_equal_total "$cli" "$datadir/3bkr.pdb" "$datadir/3bkr.cif --cif"
assert_equal_total "$cli -w" "$datadir/3gnn.pdb" "$datadir/3gnn.cif --cif"
assert_equal_total "$cli --join-models" "$datadir/2jo4.pdb" "$datadir/2jo4.cif --cif"
assert_equal_total "$cli --chain-groups AB+CD -S -n 10" "$datadir/2jo4.pdb" "$datadir/2jo4.cif --cif"
assert_pass "$cli --cif --separate-models --format=cif $datadir/1ubq.cif > $dump"
assert_pass "$cli --cif --format=cif $datadir/1ubq.cif > $dump"
assert_pass "$cli --cif --format=cif --separate-chains $datadir/1ubq.cif > $dump"
assert_pass "$cli --cif --format=cif --separate-chains --separate-models $datadir/1ubq.cif > $dump"
assert_fail "$cli --cif --format=pdb $datadir/1ubq.cif > $dump"
assert_fail "$cli --format=cif $datadir/1ubq.pdb > $dump"

echo
echo "== Testing --separate-chains and --separate-models output are equal between cif and pdb"
assert_equal_total "$cli --separate-chains -S -n 10" "$datadir/2jo4.pdb" "$datadir/2jo4.cif --cif"
assert_equal_total "$cli --separate-chains -S -n 10" "$datadir/2isk.pdb" "$datadir/2isk.cif --cif"
assert_equal_total "$cli --separate-chains -S -n 10" "$datadir/1sui.pdb" "$datadir/1sui.cif --cif"
assert_equal_total "$cli --separate-chains -S -n 10" "$datadir/5dx9.pdb" "$datadir/5dx9.cif --cif"

# need input files with multiple models
assert_equal_total "$cli --separate-models -S -n 10" "$datadir/2jo4.pdb" "$datadir/2jo4.cif --cif"
assert_equal_total "$cli --separate-models -S -n 10" "$datadir/2isk.pdb" "$datadir/2isk.cif --cif"
assert_equal_total "$cli --separate-models -S -n 10" "$datadir/1sui.pdb" "$datadir/1sui.cif --cif"
assert_equal_total "$cli --separate-models -S -n 10" "$datadir/1d3z.pdb" "$datadir/1d3z.cif --cif"
# need input files with multiple models
assert_equal_total "$cli --separate-chains --separate-models -S -n 10" "$datadir/2jo4.pdb" "$datadir/2jo4.cif --cif"
assert_equal_total "$cli --separate-chains --separate-models -S -n 10" "$datadir/2isk.pdb" "$datadir/2isk.cif --cif"
assert_equal_total "$cli --separate-chains --separate-models -S -n 10" "$datadir/1sui.pdb" "$datadir/1sui.cif --cif"
assert_equal_total "$cli --separate-chains --separate-models -S -n 10" "$datadir/1d3z.pdb" "$datadir/1d3z.cif --cif"

echo
echo "== Testing user-configurations =="
assert_pass "$cli -c $sharedir/naccess.config -n 3 < $smallpdb > $dump"
assert_pass "$cli -c $sharedir/oons.config -n 3 < $smallpdb > $dump"
assert_fail "$cli -c $datadir/err.config -n 3 < $smallpdb > $dump"
# can't combine these options
assert_fail "$cli -c $datadir/naccess.config -n 3 -O < $smallpdb > $dump"
assert_fail "$cli -c $datadir/naccess.config -n 3 --radii=naccess < $smallpdb > $dump"

echo
echo "== Testing --radii" ==
assert_pass "$cli --radii=naccess -n 3 < $datadir/1ubq.pdb > tmp/static.dat"
assert_pass "$cli -c $sharedir/naccess.config -n 3 < $datadir/1ubq.pdb > tmp/from_config.dat"
assert_pass "diff tmp/static.dat tmp/from_config.dat"
assert_pass "$cli --radii=protor -n 3 < $datadir/1ubq.pdb > tmp/static.dat"
assert_pass "$cli -c $sharedir/protor.config -n 3 < $datadir/1ubq.pdb > tmp/from_config.dat"
assert_pass "diff tmp/static.dat tmp/from_config.dat"
assert_fail "$cli --radii=bla -n 3 < $datadir/1ubq.pdb > $dump"

echo
echo "== Testing res format =="
assert_pass "$cli -S --format=res -o tmp/restype -e $dump < $datadir/1ubq.pdb"
assert_pass "diff tmp/restype $datadir/restype.reference"
#deprecated
assert_pass "$cli -S -r < $datadir/1ubq.pdb > tmp/restype"
assert_pass "diff tmp/restype $datadir/restype.reference"

echo
echo "== Testing seq format =="
assert_pass "$cli -S --format=seq -o tmp/seq < $datadir/1ubq.pdb"
assert_pass "diff tmp/seq $datadir/seq.reference"
#deprecated
assert_pass "$cli -S -R < $datadir/1ubq.pdb > tmp/seq"
assert_pass "diff tmp/seq $datadir/seq.reference"

echo
echo "== Testing PDB output format =="
assert_pass "$cli -S --format=pdb < $datadir/1ubq.pdb | grep -v REMARK > tmp/bfactor.pdb"
assert_pass "diff tmp/bfactor.pdb $datadir/1ubq.B.pdb"
#deprecated
assert_pass "$cli -S -B < $datadir/1ubq.pdb | grep -v REMARK > tmp/bfactor.pdb"
assert_pass "diff tmp/bfactor.pdb $datadir/1ubq.B.pdb"

echo
echo "== Testing RSA format =="
for r in protor naccess
do
    for p in $(ls $datadir/rsa/*.pdb)
    do
        rel=$($cli -L -n 1000 $p --format=rsa --radii=$r | grep "S   2" | sed "s/[[:space:]]\{1,\}/ /g" | cut -f 6,8,10,12,14 -d ' ')
        if [[ $p == *"GLY"* ]]
        then
            assert_pass "test '$rel' = '100.0 N/A 100.0 100.0 100.0' && test $p"
        else
            assert_pass "test '$rel' = '100.0 100.0 100.0 100.0 100.0' && test $p"
        fi
    done
done
assert_fail "$cli --format=rsa -C $smallpdb"
assert_fail "$cli --format=rsa -M $smallpdb"
assert_pass "$cli -L -n 1000 --format=rsa -O -w $datadir/rsa/ALA.pdb > tmp/no_rel"
rel=$(grep "S   2" tmp/no_rel | sed "s/[[:space:]]\{1,\}/ /g" | cut -f 6,8,10,12,14 -d ' ')
assert_pass "test '$rel' = 'N/A N/A N/A N/A N/A'"
# deprecated
assert_pass "$cli --rsa $datadir/1ubq.pdb > $dump"

echo "== Verify idempotency of CIF format =="
assert_equal_opt "$cli --cif --format=cif $datadir/1ubq.cif" "" " | $cli --cif --format=cif"
assert_equal_opt "$cli --cif --format=cif --separate-chains $datadir/2jo4.cif" "" " | $cli --separate-chains --cif --format=cif"
assert_equal_opt "$cli --cif --format=cif --separate-models $datadir/2jo4.cif" "" " | $cli --separate-models --cif --format=cif"
assert_equal_opt "$cli --cif --format=cif --separate-models --separate-chains $datadir/2jo4.cif" "" \
    " | $cli --separate-models --separate-chains --cif --format=cif"

# XML // very basic testing, just to make sure XML is valid and that the right tags are present
if [[ use_xml -eq 1 ]] ; then
    echo
    echo "== Testing XML =="
    xml_file=tmp/test.xml

    assert_pass "$cli --format=xml $smallpdb > $xml_file"
    if [[ use_xmllint -eq 1 ]] ; then assert_pass "xmllint $xml_file > $dump"; fi

    assert_pass "$cli --format=xml --depth=atom $smallpdb > $xml_file"
    if [[ use_xmllint -eq 1 ]] ; then assert_pass "xmllint $xml_file > $dump"; fi
    assert_pass "grep '<atom' $xml_file > $dump"
    assert_pass "grep '<residue' $xml_file > $dump"
    assert_pass "grep '<chain' $xml_file > $dump"

    assert_pass "$cli --format=xml --depth=residue $smallpdb > $xml_file"
    if [[ use_xmllint -eq 1 ]] ; then assert_pass "xmllint $xml_file > $dump"; fi
    assert_fail "grep '<atom' $xml_file > $dump"
    assert_pass "grep '<residue' $xml_file > $dump"
    assert_pass "grep '<chain' $xml_file > $dump"

    assert_pass "$cli --format=xml --depth=chain $smallpdb > $xml_file"
    if [[ use_xmllint -eq 1 ]] ; then assert_pass "xmllint $xml_file > $dump"; fi
    assert_fail "grep '<atom' $xml_file > $dump"
    assert_fail "grep '<residue' $xml_file > $dump"
    assert_pass "grep '<chain' $xml_file > $dump"

    assert_pass "$cli --format=xml --depth=structure $smallpdb > $xml_file"
    if [[ use_xmllint -eq 1 ]] ; then assert_pass "xmllint $xml_file > $dump"; fi
    assert_fail "grep '<atom' $xml_file > $dump"
    assert_fail "grep '<residue' $xml_file > $dump"
    assert_fail "grep '<chain' $xml_file > $dump"

    assert_pass "$cli --format=xml -C $datadir/2jo4.pdb > $xml_file"
    if [[ use_xmllint -eq 1 ]] ; then assert_pass "xmllint $xml_file > $dump"; fi
    assert_fail "grep '<selection' $xml_file > $dump"

    assert_pass "$cli --format=xml -C $smallpdb --select=\"ala, resn ala\" --select=\"C, name C\" > $xml_file"
    if [[ use_xmllint -eq 1 ]] ; then assert_pass "xmllint $xml_file > $dump"; fi
    assert_pass "grep '<selection' $xml_file > $dump"

    # misspelling
    assert_fail "$cli --format=xml --depth=structures $smallpdb > $xml_file"
fi
# JSON // very basic testing, just to make sure JSON is valid and that the right tags are present
if [[ use_json -eq 1 ]] ; then
    echo
    echo "== Testing JSON =="
    json_file=tmp/test.json
    assert_pass "$cli --format=json $smallpdb > $json_file"
    if [[ use_jsonlint -eq 1 ]] ; then assert_pass "jsonlint $json_file > $dump"; fi

    assert_pass "$cli --format=json --depth=atom $smallpdb > $json_file"
    if [[ use_jsonlint -eq 1 ]] ; then assert_pass "jsonlint $json_file > $dump"; fi
    assert_pass "grep 'atom' $json_file > $dump"
    assert_pass "grep 'residue' $json_file > $dump"
    assert_pass "grep 'chain' $json_file > $dump"

    assert_pass "$cli --format=json -C $datadir/2jo4.pdb > $json_file"
    if [[ use_jsonlint -eq 1 ]] ; then assert_pass "jsonlint $json_file > $dump"; fi
    assert_fail "grep 'selection' $json_file > $dump"

    assert_pass "$cli --format=json $smallpdb --select=\"ala, resn ala\" --select=\"C, name C\" > $json_file"
    if [[ use_jsonlint -eq 1 ]] ; then assert_pass "jsonlint $json_file > $dump"; fi
    assert_pass "grep 'selection' $json_file > $dump"
fi

echo
echo "== Testing option --select =="
assert_pass "$cli -S --select \"s1, resn ala\" --select \"s2, resn arg\" --select \"s3, resi 1\" $datadir/1ubq.pdb > tmp/select"
sel_ala=$(grep s1 tmp/select | cut -f 2 -d ':' | sed 's/\ //g')
res_ala=$(grep ALA tmp/restype | cut -f 2 -d ':' | sed 's/\ //g')
if [ "$res_ala" != "$sel_ala" ];
then
    let errors=errors+1
    echo "Error: --format=res and --select don't give same result for ALA ('$res_ala' and '$sel_ala')"
fi
sel_arg=$(grep s2 tmp/select | cut -f 2 -d ':' | sed 's/\ //g' | sed s/A2//)
res_arg=$(grep ARG tmp/restype | cut -f 2 -d ':' | sed 's/\ //g' | sed s/A2// | sed s/ARG//)
if [ "$res_arg" != "$sel_arg" ]
then
    let errors=errors+1
    echo "Error: --format=res and --select don't give same result for ARG ('$res_arg' and '$sel_arg')"
fi
sel_res1=$(grep s3 tmp/select | cut -f 2 -d ':' | sed 's/\ //g' | sed s/A2//)
seq_res1=$(grep " 1 " tmp/seq | cut -f 2 -d ':' | cut -f 2 -d 'T' | sed 's/ //g')
if [ "$seq_res1" != "$sel_res1" ]
then
    let errors=errors+1
    echo "Error: --format=seq and --select don't give same result for first residue in 1ubq.pdb ('$seq_res1' and '$sel_res1')"
fi

echo
echo
echo "== Testing multithreading =="
assert_pass "$cli -t 1 -S -n 10 < $smallpdb > $dump"
assert_pass "$cli -t 2 -S -n 10 < $smallpdb > $dump"
assert_pass "$cli -t 10 -S -n 10 < $smallpdb > $dump"
assert_pass "$cli -t 1 -L -n 3 < $smallpdb > $dump"
assert_pass "$cli -t 2 -L -n 3 < $smallpdb > $dump"
assert_pass "$cli -t 10 -L -n 3 < $smallpdb > $dump"
assert_fail "$cli -t 0 < $smallpdb > $dump"

echo
echo "== Testing input with residue insertions ==="
assert_pass "test $($cli -n 2 --format=seq < $datadir/icode.pdb | grep ^SEQ | wc -l) -eq 5"

echo
echo "== Testing conflicting options =="
assert_fail "$cli -m -M $smallpdb > $dump"
assert_fail "$cli -g A+B -C $smallpdb > $dump"
assert_fail "$cli -c $sharedir/naccess.config --radii=naccess $smallpdb > $dump"
assert_fail "$cli -O --radii=naccess $smallpdb > $dump"
assert_fail "$cli -c $sharedir/naccess.config -O $datadir/1ubq.pdb > $dump"

echo
echo "== Testing long-options =="
assert_equal_opt "$cli $smallpdb" "-h" "--help"
assert_equal_opt "$cli $smallpdb" "-v" "--version"
assert_equal_opt "$cli $smallpdb" "-S -n 10" "--shrake-rupley -n 10"
assert_equal_opt "$cli $smallpdb" "-L -n 3 " "--lee-richards -n 3 "
assert_equal_opt "$cli $smallpdb" "-p 1.5 -n 3" "--probe-radius=1.5 -n 3"
assert_equal_opt "$cli $smallpdb" "-L -n 3 " "-L --resolution=3 "
assert_equal_opt "$cli $smallpdb" "-n 5" "--resolution=5"
assert_equal_opt "$cli $smallpdb" "-t 4" "--n-threads=4"
assert_equal_opt "$cli $smallpdb" "-c $sharedir/naccess.config" "--config-file=$sharedir/naccess.config"
assert_equal_opt "$cli $smallpdb" "-H -w" "--hetatm -w"
assert_equal_opt "$cli $datadir/1d3z.pdb" "-Y -n 2" "--hydrogen -n 2"
assert_equal_opt "$cli $datadir/1d3z.pdb" "-m -n 2" "--join-models -n 2"
assert_equal_opt "$cli $datadir/1d3z.pdb" "-C -n 2" "--separate-chains -n 2"
assert_equal_opt "$cli $datadir/1d3z.pdb" "-M -n 2" "--separate-models -n 2"
assert_equal_opt "$cli $smallpdb" "-w -n 2" "--no-warnings -n 2"
assert_equal_opt "$cli $datadir/2jo4.pdb" "-g AB+CD -n 2" "--chain-groups AB+CD -n 2"
assert_equal_opt "$cli $datadir/2jo4.pdb" "-g AB+CD -n 2" "-g AB -g CD -n 2"
assert_equal_opt "$cli $datadir/1ubq.B.pdb" "-O -n 2" "--radius-from-occupancy -n 2"
assert_equal_opt "$cli $smallpdb" "-f xml -n 2" "--format=xml -n 2"
# deprecated, just check that the program doesn't choke
assert_equal_opt "$cli $smallpdb" "-r -n 2" "--foreach-residue-type -n 2"
assert_equal_opt "$cli $smallpdb" "-R -n 2" "--foreach-residue -n 2"
assert_equal_opt "$cli $smallpdb" "-B -n 2" "--print-as-B-values -n 2"
assert_equal_opt "$cli $smallpdb" "-l -n 2" "--no-log -n 2"

rm -f tmp/*

echo
echo "There where $errors errors."
echo
if [ $errors -gt 0 ]; then
    exit $errors
else
    exit 0
fi