modified: src1/input.c
[GalaxyCodeBases.git] / c_cpp / lib / htslib / test / tabix / test-tabix.sh
blob358a3dd54ca9eae08aa2b79623e056913eac12a2
1 #!/bin/sh
3 # Copyright (C) 2017 Genome Research Ltd.
5 # Author: Robert Davies <rmd@sanger.ac.uk>
7 # Permission is hereby granted, free of charge, to any person obtaining a copy
8 # of this software and associated documentation files (the "Software"), to deal
9 # in the Software without restriction, including without limitation the rights
10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 # copies of the Software, and to permit persons to whom the Software is
12 # furnished to do so, subject to the following conditions:
14 # The above copyright notice and this permission notice shall be included in
15 # all copies or substantial portions of the Software.
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 # DEALINGS IN THE SOFTWARE.
25 # Executes a single test and compares against the expected output
26 run_test() {
27 # Expected result: pass (P) / fail (F) / nonzero exit (N)
28 p="$1"; shift
29 # File with expected output (empty or '.' if none)
30 e="$1"; shift
31 # Test result
32 r="P"
33 # Why the test failed
34 y=""
35 if [ "x$test_iter" = "x" ]
36 then
37 test_iter=1
38 else
39 test_iter=`expr $test_iter + 1`
41 result=`eval ${@+"$@"} 2>_err.tmp > _out.tmp`
42 if [ $? != 0 ]
43 then
44 if [ "$p" != "N" ]
45 then
46 # Expected zero exit code, got non-zero
47 r="F"
48 y="exit_code"
49 else
50 # Expected non-zero exit code and got it
51 r="P"
53 elif [ "$p" = "N" ]
54 then
55 # Expected non-zero exit code, but got zero
56 r="F"
57 y="exit_code"
58 elif [ "x$e" != "x" -a "$e" != "." ]
59 then
60 if cmp -s _out.tmp "$e"
61 then
62 # Output was as expected
63 r="P"
64 rm -f _out.tmp _err.tmp
65 else
66 # Output differed
67 r="F"
68 y="output"
70 else
71 # Expected zero exit code and got it.
72 r="P"
73 rm -f _out.tmp _err.tmp
76 if [ "$r" = "F" ]
77 then
78 # Test failed
79 case "$p" in
80 [PN])
81 echo "FAIL : $@"
82 if [ "x$e" != "x" -a "$e" != "." ]
83 then
84 keep_output="FAIL-$e.${test_iter}"
85 else
86 keep_output="FAIL.${test_iter}"
88 mv _out.tmp "${keep_output}.out"
89 mv _err.tmp "${keep_output}.err"
90 nufail=`expr $nufail + 1`
91 if [ "$y" = "exit_code" ]
92 then
93 if [ "$p" != "N" ]
94 then
95 echo "Got non-zero exit code"
96 else
97 echo "Got unexpected zero exit code"
99 echo "See ${keep_output}.{out,err} for output"
100 else
101 echo "Output differed from expected result"
102 echo "Compare $e ${keep_output}.out"
106 echo "XFAIL: $@"
107 nefail=`expr $nefail + 1`
109 esac
110 else
111 # Test passed
112 case "$p" in
113 "P")
114 echo "PASS : $@"
115 nepass=`expr $nepass + 1`
117 "N")
118 echo "PASS : $@ (must exit non-zero)"
119 nepass=`expr $nepass + 1`
122 echo "XPASS: $@"
123 nupass=`expr $nupass + 1`
125 esac
129 tabix_test() {
130 nupass=0; nepass=0
131 nufail=0; nefail=0
133 exec 9<"$1"
134 while read -r line <&9
136 set -- $line
137 case $1 in
138 "#"*) # skip comments
140 "") # skip blank lines too
143 "INIT")
144 shift
145 eval ${@+"$@"} > /dev/null
146 if [ $? != 0 ]
147 then
148 echo "INIT FAIL: $@"
149 return 1
154 p=$1;shift
155 o=$1;shift
156 run_test "$p" "$o" ${@+"$@"}
158 esac
159 done
160 exec 9<&-
162 echo ""
163 echo "Expected passes: $nepass"
164 echo "Unexpected passes: $nupass"
165 echo "Expected failures: $nefail"
166 echo "Unexpected failures: $nufail"
167 if [ "$nupass" -gt 0 -o "$nufail" -gt 0 ]
168 then
169 return 1
170 else
171 return 0
175 echo "Testing tabix..."
177 bgzip="../../bgzip"
178 tabix="../../tabix"
180 tabix_test $@
182 exit $?