Example #1
0
File: tap.c Project: vehar/tomlc
int
like_at_loc (int for_match, const char *file, int line, const char *got,
             const char *expected, const char *fmt, ...)
{
    int test;
    regex_t re;
    va_list args;
    int err = regcomp(&re, expected, REG_EXTENDED);
    if (err) {
        char errbuf[256];
        regerror(err, &re, errbuf, sizeof errbuf);
        fprintf(stderr, "Unable to compile regex '%s': %s at %s line %d\n",
                        expected, errbuf, file, line);
        exit(255);
    }
    err = regexec(&re, got, 0, NULL, 0);
    regfree(&re);
    test = for_match ? !err : err;
    va_start(args, fmt);
    vok_at_loc(file, line, test, fmt, args);
    va_end(args);
    if (!test) {
        if (for_match) {
            diag("                   '%s'", got);
            diag("    doesn't match: '%s'", expected);
        }
        else {
            diag("                   '%s'", got);
            diag("          matches: '%s'", expected);
        }
    }
    return test;
}
Example #2
0
File: tap.c Project: vehar/tomlc
int
cmp_ok_at_loc (const char *file, int line, int a, const char *op, int b,
               const char *fmt, ...)
{
    int test = eq(op, "||") ? a || b
             : eq(op, "&&") ? a && b
             : eq(op, "|")  ? a |  b
             : eq(op, "^")  ? a ^  b
             : eq(op, "&")  ? a &  b
             : eq(op, "==") ? a == b
             : eq(op, "!=") ? a != b
             : eq(op, "<")  ? a <  b
             : eq(op, ">")  ? a >  b
             : eq(op, "<=") ? a <= b
             : eq(op, ">=") ? a >= b
             : eq(op, "<<") ? a << b
             : eq(op, ">>") ? a >> b
             : eq(op, "+")  ? a +  b
             : eq(op, "-")  ? a -  b
             : eq(op, "*")  ? a *  b
             : eq(op, "/")  ? a /  b
             : eq(op, "%")  ? a %  b
             : diag("unrecognized operator '%s'", op);
    va_list args;
    va_start(args, fmt);
    vok_at_loc(file, line, test, fmt, args);
    va_end(args);
    if (!test) {
        diag("    %d", a);
        diag("        %s", op);
        diag("    %d", b);
    }
    return test;
}
Example #3
0
File: tap.c Project: vehar/tomlc
int
ok_at_loc (const char *file, int line, int test, const char *fmt, ...) {
    va_list args;
    va_start(args, fmt);
    vok_at_loc(file, line, test, fmt, args);
    va_end(args);
    return test;
}
Example #4
0
File: tap.c Project: vehar/tomlc
int
isnt_at_loc (const char *file, int line, const char *got, const char *expected,
             const char *fmt, ...)
{
    int test = ne(got, expected);
    va_list args;
    va_start(args, fmt);
    vok_at_loc(file, line, test, fmt, args);
    va_end(args);
    if (!test) {
        diag("         got: '%s'", got);
        diag("    expected: anything else");
    }
    return test;
}
Example #5
0
int
cmp_mem_at_loc (const char *file, int line, const void *got,
                const void *expected, size_t n, const char *fmt, ...)
{
    size_t offset;
    int diff = find_mem_diff(got, expected, n, &offset);
    va_list args;
    va_start(args, fmt);
    vok_at_loc(file, line, !diff, fmt, args);
    va_end(args);
    if (diff == 1) {
        diag("    Difference starts at offset %d", offset);
        diag("         got: 0x%02x", ((unsigned char *)got)[offset]);
        diag("    expected: 0x%02x", ((unsigned char *)expected)[offset]);
    }
    else if (diff == 2) {
        diag("         got: %s", got ? "not NULL" : "NULL");
        diag("    expected: %s", expected ? "not NULL" : "NULL");
    }
    return !diff;
}
Example #6
0
File: test.c Project: joydo/librx
int
rx_like_at_loc (int for_match, const char *file, int line, const char *got,
                const char *expected, const char *fmt, ...)
{
    va_list args;
    int test;
    Rx *rx = rx_new(expected);
    if (!rx)
        exit(255);
    test = rx_match(rx, got) ^ !for_match;
    rx_free(rx);
    va_start(args, fmt);
    vok_at_loc(file, line, test, fmt, args);
    va_end(args);
    if (!test) {
        diag("    %13s  '%s'", "", got);
        diag("    %13s: '%s'",
             for_match ? "doesn't match" : "matches", expected);
    }
    return test;
}