-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.sh
executable file
·174 lines (150 loc) · 4.53 KB
/
tests.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
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
#!/usr/bin/env bash
source functions.sh
source variables.sh
woche_script_path="./woche.sh"
current_week
file=$current_week
check_test_result() {
if [[ "$output" == *"FAILED"* ]]; then
exit 1
fi
}
delete_file() {
cd "$path_to_files" > /dev/null
rm -f "$current_week.md"
cd - > /dev/null
}
delete_file
# Test with more than 3 arguments
output=$("$woche_script_path" mon "Test task" "Argument" "Extra argument")
if [[ "$output" == *"tips: woche.sh"* ]]; 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" == *"tips: woche.sh"* ]]; 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" == *"tips: woche.sh"* ]]; 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
if [ ! -e "$file.md" ]; then
echo "Error: The file $file.md does not exist."
exit 1
fi
cd - > /dev/null
# 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
if [ -z "$(sed -n "/# $mon/ p" "$file.md")" ]; then
echo "Error: Task has not been added."
exit 1
fi
cd - > /dev/null
# 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
output=$("$woche_script_path" edit 2 "New task ,.!@")
if [[ "$output" == *"Line 2 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
if [ -z "$(sed -n "2 p" "$file.md" | grep "New task ,.!@")" ]; then
echo "Error: Task has not been edited."
exit 1
fi
cd - > /dev/null
# Test show command
output=$("$woche_script_path" show)
if [[ "$output" == *"Week starts on"* ]]; then
echo "Test 'show' command: PASSED"
else
echo "Test 'show' command: FAILED"
fi
check_test_result
# Test delete command
output=$("$woche_script_path" delete 2)
if [[ "$output" == *"Line 2 deleted."* ]]; then
echo "Test 'delete' command: PASSED"
else
echo "Test 'delete' command: FAILED"
fi
check_test_result
delete_file