@@ -12,6 +12,7 @@ todo_file=todo.txt
12
12
13
13
input_glob=input.*
14
14
expected_glob=expected.*
15
+ expected_errors_extension=err
15
16
16
17
metafix_output_glob=output-metafix.*
17
18
catmandu_output_glob=output-catmandu.*
@@ -102,6 +103,8 @@ function get_file() {
102
103
reason=" Ambiguous $type files: $* "
103
104
elif [ ! -r " $1 " ]; then
104
105
reason=" No $type file: $1 "
106
+ elif [ " $type " != " output" ] && [ ! -s " $1 " ]; then
107
+ reason=" Empty $type file: $1 "
105
108
else
106
109
current_file=$1
107
110
return 0
@@ -138,6 +141,40 @@ function skip_test() {
138
141
fi
139
142
}
140
143
144
+ function test_passed() {
145
+ if [ -r " $2 " ]; then
146
+ log " $color_test $1 $color_reset : ${color_failed} FAILED$color_reset (Marked as \" to do\" , but passed.)"
147
+
148
+ (( failed++ )) || true
149
+ else
150
+ if parse_boolean " $METAFIX_LOG_PASSED " ; then
151
+ log " $color_test $1 $color_reset : ${color_passed} PASSED$color_reset $3 "
152
+ fi
153
+
154
+ (( passed++ )) || true
155
+ fi
156
+ }
157
+
158
+ function test_failed() {
159
+ if ! skip_test " $1 " " $2 " ; then
160
+ log " $color_test $1 $color_reset : $color_failed $4 $color_reset $3 "
161
+
162
+ if [ $# -ge 13 ]; then
163
+ log " Fix: $9 "
164
+ log " Input: ${10} "
165
+ log " Expected: ${11} "
166
+ log " Output: ${12} "
167
+ log " Diff: ${13} "
168
+
169
+ [ -s " ${13} " ] && $colordiff < " ${13} " || rm -f " ${13} "
170
+ fi
171
+
172
+ command_info " $5 " " $6 " " $7 " " $8 "
173
+
174
+ (( failed++ )) || true
175
+ fi
176
+ }
177
+
141
178
function run_tests() {
142
179
local test matched=1\
143
180
test_directory test_fix test_input test_expected test_todo\
@@ -165,62 +202,51 @@ function run_tests() {
165
202
test_todo=" $test_directory /$todo_file "
166
203
167
204
if [ -z " $disable_todo " ] || ! skip_test " $test " " $test_todo " ; then
205
+ # TODO: catmandu (optional)
206
+
168
207
metafix_command_output=" $test_directory /metafix.out"
169
208
metafix_command_error=" $test_directory /metafix.err"
170
209
171
210
metafix_start_time=$( current_time)
172
211
173
- # TODO: catmandu (optional)
212
+ run_metafix " $test_directory /$metafix_file " > " $metafix_command_output " 2> " $metafix_command_error "
213
+ metafix_exit_status=$?
174
214
175
- if run_metafix " $test_directory /$metafix_file " > " $metafix_command_output " 2> " $metafix_command_error " ; then
176
- metafix_exit_status=$?
215
+ metafix_elapsed_time=$( elapsed_time " $metafix_start_time " )
177
216
217
+ if [ " $metafix_exit_status " -eq 0 ]; then
178
218
if get_file " $test " output " $test_directory " /$metafix_output_glob ; then
179
219
metafix_output=$current_file
180
220
metafix_diff=" $test_directory /metafix.diff"
181
221
182
- metafix_elapsed_time=$( elapsed_time " $metafix_start_time " )
183
-
184
222
if diff -u " $test_expected " " $metafix_output " > " $metafix_diff " ; then
185
- if [ -r " $test_todo " ]; then
186
- log " $color_test$test$color_reset : ${color_failed} FAILED$color_reset (Marked as \" to do\" , but passed.)"
187
-
188
- (( failed++ )) || true
189
- else
190
- if parse_boolean " $METAFIX_LOG_PASSED " ; then
191
- log " $color_test$test$color_reset : ${color_passed} PASSED$color_reset$metafix_elapsed_time "
192
- fi
193
-
194
- (( passed++ )) || true
195
- fi
223
+ test_passed " $test " " $test_todo " " $metafix_elapsed_time "
196
224
197
225
rm -f " $metafix_diff " " $metafix_command_output " " $metafix_command_error "
198
- elif ! skip_test " $test " " $test_todo " ; then
199
- log " $color_test$test$color_reset : ${color_failed} FAILED$color_reset$metafix_elapsed_time "
200
-
201
- log " Fix: $test_fix "
202
- log " Input: $test_input "
203
- log " Expected: $test_expected "
204
- log " Output: $metafix_output "
205
- log " Diff: $metafix_diff "
206
-
207
- [ -s " $metafix_diff " ] && $colordiff < " $metafix_diff " || rm -f " $metafix_diff "
208
-
209
- command_info metafix " $metafix_exit_status " " $metafix_command_output " " $metafix_command_error "
210
-
211
- (( failed++ )) || true
226
+ else
227
+ test_failed " $test " " $test_todo " " $metafix_elapsed_time " FAILED\
228
+ metafix " $metafix_exit_status " " $metafix_command_output " " $metafix_command_error " \
229
+ " $test_fix " " $test_input " " $test_expected " " $metafix_output " " $metafix_diff "
212
230
fi
213
231
else
214
232
command_info metafix " $metafix_exit_status " " $metafix_command_output " " $metafix_command_error "
215
233
fi
216
- elif ! skip_test " $test " " $test_todo " ; then
217
- metafix_exit_status= $?
234
+ elif [ " ${test_expected ##* .} " == " $expected_errors_extension " ] ; then
235
+ get_file " $test " error " $metafix_command_error " || { log ; continue ; }
218
236
219
- log " $color_test$test$color_reset : ${color_error} ERROR$color_reset "
237
+ while read -r pattern; do
238
+ if ! grep -qE " $pattern " " $metafix_command_error " ; then
239
+ test_failed " $test " " $test_todo " " (Pattern not found: $pattern )" FAILED\
240
+ metafix " $metafix_exit_status " " $metafix_command_output " " $metafix_command_error "
220
241
221
- command_info metafix " $metafix_exit_status " " $metafix_command_output " " $metafix_command_error "
242
+ continue 2
243
+ fi
244
+ done < " $test_expected "
222
245
223
- (( failed++ )) || true
246
+ test_passed " $test " " $test_todo " " $metafix_elapsed_time "
247
+ else
248
+ test_failed " $test " " $test_todo " " $metafix_elapsed_time " ERROR\
249
+ metafix " $metafix_exit_status " " $metafix_command_output " " $metafix_command_error "
224
250
fi
225
251
fi
226
252
done
0 commit comments