Back to index

nagios-plugins  1.4.16
Defines | Functions
tap.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define ok(e,...)
#define ok1(e)
#define pass(...)   ok(1, __VA_ARGS__);
#define fail(...)   ok(0, __VA_ARGS__);
#define skip_start(test, n,...)
#define skip_end   } while(0);

Functions

unsigned int _gen_result (int, const char *, char *, unsigned int, char *,...)
int plan_no_plan (void)
int plan_skip_all (char *)
int plan_tests (unsigned int)
unsigned int diag (char *,...)
int skip (unsigned int, char *,...)
void todo_start (char *,...)
void todo_end (void)
int exit_status (void)

Define Documentation

#define fail (   ...)    ok(0, __VA_ARGS__);

Definition at line 66 of file tap.h.

#define ok (   e,
  ... 
)
Value:
((e) ?                                    \
                   _gen_result(1, __func__, __FILE__, __LINE__,       \
                             __VA_ARGS__) :                           \
                   _gen_result(0, __func__, __FILE__, __LINE__,       \
                             __VA_ARGS__))

Definition at line 55 of file tap.h.

#define ok1 (   e)
Value:
((e) ?                                           \
               _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) : \
               _gen_result(0, __func__, __FILE__, __LINE__, "%s", #e))

Definition at line 61 of file tap.h.

#define pass (   ...)    ok(1, __VA_ARGS__);

Definition at line 65 of file tap.h.

#define skip_end   } while(0);

Definition at line 76 of file tap.h.

#define skip_start (   test,
  n,
  ... 
)
Value:
do {                                      \
              if((test)) {                       \
                     skip(n,  __VA_ARGS__);             \
                     continue;                   \
              }

Definition at line 68 of file tap.h.


Function Documentation

unsigned int _gen_result ( int  ,
const char *  ,
char *  ,
unsigned  int,
char *  ,
  ... 
)

Definition at line 69 of file tap.c.

{
       va_list ap;
       char *local_test_name = NULL;
       char *c;
       int name_is_digits;

       LOCK;

       test_count++;

       /* Start by taking the test name and performing any printf()
          expansions on it */
       if(test_name != NULL) {
              va_start(ap, test_name);
              vasprintf(&local_test_name, test_name, ap);
              va_end(ap);

              /* Make sure the test name contains more than digits
                 and spaces.  Emit an error message and exit if it
                 does */
              if(local_test_name) {
                     name_is_digits = 1;
                     for(c = local_test_name; *c != '\0'; c++) {
                            if(!isdigit(*c) && !isspace(*c)) {
                                   name_is_digits = 0;
                                   break;
                            }
                     }

                     if(name_is_digits) {
                            diag("    You named your test '%s'.  You shouldn't use numbers for your test names.", local_test_name);
                            diag("    Very confusing.");
                     }
              }
       }

       if(!ok) {
              printf("not ");
              failures++;
       }

       printf("ok %d", test_count);

       if(test_name != NULL) {
              printf(" - ");

              /* Print the test name, escaping any '#' characters it
                 might contain */
              if(local_test_name != NULL) {
                     flockfile(stdout);
                     for(c = local_test_name; *c != '\0'; c++) {
                            if(*c == '#')
                                   fputc('\\', stdout);
                            fputc((int)*c, stdout);
                     }
                     funlockfile(stdout);
              } else {      /* vasprintf() failed, use a fixed message */
                     printf("%s", todo_msg_fixed);
              }
       }

       /* If we're in a todo_start() block then flag the test as being
          TODO.  todo_msg should contain the message to print at this
          point.  If it's NULL then asprintf() failed, and we should
          use the fixed message.

          This is not counted as a failure, so decrement the counter if
          the test failed. */
       if(todo) {
              printf(" # TODO %s", todo_msg ? todo_msg : todo_msg_fixed);
              if(!ok)
                     failures--;
       }

       printf("\n");

       if(!ok)
              diag("    Failed %stest (%s:%s() at line %d)", 
                   todo ? "(TODO) " : "", file, func, line);

       free(local_test_name);

       UNLOCK;

       /* We only care (when testing) that ok is positive, but here we
          specifically only want to return 1 or 0 */
       return ok ? 1 : 0;
}

Here is the call graph for this function:

unsigned int diag ( char *  ,
  ... 
)

Definition at line 270 of file tap.c.

{
       va_list ap;

       LOCK;

       fputs("# ", stderr);

       va_start(ap, fmt);
       vfprintf(stderr, fmt, ap);
       va_end(ap);

       fputs("\n", stderr);

       UNLOCK;

       return 0;
}

Here is the caller graph for this function:

int exit_status ( void  )

Definition at line 356 of file tap.c.

{
       int r;

       LOCK;

       /* If there's no plan, just return the number of failures */
       if(no_plan || !have_plan) {
              UNLOCK;
              return failures;
       }

       /* Ran too many tests?  Return the number of tests that were run
          that shouldn't have been */
       if(e_tests < test_count) {
              r = test_count - e_tests;
              UNLOCK;
              return r;
       }

       /* Return the number of tests that failed + the number of tests 
          that weren't run */
       r = failures + e_tests - test_count;
       UNLOCK;

       return r;
}

Here is the caller graph for this function:

int plan_no_plan ( void  )

Definition at line 188 of file tap.c.

{

       LOCK;

       _tap_init();

       if(have_plan != 0) {
              fprintf(stderr, "You tried to plan twice!\n");
              test_died = 1;
              UNLOCK;
              exit(255);
       }

       have_plan = 1;
       no_plan = 1;

       UNLOCK;

       return 0;
}

Here is the call graph for this function:

int plan_skip_all ( char *  )

Definition at line 214 of file tap.c.

{

       LOCK;

       _tap_init();

       skip_all = 1;

       printf("1..0");

       if(reason != NULL)
              printf(" # Skip %s", reason);

       printf("\n");

       UNLOCK;

       exit(0);
}

Here is the call graph for this function:

int plan_tests ( unsigned  int)

Definition at line 239 of file tap.c.

{

       LOCK;

       _tap_init();

       if(have_plan != 0) {
              fprintf(stderr, "You tried to plan twice!\n");
              test_died = 1;
              UNLOCK;
              exit(255);
       }

       if(tests == 0) {
              fprintf(stderr, "You said to run 0 tests!  You've got to run something.\n");
              test_died = 1;
              UNLOCK;
              exit(255);
       }

       have_plan = 1;

       _expected_tests(tests);

       UNLOCK;

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int skip ( unsigned  int,
char *  ,
  ... 
)

Definition at line 302 of file tap.c.

{
       va_list ap;
       char *skip_msg;

       LOCK;

       va_start(ap, fmt);
       asprintf(&skip_msg, fmt, ap);
       va_end(ap);

       while(n-- > 0) {
              test_count++;
              printf("ok %d # skip %s\n", test_count, 
                     skip_msg != NULL ? 
                     skip_msg : "libtap():malloc() failed");
       }

       free(skip_msg);

       UNLOCK;

       return 1;
}

Here is the call graph for this function:

void todo_end ( void  )

Definition at line 344 of file tap.c.

{

       LOCK;

       todo = 0;
       free(todo_msg);

       UNLOCK;
}
void todo_start ( char *  ,
  ... 
)

Definition at line 328 of file tap.c.

{
       va_list ap;

       LOCK;

       va_start(ap, fmt);
       vasprintf(&todo_msg, fmt, ap);
       va_end(ap);

       todo = 1;

       UNLOCK;
}

Here is the call graph for this function: