-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_assertions_work
executable file
·52 lines (46 loc) · 1.99 KB
/
test_assertions_work
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
#!/usr/bin/env bash
#Deduce this script's directory
if [ -z ${BASH_SOURCE} ]; then
script_dir=$(readlink -f $(dirname "${0}"))
else
script_dir="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
fi
source "${script_dir}/test_assertions"
function laugh_maniacally_and_exit() {
echo 'hahahahaahahaha
muahhahahaahaaa
phew'
return ${1}
}
[ ${run_tests} -eq 1 ] && echo '---Invalid argument tests---'
assert_result_fails_with_error_text "$(assert_exited_with_success 2>&1)" ${?} 'description' 'assert_exited_with_success no args'
assert_result_fails_with_error_text "$(assert_exited_with_success 'description' 2>&1)" ${?} 'exit code' 'assert_exited_with_success no exit code'
assert_result_fails_with_error_text "$(assert_contains_text 2>&1)" ${?} 'description' 'assert_contains_text no args'
assert_result_fails_with_error_text "$(assert_contains_text description 2>&1)" ${?} 'text' 'assert_contains_text no text'
assert_result_fails_with_error_text "$(assert_contains_text description 'input' 2>&1)" ${?} 'some text' 'assert_contains_text no terms'
if [ ${run_tests} -eq 1 ]
then
global_assert_errors=0
echo
echo '---Example tests---'
echo 'This should succeed'
laugh_maniacally_and_exit 0 >/dev/null
assert_exited_with_success 'Happy laughter' ${?}
echo "Global assert errors: ${global_assert_errors}"
echo
echo 'This should fail'
laugh_maniacally_and_exit 1 >/dev/null
assert_exited_with_success 'Sad laughter' ${?}
echo "Global assert errors: ${global_assert_errors}"
echo
echo 'This should find some text'
laugh_result=$(laugh_maniacally_and_exit 0)
assert_exited_with_success 'Textual laughter' ${?}
assert_contains_text 'laughed a lot' "${laugh_result}" 'muah' 'ha' 'phew'
echo "Global assert errors: ${global_assert_errors}"
echo
echo 'This should fail to find yuck and muck'
assert_contains_text 'laughed a lot text search' "${laugh_result}" 'muah' 'ha' 'phew' 'yuck' 'muck'
echo "Global assert errors: ${global_assert_errors}"
echo "And now the exit code is ${?}"
fi