@@ -70,8 +70,6 @@ static void test_err_cb(void *data, jv e) {
70
70
e = jv_dump_string (e , JV_PRINT_INVALID );
71
71
if (!strncmp (jv_string_value (e ), "jq: error" , sizeof ("jq: error" ) - 1 ))
72
72
snprintf (err_data -> buf , sizeof (err_data -> buf ), "%s" , jv_string_value (e ));
73
- if (strchr (err_data -> buf , '\n' ))
74
- * (strchr (err_data -> buf , '\n' )) = '\0' ;
75
73
jv_free (e );
76
74
}
77
75
@@ -108,18 +106,7 @@ static void run_jq_tests(jv lib_dirs, int verbose, FILE *testdata, int skip, int
108
106
109
107
if (skip > 0 ) {
110
108
skip -- ;
111
-
112
- // skip past test data
113
- while (fgets (buf , sizeof (buf ), testdata )) {
114
- lineno ++ ;
115
- if (buf [0 ] == '\n' || (buf [0 ] == '\r' && buf [1 ] == '\n' ))
116
- break ;
117
- }
118
-
119
- must_fail = 0 ;
120
- check_msg = 0 ;
121
-
122
- continue ;
109
+ goto next ;
123
110
} else if (skip == 0 ) {
124
111
printf ("Skipped %d tests\n" , tests_to_skip );
125
112
skip = -1 ;
@@ -139,37 +126,40 @@ static void run_jq_tests(jv lib_dirs, int verbose, FILE *testdata, int skip, int
139
126
140
127
if (must_fail ) {
141
128
jq_set_error_cb (jq , NULL , NULL );
142
- if (!fgets (buf , sizeof (buf ), testdata )) { invalid ++ ; break ; }
143
- lineno ++ ;
144
- if (buf [strlen (buf )- 1 ] == '\n' ) buf [strlen (buf )- 1 ] = 0 ;
145
129
if (compiled ) {
146
- printf ("*** Test program compiled that should not have at line %u: %s\n" , lineno , prog );
147
- must_fail = 0 ;
148
- check_msg = 0 ;
149
- invalid ++ ;
150
- continue ;
130
+ printf ("*** Test program compiled successfully, but should fail at line number %u: %s\n" , lineno , prog );
131
+ goto fail ;
132
+ }
133
+ char * err_buf = err_msg .buf ;
134
+ while (fgets (buf , sizeof (buf ), testdata )) {
135
+ lineno ++ ;
136
+ if (skipline (buf )) break ;
137
+ if (check_msg ) {
138
+ if (buf [strlen (buf )- 1 ] == '\n' ) buf [strlen (buf )- 1 ] = '\0' ;
139
+ if (strncmp (buf , err_buf , strlen (buf )) != 0 ) {
140
+ if (strchr (err_buf , '\n' )) * strchr (err_buf , '\n' ) = '\0' ;
141
+ printf ("*** Erroneous program failed with '%s', but expected '%s' at line number %u: %s\n" , err_buf , buf , lineno , prog );
142
+ goto fail ;
143
+ }
144
+ err_buf += strlen (buf );
145
+ if (* err_buf == '\n' ) err_buf ++ ;
146
+ }
151
147
}
152
- if (check_msg && strcmp (buf , err_msg .buf ) != 0 ) {
153
- printf ("*** Erroneous test program failed with wrong message (%s) at line %u: %s\n" , err_msg .buf , lineno , prog );
148
+ if (check_msg && * err_buf != '\0' ) {
149
+ if (strchr (err_buf , '\n' )) * strchr (err_buf , '\n' ) = '\0' ;
150
+ printf ("*** Erroneous program failed with extra message '%s' at line %u: %s\n" , err_buf , lineno , prog );
154
151
invalid ++ ;
155
- } else {
156
- passed ++ ;
152
+ pass = 0 ;
157
153
}
158
154
must_fail = 0 ;
159
155
check_msg = 0 ;
156
+ passed += pass ;
160
157
continue ;
161
158
}
162
159
163
160
if (!compiled ) {
164
161
printf ("*** Test program failed to compile at line %u: %s\n" , lineno , prog );
165
- invalid ++ ;
166
- // skip past test data
167
- while (fgets (buf , sizeof (buf ), testdata )) {
168
- lineno ++ ;
169
- if (buf [0 ] == '\n' || (buf [0 ] == '\r' && buf [1 ] == '\n' ))
170
- break ;
171
- }
172
- continue ;
162
+ goto fail ;
173
163
}
174
164
if (verbose ) {
175
165
printf ("Disassembly:\n" );
@@ -181,8 +171,7 @@ static void run_jq_tests(jv lib_dirs, int verbose, FILE *testdata, int skip, int
181
171
jv input = jv_parse (buf );
182
172
if (!jv_is_valid (input )) {
183
173
printf ("*** Input is invalid on line %u: %s\n" , lineno , buf );
184
- invalid ++ ;
185
- continue ;
174
+ goto fail ;
186
175
}
187
176
jq_start (jq , input , verbose ? JQ_DEBUG_TRACE : 0 );
188
177
@@ -192,8 +181,7 @@ static void run_jq_tests(jv lib_dirs, int verbose, FILE *testdata, int skip, int
192
181
jv expected = jv_parse (buf );
193
182
if (!jv_is_valid (expected )) {
194
183
printf ("*** Expected result is invalid on line %u: %s\n" , lineno , buf );
195
- invalid ++ ;
196
- continue ;
184
+ goto fail ;
197
185
}
198
186
jv actual = jq_next (jq );
199
187
if (!jv_is_valid (actual )) {
@@ -226,12 +214,25 @@ static void run_jq_tests(jv lib_dirs, int verbose, FILE *testdata, int skip, int
226
214
printf ("*** Superfluous result: " );
227
215
jv_dump (extra , 0 );
228
216
printf (" for test at line number %u, %s\n" , lineno , prog );
217
+ invalid ++ ;
229
218
pass = 0 ;
230
219
} else {
231
220
jv_free (extra );
232
221
}
233
222
}
234
- passed += pass ;
223
+ passed += pass ;
224
+ continue ;
225
+
226
+ fail :
227
+ invalid ++ ;
228
+
229
+ next :
230
+ while (fgets (buf , sizeof (buf ), testdata )) {
231
+ lineno ++ ;
232
+ if (skipline (buf )) break ;
233
+ }
234
+ must_fail = 0 ;
235
+ check_msg = 0 ;
235
236
}
236
237
jq_teardown (& jq );
237
238
0 commit comments