-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.sh
More file actions
executable file
·336 lines (290 loc) · 10.1 KB
/
tests.sh
File metadata and controls
executable file
·336 lines (290 loc) · 10.1 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#!/usr/bin/env bash
source functions.sh
source variables.sh
woche_script_path="./woche.sh"
# Store original path_to_files in variables.sh
original_path_to_files="$path_to_files"
# Ensure path_to_files is set to the test directory in variables.sh
sed -i 's|^path_to_files=.*|path_to_files="/tmp/"|' variables.sh
source variables.sh
current_week
file=$current_week
check_test_result() {
if [[ "$output" == *"FAILED"* ]]; then
exit 1
fi
}
delete_file() {
cd "$path_to_files" > /dev/null || exit
rm -f "$current_week.md"
cd - > /dev/null || exit
}
delete_file
# Test with more than 3 arguments
output=$("$woche_script_path" mon "Test task" "Argument" "Extra argument")
if [[ "$output" == *"Woche - Weekly Task Manager"* ]]; then
echo "Test 'more than 3 arguments' command: PASSED"
else
echo "Test 'more than 3 arguments' command: FAILED"
fi
check_test_result
# Test if the file do not exists - show command
output=$("$woche_script_path" show)
if [[ "$output" == *"Error: The file"* ]]; then
echo "Test if the file do not exists - show command: PASSED"
else
echo "Test if the file do not exists - show command: FAILED"
fi
check_test_result
# Test if the file do not exists - delete command
output=$("$woche_script_path" delete 2)
if [[ "$output" == *"Error: The file"* ]]; then
echo "Test if the file do not exists - delete command: PASSED"
else
echo "Test if the file do not exists- delete command: FAILED"
fi
check_test_result
# Test if the file do not exists - edit command
output=$("$woche_script_path" edit 2 "New task")
if [[ "$output" == *"Error: The file"* ]]; then
echo "Test if the file do not exists - edit command: PASSED"
else
echo "Test if the file do not exists - edit command: FAILED"
fi
check_test_result
# Test invalid command
output=$("$woche_script_path" invalid)
if [[ "$output" == *"Woche - Weekly Task Manager"* ]]; then
echo "Test invalid command: PASSED"
else
echo "Test invalid command: FAILED"
fi
check_test_result
# Test the 'help' command
output=$("$woche_script_path" help)
if [[ "$output" == *"Woche - Weekly Task Manager"* ]]; then
echo "Test 'help' command: PASSED"
else
echo "Test 'help' command: FAILED"
fi
check_test_result
# Test the 'create' command
output=$("$woche_script_path" create)
if [[ "$output" == *"The file"*"has been created."* ]]; then
echo "Test 'create' command: PASSED"
else
echo "Test 'create' command: FAILED"
fi
check_test_result
# Test the 'create' command when the file already exists
output=$("$woche_script_path" create)
if [[ "$output" == *"The file"*"already exists."* ]]; then
echo "Test 'create' command when the file already exists: PASSED"
else
echo "Test 'create' command when the file already exists: FAILED"
fi
check_test_result
## Check if the file is created on last test
cd "$path_to_files" > /dev/null || exit
if [ ! -e "$file.md" ]; then
echo "Error: The file $file.md does not exist."
exit 1
fi
cd - > /dev/null || exit
# Check if the # Monday was added to the file
cd "$path_to_files" > /dev/null || exit
if [ -z "$(sed -n "/# $mon/ p" "$file.md")" ]; then
echo "Error: The day of the week is not written in the file."
exit 1
fi
cd - > /dev/null || exit
# Test the last command
cd "$path_to_files" > /dev/null || exit
last_week=$(date -d "$current_week - 7 days" "+%y%m%d")
cp "$file.md" "$last_week.md"
cd - > /dev/null || exit
output=$("$woche_script_path" show last)
if [[ "$output" == *"Week starts on"* ]]; then
echo "Test 'last week' command: PASSED"
else
echo "Test 'last week' command: FAILED"
fi
check_test_result
# Test the all command
output=$("$woche_script_path" all)
if [[ "$output" == "All markdown files in $path_to_files:"* ]]; then
echo "Test 'all' command: PASSED"
else
echo "Test 'all' command: FAILED"
fi
check_test_result
# Test add task to a day command
output=$("$woche_script_path" mon "Test task")
if [[ "$output" == *"Task 'Test task' added to"* ]]; then
echo "Test 'add task to a day' command: PASSED"
else
echo "Test 'add task to a day' command: FAILED"
fi
check_test_result
## Check if the task is added on last test
cd "$path_to_files" > /dev/null || exit
if [ -z "$(sed -n "/# $mon/ p" "$file.md")" ]; then
echo "Error: Task has not been added."
exit 1
fi
cd - > /dev/null || exit
# Test add task with punctituation to a day command
output=$("$woche_script_path" mon "Test task with punctuation: ;,!@#$%^&*()_+")
if [[ "$output" == *"Task 'Test task with punctuation: ;,!@#$%^&*()_+' added to"* ]]; then
echo "Test 'add task to a day' command: PASSED"
else
echo "Test 'add task to a day' command: FAILED"
fi
check_test_result
# Test edit command with punctituation
line_to_edit=$(grep -n "Test task with punctuation" "$path_to_files/$file.md" | cut -d: -f1)
output=$("$woche_script_path" edit "$line_to_edit" "New task ,.!@")
if [[ "$output" == *"Line $line_to_edit edited."* ]]; then
echo "Test 'edit' command: PASSED"
else
echo "Test 'edit' command: FAILED"
fi
## Check if the task is edited on last test
cd "$path_to_files" > /dev/null || exit
if ! sed -n "${line_to_edit}p" "$file.md" | grep -q "New task ,.!@"; then
echo "Error: Task has not been edited."
exit 1
fi
cd - > /dev/null || exit
# Test show command
output=$("$woche_script_path" create)
output=$("$woche_script_path" mon "Task one")
output=$("$woche_script_path" mon "Task two")
output=$("$woche_script_path" tue "Task three")
line_one=$(grep -n "Task one" "$path_to_files/$file.md" | cut -d: -f1)
line_two=$(grep -n "Task two" "$path_to_files/$file.md" | cut -d: -f1)
line_three=$(grep -n "Task three" "$path_to_files/$file.md" | cut -d: -f1)
output=$("$woche_script_path" show)
if [[ "$output" == *"Week starts on"* ]] && \
[[ "$output" == *"Task one"* ]] && \
[[ "$output" == *"Task two"* ]] && \
[[ "$output" == *"Task three"* ]]; then
echo "Test 'show' command: PASSED"
else
echo "Test 'show' command: FAILED"
fi
check_test_result
# Test 'today' command
output=$("$woche_script_path" today "Test task")
if [[ "$output" == *"Task 'Test task' added to"* ]]; then
echo "Test 'today' command: PASSED"
else
echo "Test 'today' command: FAILED"
fi
check_test_result
# Test 'search' command
output=$("$woche_script_path" create)
output=$("$woche_script_path" mon "Searchable task")
output=$("$woche_script_path" search "Searchable task")
if [[ "$output" == *"Searchable task"* ]]; then
echo "Test 'search' command: PASSED"
else
echo "Test 'search' command: FAILED"
fi
check_test_result
# Test delete command with 'y' confirmation
output=$("$woche_script_path" create)
output=$("$woche_script_path" mon "Task to be deleted")
line_to_delete=$(grep -n "Task to be deleted" "$path_to_files/$file.md" | cut -d: -f1)
output=$(echo "y" | "$woche_script_path" delete "$line_to_delete")
if [[ "$output" == *"Line $line_to_delete deleted."* ]]; then
echo "Test 'delete' command with 'y' confirmation: PASSED"
else
echo "Test 'delete' command with 'y' confirmation: FAILED"
fi
check_test_result
## Check if the task is deleted on last test
cd "$path_to_files" > /dev/null || exit
if grep -q "Task to be deleted" "$file.md"; then
echo "Error: Task has not been deleted."
exit 1
fi
cd - > /dev/null || exit
# Test delete command with 'n' confirmation
output=$("$woche_script_path" create)
output=$("$woche_script_path" mon "Task not to be deleted")
line_to_delete=$(grep -n "Task not to be deleted" "$path_to_files/$file.md" | cut -d: -f1)
output=$(echo "n" | "$woche_script_path" delete "$line_to_delete")
if [[ "$output" == *"Deletion cancelled."* ]]; then
echo "Test 'delete' command with 'n' confirmation: PASSED"
else
echo "Test 'delete' command with 'n' confirmation: FAILED"
fi
check_test_result
## Check if the task is not deleted on last test
cd "$path_to_files" > /dev/null || exit
if ! grep -q "Task not to be deleted" "$file.md"; then
echo "Error: Task has been deleted when it shouldn't have been."
exit 1
fi
cd - > /dev/null || exit
# Test 'done' command
output=$("$woche_script_path" create)
output=$("$woche_script_path" mon "Task to be marked as done")
line_to_mark_done=$(grep -n "Task to be marked as done" "$path_to_files/$file.md" | cut -d: -f1)
output=$("$woche_script_path" done "$line_to_mark_done")
if [[ "$output" == *"Task on line $line_to_mark_done marked as done."* ]]; then
echo "Test 'done' command: PASSED"
else
echo "Test 'done' command: FAILED"
fi
check_test_result
## Check if the task is marked as done on last test
cd "$path_to_files" > /dev/null || exit
if ! sed -n "${line_to_mark_done}p" "$file.md" | awk '/^- \[x\] Task to be marked as done/'; then
echo "Error: Task has not been marked as done."
exit 1
fi
cd - > /dev/null || exit
# Test config language command
output=$("$woche_script_path" config language en)
if [[ "$output" == *"Language set to: en"* ]]; then
echo "Test 'config language' command: PASSED"
else
echo "Test 'config language' command: FAILED"
fi
check_test_result
# Check if config file was created
if [ -f "$HOME/.woche/config" ]; then
echo "Test config file creation: PASSED"
else
echo "Test config file creation: FAILED"
fi
check_test_result
# Test automatic language detection
# Create file in English
output=$("$woche_script_path" create)
output=$("$woche_script_path" mon "English task")
# Switch to German and verify show still works
output=$("$woche_script_path" config language de)
output=$("$woche_script_path" show)
if [[ "$output" == *"English task"* ]]; then
echo "Test automatic language detection: PASSED"
else
echo "Test automatic language detection: FAILED"
fi
check_test_result
# Test error when using wrong language commands
output=$("$woche_script_path" mont "German task" 2>&1)
if [[ "$output" == *"Error: This file uses English day names"* ]]; then
echo "Test language mismatch detection: PASSED"
else
echo "Test language mismatch detection: FAILED"
fi
check_test_result
# Switch back to English for cleanup
output=$("$woche_script_path" config language en)
delete_file
# Revert path_to_files to its original value in variables.sh
sed -i "s|^path_to_files=.*|path_to_files=""$original_path_to_files""|" variables.sh
source variables.sh