-
Notifications
You must be signed in to change notification settings - Fork 0
/
matchers.test.sh
executable file
·97 lines (73 loc) · 2.08 KB
/
matchers.test.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
#!/usr/bin/env zsh
source "$__ZSH_SCRIPTEST_HOME/matchers.sh"
source "$__ZSH_SCRIPTEST_HOME/test_util.sh"
function test_assert_equal() {
test_case_title
(eval 'assert_equal "1" "1"')
[[ "$?" == "0" ]] || exit 1
(eval 'assert_equal "1" "2"')
[[ "$?" == "1" ]] || exit 1
}
function test_assert_empty() {
test_case_title
(eval 'assert_empty "not empty"')
[[ "$?" == "1" ]] || exit 1
(eval 'assert_empty ""')
[[ "$?" == "0" ]] || exit 1
}
function test_assert_not_empty() {
test_case_title
(eval 'assert_not_empty "not empty"')
[[ "$?" == "0" ]] || exit 1
(eval 'assert_not_empty ""')
[[ "$?" == "1" ]] || exit 1
}
function test_assert_dir_exists() {
test_case_title
(eval 'assert_dir_exists "$HOME"')
[[ "$?" == "0" ]] || exit 1
(eval 'assert_dir_exists $HOME/test_non_existing_dir')
[[ "$?" == "1" ]] || exit 1
}
function test_assert_dir_not_exists() {
test_case_title
(eval 'assert_dir_not_exists "$HOME"')
[[ "$?" == "1" ]] || exit 1
(eval 'assert_dir_not_exists $HOME/test_non_existing_dir')
[[ "$?" == "0" ]] || exit 1
}
function test_assert_file_exists() {
test_case_title
local existing_file="$(mktemp)"
(eval 'assert_file_exists "$existing_file"')
[[ "$?" == "0" ]] || exit 1
(eval 'assert_file_exists $HOME/test_non_existing_file')
[[ "$?" == "1" ]] || exit 1
}
function test_assert_file_not_exists() {
test_case_title
local existing_file="$(mktemp)"
(eval 'assert_file_not_exists "$HOME/test_non_existing_file"')
[[ "$?" == "0" ]] || exit 1
(eval 'assert_file_not_exists $existing_file')
[[ "$?" == "1" ]] || exit 1
}
function test_assert_contains() {
test_case_title
(eval 'assert_contains "abc" "a"')
[[ "$?" == "0" ]] || exit 1
(eval 'assert_contains "abc" "b"')
[[ "$?" == "0" ]] || exit 1
(eval 'assert_contains "abc" "c"')
[[ "$?" == "0" ]] || exit 1
(eval 'assert_contains "abc" "d"')
[[ "$?" == "1" ]] || exit 1
}
test_assert_equal
test_assert_empty
test_assert_not_empty
test_assert_dir_exists
test_assert_dir_not_exists
test_assert_file_exists
test_assert_file_not_exists
test_assert_contains