~ubuntu-branches/ubuntu/raring/nagios3/raring

« back to all changes in this revision

Viewing changes to tap/src/tap.c

  • Committer: Package Import Robot
  • Author(s): Alexander Wirt
  • Date: 2012-06-16 09:05:19 UTC
  • mfrom: (8.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20120616090519-1okxgkbe21vumokr
Tags: 3.4.1-1
* [28e077b] Imported Upstream version 3.3.1
* [d5314e0] don't call updatepo in clean target
* [45b3eb9] Don't remove config foo
* [54e3dff] Don't fix permissions in cgi postinst
* [d7be9db] Build-depend on libpng-dev (Closes: #662441)
* [4c47006] Add dutch po translation (Closes: #654855)
* [2b6573b] Refresh 10_p1_pl_shebang.dpatch
* [316fd7a] Update 40_fix_spurious_dollar_signs_added_to_command_lines
* [5ff2780] Refresh 55_strip_logarchivepath.dpatch
* [811d269] Refresh 60_fix_p1.pl_patch_mini_epn.dpatch
* [39a1e9c] Remove now unneeded patch 98_fix_XSS_CVE-2011-2179
* [785a4e8] Remove unneded patch 99_fix_XSS_CVE-2011-1523
* [6ce98ef] Remove unneeded patchs from 00list
* [1d18266] Imported Upstream version 3.4.0
* [05584c8] Refresh patches
* [58098cd] Imported Upstream version 3.4.1
* [3e9e07a] Bump standards version
* [fe991e2] wrap-and-sort
* [1ba78f7] Also create /var/run/nagios in cgi package (Closes: #626854)

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
 * test_comment -- a comment to print afterwards, may be NULL
68
68
 */
69
69
unsigned int
70
 
_gen_result(int ok, const char *func, char *file, unsigned int line, 
71
 
            char *test_name, ...)
72
 
{
 
70
_gen_result(int ok, const char *func, char *file, unsigned int line,
 
71
            char *test_name, ...) {
73
72
        va_list ap;
74
73
        char *local_test_name = NULL;
75
74
        char *c;
95
94
                                if(!isdigit(*c) && !isspace(*c)) {
96
95
                                        name_is_digits = 0;
97
96
                                        break;
 
97
                                        }
98
98
                                }
99
 
                        }
100
99
 
101
100
                        if(name_is_digits) {
102
101
                                diag("    You named your test '%s'.  You shouldn't use numbers for your test names.", local_test_name);
103
102
                                diag("    Very confusing.");
 
103
                                }
104
104
                        }
105
105
                }
106
 
        }
107
106
 
108
107
        if(!ok) {
109
108
                printf("not ");
110
109
                failures++;
111
 
        }
 
110
                }
112
111
 
113
112
        printf("ok %d", test_count);
114
113
 
123
122
                                if(*c == '#')
124
123
                                        fputc('\\', stdout);
125
124
                                fputc((int)*c, stdout);
126
 
                        }
 
125
                                }
127
126
                        funlockfile(stdout);
128
 
                } else {        /* vasprintf() failed, use a fixed message */
 
127
                        }
 
128
                else {  /* vasprintf() failed, use a fixed message */
129
129
                        printf("%s", todo_msg_fixed);
 
130
                        }
130
131
                }
131
 
        }
132
132
 
133
133
        /* If we're in a todo_start() block then flag the test as being
134
134
           TODO.  todo_msg should contain the message to print at this
141
141
                printf(" # TODO %s", todo_msg ? todo_msg : todo_msg_fixed);
142
142
                if(!ok)
143
143
                        failures--;
144
 
        }
 
144
                }
145
145
 
146
146
        printf("\n");
147
147
 
148
148
        if(!ok)
149
 
                diag("    Failed %stest (%s:%s() at line %d)", 
 
149
                diag("    Failed %stest (%s:%s() at line %d)",
150
150
                     todo ? "(TODO) " : "", file, func, line);
151
151
 
152
152
        free(local_test_name);
156
156
        /* We only care (when testing) that ok is positive, but here we
157
157
           specifically only want to return 1 or 0 */
