src/test/fail.c
author Tero Marttila <terom@fixme.fi>
Fri, 08 May 2009 02:51:20 +0300
changeset 195 42aedce3e2eb
parent 194 808b1b047620
permissions -rw-r--r--
rework test to implement flags, test_results, test_stats, TEST_WILL_FAIL
#include "fail.h"
#include "test.h"
#include "../str.h"
#include "../log.h"
#include "backtrace.h"

#include <stdarg.h>

void test_fail_va (const char *func, const char *file, int line, int skip, const char *fmt, va_list vargs)
{
    // log it
    log_output_tag(LOG_ERROR, "FAIL", func, fmt, vargs, " @@ %s@%s:%d - backtrace follows:", func, file, line);

    // print out a stack dump, not including this function or the backtrace func
    test_backtrace(skip + 2);
    
    // then jump out
    longjmp(_test_ctx.jmp_fail, TEST_FAIL);
}

void test_fail (const char *func, const char *file, int line, int skip, const char *fmt, ...)
{   
    va_list vargs; 
    
    va_start(vargs, fmt);

    test_fail_va(func, file, line, skip, fmt, vargs);

    va_end(vargs);
}

void test_test_fail (void)
{
    fail_if(1, "testing failure: %s", "xxx");
}