-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathassert_folders.sh
More file actions
154 lines (118 loc) · 4.65 KB
/
assert_folders.sh
File metadata and controls
154 lines (118 loc) · 4.65 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env bash
function assert_directory_exists() {
bashunit::assert::should_skip && return 0
local expected="$1"
local test_fn
test_fn="$(bashunit::helper::find_test_function_name)"
local label="${2:-$(bashunit::helper::normalize_test_function_name "$test_fn")}"
if [ ! -d "$expected" ]; then
bashunit::assert::mark_failed
bashunit::console_results::print_failed_test "${label}" "${expected}" "to exist but" "do not exist"
return
fi
bashunit::state::add_assertions_passed
}
function assert_directory_not_exists() {
bashunit::assert::should_skip && return 0
local expected="$1"
local test_fn
test_fn="$(bashunit::helper::find_test_function_name)"
local label="${2:-$(bashunit::helper::normalize_test_function_name "$test_fn")}"
if [ -d "$expected" ]; then
bashunit::assert::mark_failed
bashunit::console_results::print_failed_test "${label}" "${expected}" "to not exist but" "the directory exists"
return
fi
bashunit::state::add_assertions_passed
}
function assert_is_directory() {
bashunit::assert::should_skip && return 0
local expected="$1"
local test_fn
test_fn="$(bashunit::helper::find_test_function_name)"
local label="${2:-$(bashunit::helper::normalize_test_function_name "$test_fn")}"
if [ ! -d "$expected" ]; then
bashunit::assert::mark_failed
bashunit::console_results::print_failed_test "${label}" "${expected}" "to be a directory" "but is not a directory"
return
fi
bashunit::state::add_assertions_passed
}
function assert_is_directory_empty() {
bashunit::assert::should_skip && return 0
local expected="$1"
local test_fn
test_fn="$(bashunit::helper::find_test_function_name)"
local label="${2:-$(bashunit::helper::normalize_test_function_name "$test_fn")}"
if [ ! -d "$expected" ] || [ -n "$(ls -A "$expected")" ]; then
bashunit::assert::mark_failed
bashunit::console_results::print_failed_test "${label}" "${expected}" "to be empty" "but is not empty"
return
fi
bashunit::state::add_assertions_passed
}
function assert_is_directory_not_empty() {
bashunit::assert::should_skip && return 0
local expected="$1"
local test_fn
test_fn="$(bashunit::helper::find_test_function_name)"
local label="${2:-$(bashunit::helper::normalize_test_function_name "$test_fn")}"
if [ ! -d "$expected" ] || [ -z "$(ls -A "$expected")" ]; then
bashunit::assert::mark_failed
bashunit::console_results::print_failed_test "${label}" "${expected}" "to not be empty" "but is empty"
return
fi
bashunit::state::add_assertions_passed
}
function assert_is_directory_readable() {
bashunit::assert::should_skip && return 0
local expected="$1"
local test_fn
test_fn="$(bashunit::helper::find_test_function_name)"
local label="${2:-$(bashunit::helper::normalize_test_function_name "$test_fn")}"
if [ ! -d "$expected" ] || [ ! -r "$expected" ] || [ ! -x "$expected" ]; then
bashunit::assert::mark_failed
bashunit::console_results::print_failed_test "${label}" "${expected}" "to be readable" "but is not readable"
return
fi
bashunit::state::add_assertions_passed
}
function assert_is_directory_not_readable() {
bashunit::assert::should_skip && return 0
local expected="$1"
local test_fn
test_fn="$(bashunit::helper::find_test_function_name)"
local label="${2:-$(bashunit::helper::normalize_test_function_name "$test_fn")}"
if [ ! -d "$expected" ] || { [ -r "$expected" ] && [ -x "$expected" ]; }; then
bashunit::assert::mark_failed
bashunit::console_results::print_failed_test "${label}" "${expected}" "to be not readable" "but is readable"
return
fi
bashunit::state::add_assertions_passed
}
function assert_is_directory_writable() {
bashunit::assert::should_skip && return 0
local expected="$1"
local test_fn
test_fn="$(bashunit::helper::find_test_function_name)"
local label="${2:-$(bashunit::helper::normalize_test_function_name "$test_fn")}"
if [ ! -d "$expected" ] || [ ! -w "$expected" ]; then
bashunit::assert::mark_failed
bashunit::console_results::print_failed_test "${label}" "${expected}" "to be writable" "but is not writable"
return
fi
bashunit::state::add_assertions_passed
}
function assert_is_directory_not_writable() {
bashunit::assert::should_skip && return 0
local expected="$1"
local test_fn
test_fn="$(bashunit::helper::find_test_function_name)"
local label="${2:-$(bashunit::helper::normalize_test_function_name "$test_fn")}"
if [ ! -d "$expected" ] || [ -w "$expected" ]; then
bashunit::assert::mark_failed
bashunit::console_results::print_failed_test "${label}" "${expected}" "to be not writable" "but is writable"
return
fi
bashunit::state::add_assertions_passed
}