158
158
        return ok ? 1 : 0;
159
 
}
 
159
        }
160
160
 
161
161
/*
162
162
 * Initialise the TAP library.  Will only do so once, however many times it's
163
163
 * called.
164
164
 */
165
165
void
166
 
_tap_init(void)
167
 
{
 
166
_tap_init(void) {
168
167
        static int run_once = 0;
169
168
 
170
169
        LOCK;
173
172
                atexit(_cleanup);
174
173
 
175
174
                /* stdout needs to be unbuffered so that the output appears
176
 
                   in the same place relative to stderr output as it does 
 
175
                   in the same place relative to stderr output as it does
177
176
                   with Test::Harness */
178
177
                setbuf(stdout, 0);
179
178
                run_once = 1;
 
179
                }
 
180
 
 
181
        UNLOCK;
180
182
        }
181
183
 
182
 
        UNLOCK;
183
 
}
184
 
 
185
184
/*
186
185
 * Note that there's no plan.
187
186
 */
188
187
int
189
 
plan_no_plan(void)
190
 
{
 
188
plan_no_plan(void) {
191
189
 
192
190
        LOCK;
193
191
 
198
196
                test_died = 1;
199
197
                UNLOCK;
200
198
                exit(255);
201
 
        }
 
199
                }
202
200
 
203
201
        have_plan = 1;
204
202
        no_plan = 1;
206
204
        UNLOCK;
207
205
 
208
206
        return 0;
209
 
}
 
207
        }
210
208
 
211
209
/*
212
210
 * Note that the plan is to skip all tests
213
211
 */
214
212
int
215
 
plan_skip_all(char *reason)
216
 
{
 
213
plan_skip_all(char *reason) {
217
214
 
218
215
        LOCK;
219
216
 
231
228
        UNLOCK;
232
229
 
233
230
        exit(0);
234
 
}
 
231
        }
235
232
 
236
233
/*
237
234
 * Note the number of tests that will be run.
238
235
 */
239
236
int
240
 
plan_tests(unsigned int tests)
241
 
{
 
237
plan_tests(unsigned int tests) {
242
238
 
243
239
        LOCK;
244
240
 
249
245
                test_died = 1;
250
246
                UNLOCK;
251
247
                exit(255);
252
 
        }
 
248
                }
253
249
 
254
250
        if(tests == 0) {
255
251
                fprintf(stderr, "You said to run 0 tests!  You've got to run something.\n");
256
252
                test_died = 1;
257
253
                UNLOCK;
258
254
                exit(255);
259
 
        }
 
255
                }
260
256
 
261
257
        have_plan = 1;
262
258
 
265
261
        UNLOCK;
266
262
 
267
263
        return 0;
268
 
}
 
264
        }
269
265
 
270
266
unsigned int
271
 
diag(char *fmt, ...)
272
 
{
 
267
diag(char *fmt, ...) {
273
268
        va_list ap;
274
269
 
275
270
        LOCK;
285
280
        UNLOCK;
286
281
 
287
282
        return 0;
288
 
}
 
283
        }
289
284
 
290
285
void
291
 
_expected_tests(unsigned int tests)
292
 
{
 
286
_expected_tests(unsigned int tests) {
293
287
 
294
288
        LOCK;
295
289
 
297
291
        e_tests = tests;
298
292
 
299
293
        UNLOCK;
300
 
}
 
294
        }
301
295
 
302
296
int
303
 
skip(unsigned int n, char *fmt, ...)
304
 
