-
Notifications
You must be signed in to change notification settings - Fork 25
/
test.example.sh
101 lines (81 loc) · 2.43 KB
/
test.example.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
function testcase_athena.example()
{
# asserting values
bashunit.test.assert_value "One" "One"
bashunit.test.assert_value.expects_fail "One" "Two"
# asserting return of functions
bashunit.test.assert_return "_my_example_function" "pass"
bashunit.test.assert_return.expects_fail "_my_example_function" "fail"
# asserting output of functions
bashunit.test.assert_output "_my_example_function" "OK" "pass"
bashunit.test.assert_output.expects_fail "_my_example_function" "OK" "fail"
# asserting exit codes
bashunit.test.assert_exit_code "_my_example_function_with_exit_0"
bashunit.test.assert_exit_code.expects_fail "_my_example_function_with_exit_1"
# mocking
bashunit.test.mock "_my_example_function" "_my_example_mock"
bashunit.test.assert_output "_my_example_function" "Now i am the mock"
bashunit.test.assert_exit_code.expects_fail "_my_example_function"
bashunit.test.mock.returns "my_mock" 3
bashunit.test.assert_return.expects_fail "my_mock"
bashunit.test.mock.outputs "my_mock" "my string"
bashunit.test.assert_output "my_mock" "my string"
bashunit.test.mock.exits "my_mock" 0
bashunit.test.assert_exit_code "my_mock"
bashunit.test.mock.exits "my_mock" 1
bashunit.test.assert_exit_code.expects_fail "my_mock"
bashunit.test.mock.outputs "_my_example_function" "my new string"
bashunit.test.assert_output "_my_example_function" "my new string"
bashunit.test.mock.returns "_my_example_function" 0
bashunit.test.assert_return "_my_example_function"
local multiline_string=$(cat <<EOF
{
"key": {}
}
EOF
)
bashunit.test.assert_output "_my_example_echo" "$multiline_string" "$multiline_string"
bashunit.test.assert_output "_my_example_echo_arguments" "$multiline_string" "$multiline_string"
bashunit.test.assert_string_contains "my string" "my"
bashunit.test.assert_string_contains.expects_fail "my string" "xpto"
multiline_string="$(cat <<EOF
my string: [xpto]
EOF
)"
bashunit.test.assert_string_contains "$multiline_string" "xpto]"
bashunit.test.assert_string_contains.expects_fail "$multiline_string" "xpto2]"
}
function _my_example_echo()
{
echo -n "$1"
}
function _my_example_echo_arguments()
{
echo -n "$@"
}
function _my_example_mock()
{
echo "Now i am the mock"
return 1
}
function _my_example_function()
{
case $1 in
"fail")
echo "NOT OK"
return 1
;;
*)
echo "OK"
return 0
;;
esac
}
function _my_example_function_with_exit_0()
{
exit 0
}
function _my_example_function_with_exit_1()
{
exit 1
}