-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_stxtyper.sh
executable file
·132 lines (116 loc) · 4.89 KB
/
test_stxtyper.sh
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
#!/bin/bash
if [ "$1" == "path" ]
then
echo "Testing stxtyper command in your \$PATH"
which stxtyper
STXTYPER=stxtyper
else
echo "Testing ./stxtyper"
echo " To test stxtyper in your path run 'test_stxtyper.sh path'"
STXTYPER=./stxtyper
fi
if [ ! -e "test/basic.expected" ]
then
echo "test/basic.expected not found, downloading new test data"
echo "from https://raw.githubusercontent.com/ncbi/stxtyper/main/"
mkdir test
pushd test
curl --location --silent -O https://raw.githubusercontent.com/ncbi/stxtyper/main/test/amrfinder_integration.expected \
-O https://raw.githubusercontent.com/ncbi/stxtyper/main/test/amrfinder_integration.fa \
-O https://raw.githubusercontent.com/ncbi/stxtyper/main/test/amrfinder_integration2.expected \
-O https://raw.githubusercontent.com/ncbi/stxtyper/main/test/amrfinder_integration2.fa \
-O https://raw.githubusercontent.com/ncbi/stxtyper/main/test/basic.expected \
-O https://raw.githubusercontent.com/ncbi/stxtyper/main/test/basic.fa \
-O https://raw.githubusercontent.com/ncbi/stxtyper/main/test/basic.nuc_out.expected \
-O https://raw.githubusercontent.com/ncbi/stxtyper/main/test/cases.expected \
-O https://raw.githubusercontent.com/ncbi/stxtyper/main/test/cases.fa \
-O https://raw.githubusercontent.com/ncbi/stxtyper/main/test/synthetics.expected \
-O https://raw.githubusercontent.com/ncbi/stxtyper/main/test/synthetics.fa \
-O https://raw.githubusercontent.com/ncbi/stxtyper/main/test/virulence_ecoli.expected \
-O https://raw.githubusercontent.com/ncbi/stxtyper/main/test/virulence_ecoli.fa
popd
fi
# globals updated by function test_input_file
FAILURES=0
TESTS=0
TEST_TEXT=''
# echo "TERM=$TERM"
# some color macros
if [ "$TERM" == "" ] || [ "$TERM" == "dumb" ] || [ ! -t 1 ]
then
green='' # no colors
red=''
bold=''
reset=''
else
green=`tput setaf 2` # Set green foreground color (code 2)
red=`tput setaf 1` # Set red foreground color (code 1)
bold=`tput bold` # Set bold
reset=`tput sgr0` # Reset color to default
fi
function test_input_file {
local test_base="$1"
local options="$2"
TESTS=$(( $TESTS + 1 ))
if ! $STXTYPER $options -n "test/$test_base.fa" > "test/$test_base.got"
then
echo "${red}not ok: $STXTYPER returned a non-zero exit value indicating a failure of the software${reset}"
echo "# $STXTYPER $options -n test/$test_base.fa > test/$test_base.got"
TEST_TEXT="$TEST_TEXT"$'\n'"${red}Failed $test_base${reset}"
return 1
else
if ! diff -q "test/$test_base.expected" "test/$test_base.got"
then
echo "${red}not ok: $STXTYPER returned output different from expected${reset}"
echo "# $STXTYPER $options -n test/$test_base.fa > test/$test_base.got"
echo "# diff test/$test_base.expected test/$test_base.got"
diff "test/$test_base.expected" "test/$test_base.got"
echo "# To approve run:"
echo "# mv test/$test_base.got test/$test_base.expected "
TEST_TEXT="$TEST_TEXT"$'\n'"${red}Failed $test_base${reset}"
return 1
else
echo "${green}ok:${reset} test/$test_base.fa"
return 0
fi
fi
}
test_input_file 'basic' '--nucleotide_output test/basic.nuc_out.got'
FAILURES=$(( $? + $FAILURES ))
# test --nucleotide_output option
TESTS=$(( $TESTS + 1 ))
if ! diff -q "test/basic.nuc_out.expected" "test/basic.nuc_out.got"
then
echo "${red}not ok: $STXTYPER returned --nucleotide_output file different from expected${reset}"
echo "# $STXTYPER --nucleotide_output test/basic.nuc_out.got -n test/basic.fa > test/basic.got"
echo "# diff test/basic.nuc_out.expected test/basic.nuc_out.got"
diff "test/basic.nuc_out.expected" "test/basic.nuc_out.got"
echo "# To approve run:"
echo "# mv test/basic.nuc_out.got test/basic.nuc_out.expected "
TEST_TEXT="$TEST_TEXT"$'\n'"${red}Failed basic --nucleotide_output test${reset}"
FAILURES=$(( $FAILURES + 1 ))
else
echo "${green}ok:${reset} --nucleotide_output test/basic.nuc_out.got options worked"
fi
test_input_file 'synthetics'
FAILURES=$(( $? + $FAILURES ))
test_input_file 'virulence_ecoli' '--threads 4'
FAILURES=$(( $? + $FAILURES ))
test_input_file 'cases'
FAILURES=$(( $? + $FAILURES ))
test_input_file 'amrfinder_integration' '--amrfinder'
FAILURES=$(( $? + $FAILURES ))
test_input_file 'amrfinder_integration2' '--amrfinder --print_node'
FAILURES=$(( $? + $FAILURES ))
echo "Done."
echo "$TEST_TEXT"
echo ""
if [ "$FAILURES" -gt 0 ]
then
PASSED=$(( $TESTS - $FAILURES ))
echo "${red}not ok overall: $FAILURES out of $TESTS stxtyper tests failed${reset}"
exit 1
else
echo "${green}ok: all $TESTS stxtyper tests passed${reset}"
echo "${green}${bold}Success!${reset}"
fi