{
 
297
skip(unsigned int n, char *fmt, ...) {
305
298
        va_list ap;
306
299
        char *skip_msg;
307
300
 
313
306
 
314
307
        while(n-- > 0) {
315
308
                test_count++;
316
 
                printf("ok %d # skip %s\n", test_count, 
317
 
                       skip_msg != NULL ? 
 
309
                printf("ok %d # skip %s\n", test_count,
 
310
                       skip_msg != NULL ?
318
311
                       skip_msg : "libtap():malloc() failed");
319
 
        }
 
312
                }
320
313
 
321
314
        free(skip_msg);
322
315
 
323
316
        UNLOCK;
324
317
 
325
318
        return 1;
326
 
}
 
319
        }
327
320
 
328
321
void
329
 
todo_start(char *fmt, ...)
330
 
{
 
322
todo_start(char *fmt, ...) {
331
323
        va_list ap;
332
324
 
333
325
        LOCK;
339
331
        todo = 1;
340
332
 
341
333
        UNLOCK;
342
 
}
 
334
        }
343
335
 
344
336
void
345
 
todo_end(void)
346
 
{
 
337
todo_end(void) {
347
338
 
348
339
        LOCK;
349
340
 
351
342
        free(todo_msg);
352
343
 
353
344
        UNLOCK;
354
 
}
 
345
        }
355
346
 
356
347
int
357
 
exit_status(void)
358
 
{
 
348
exit_status(void) {
359
349
        int r;
360
350
 
361
351
        LOCK;
364
354
        if(no_plan || !have_plan) {
365
355
                UNLOCK;
366
356
                return failures;
367
 
        }
 
357
                }
368
358
 
369
359
        /* Ran too many tests?  Return the number of tests that were run
370
360
           that shouldn't have been */
372
362
                r = test_count - e_tests;
373
363
                UNLOCK;
374
364
                return r;
375
 
        }
 
365
                }
376
366
 
377
 
        /* Return the number of tests that failed + the number of tests 
 
367
        /* Return the number of tests that failed + the number of tests
378
368
           that weren't run */
379
369
        r = failures + e_tests - test_count;
380
370
        UNLOCK;
381
371
 
382
372
        return r;
383
 
}
 
373
        }
384
374
 
385
375
/*
386
376
 * Cleanup at the end of the run, produce any final output that might be
387
377
 * required.
388
378
 */
389
379
void
390
 
_cleanup(void)
391
 
{
 
380
_cleanup(void) {
392
381
 
393
382
        LOCK;
394
383
 
399
388
                diag("Looks like your test died before it could output anything.");
400
389
                UNLOCK;
401
390
                return;
402
 
        }
 
391
                }
403
392
 
404
393
        if(test_died) {
405
394
                diag("Looks like your test died just after %d.", test_count);
406
395
                UNLOCK;
407
396
                return;
408
 
        }
 
397
                }
409
398
 
410
399
 
411
400
        /* No plan provided, but now we know how many tests were run, and can
412
401
           print the header at the end */
413
402
        if(!skip_all && (no_plan || !have_plan)) {
414
403
                printf("1..%d\n", test_count);
415
 
        }
 
404
                }
416
405
 
417
406
        if((have_plan && !no_plan) && e_tests < test_count) {
418
407
                diag("Looks like you planned %d tests but ran %d extra.",
419
408
                     e_tests, test_count - e_tests);
420
409
                UNLOCK;
421
410
                return;
422
 
        }
 
411
                }
423
412
 
424
413
        if((have_plan || !no_plan) && e_tests > test_count) {
425
414
                diag("Looks like you planned %d tests but only ran %d.",
426
415
                     e_tests, test_count);
427
416
                UNLOCK;
428
417
                return;
429
 
        }
 
418
                }
430
419
 
431
420
        if(failures)
432
 
                diag("Looks like you failed %d tests of %d.", 
 
421
                diag("Looks like you failed %d tests of %d.",
433
422
                     failures, test_count);
434
423
 
435
424
        UNLOCK;
436
 
}
 
425
        }