Skip to content

Commit 692e4b6

Browse files
committed
Make help message test more dynamic
1 parent 554e59d commit 692e4b6

1 file changed

Lines changed: 37 additions & 2 deletions

File tree

functional_tests/Magphi-test.sh

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,41 @@ function test_exit_status {
164164
fi
165165
}
166166

167+
# Run a command and check that all expected strings appear in the output
168+
# ARG1: command we want to test as a string
169+
# ARG2: expected exit status
170+
# ARG3+: strings that must appear in the output
171+
function test_stdout_contains {
172+
let num_tests+=1
173+
local cmd=$1
174+
local expected_exit_status=$2
175+
shift 2
176+
local expected_strings=("$@")
177+
output=$(eval $cmd 2>&1)
178+
exit_status=$?
179+
verbose_message "Testing stdout contains strings: $cmd"
180+
local failed=0
181+
for s in "${expected_strings[@]}"; do
182+
if [[ "$output" != *"$s"* ]]; then
183+
let num_errors+=1
184+
echo "TEST FAILED!"
185+
echo "Test output failed (missing expected string): $cmd"
186+
echo "Expected to find: $s"
187+
echo "Actual output:"
188+
echo "$output"
189+
failed=1
190+
break
191+
fi
192+
done
193+
if [ "$failed" -eq 0 ] && [ "$exit_status" -ne "$expected_exit_status" ]; then
194+
let num_errors+=1
195+
echo "TEST FAILED!"
196+
echo "Test exit status failed: $cmd"
197+
echo "Actual exit status: $exit_status"
198+
echo "Expected exit status: $expected_exit_status"
199+
fi
200+
}
201+
167202
function call_new_test {
168203
echo ''
169204
echo $1
@@ -177,10 +212,10 @@ cd $test_data_dir
177212
## Test commandline exit status
178213
# Test output for no arguments
179214
call_new_test "Test output for no arguments"
180-
test_stdout_exit "$test_program" no_input.expected 2
215+
test_stdout_contains "$test_program" 2 "Magphi" "Welcome to Magphi" "--input_genomes" "--input_seeds" "--help"
181216
# Test output for -help argument given
182217
call_new_test "Test output for -help argument given"
183-
test_stdout_exit "$test_program -help" no_input.expected 0
218+
test_stdout_contains "$test_program -help" 0 "Magphi" "Welcome to Magphi" "--input_genomes" "--input_seeds" "--help"
184219
# Test exit status for a bad command line invocation
185220
call_new_test "Test exit status for a bad command line invocation"
186221
test_exit_status "$test_program --this_is_not_a_valid_argument > /dev/null 2>&1" 2

0 commit comments

Comments
 (0)