repo
string | commit
string | message
string | diff
string |
---|---|---|---|
zorgnax/libtap
|
ac35029ea81c7daf746ac4cf1a9d985a799d75d8
|
Move includes and define to near the top
|
diff --git a/tap.c b/tap.c
index 2a7ba57..9ea8bb1 100644
--- a/tap.c
+++ b/tap.c
@@ -1,364 +1,366 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the LGPL
*/
#define _DEFAULT_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <sys/types.h>
#include <sys/mman.h>
#include "tap.h"
+#ifndef _WIN32
+#include <sys/mman.h>
+#include <sys/param.h>
+#include <regex.h>
+
+#ifndef MAP_ANONYMOUS
+#ifdef MAP_ANON
+#define MAP_ANONYMOUS MAP_ANON
+#else
+#error "System does not support mapping anonymous pages"
+#endif
+#endif
+#endif
+
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
if (!str) {
perror("malloc error");
exit(1);
}
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
tap_plan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
diag("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
if (!test) {
printf("not ");
}
printf("ok %d", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
printf("# Failed ");
if (todo_mesg)
printf("(TODO) ");
printf("test ");
if (*name)
printf("'%s'\n# ", name);
printf("at %s line %d.\n", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static int
find_mem_diff (const char *a, const char *b, size_t n, size_t *offset) {
size_t i;
if (a == b)
return 0;
if (!a || !b)
return 2;
for (i = 0; i < n; i++) {
if (a[i] != b[i]) {
*offset = i;
return 1;
}
}
return 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", ((const unsigned char *)got)[offset]);
diag(" expected: 0x%02x", ((const unsigned char *)expected)[offset]);
}
else if (diff == 2) {
diag(" got: %s", got ? "not NULL" : "NULL");
diag(" expected: %s", expected ? "not NULL" : "NULL");
}
return !diff;
}
int
diag (const char *fmt, ...) {
va_list args;
char *mesg, *line;
int i;
va_start(args, fmt);
if (!fmt) {
va_end(args);
return 0;
}
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
printf("# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 2;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
retval = 1;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
(void) ignore;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
tap_skip (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
diag("skip %s\n", why);
}
free(why);
}
void
tap_todo (int ignore, const char *fmt, ...) {
va_list args;
(void) ignore;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
tap_end_todo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
-#include <sys/mman.h>
-#include <sys/param.h>
-#include <regex.h>
-
-#ifndef MAP_ANONYMOUS
-#ifdef MAP_ANON
-#define MAP_ANONYMOUS MAP_ANON
-#else
-#error "System does not support mapping anonymous pages"
-#endif
-#endif
-
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros. */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
|
zorgnax/libtap
|
38ccd86aa085657cf799fe00447ade4c04ea93d2
|
fix dropped const qualifier
|
diff --git a/tap.c b/tap.c
index 788970a..e470838 100644
--- a/tap.c
+++ b/tap.c
@@ -1,362 +1,362 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the LGPL
*/
#define _DEFAULT_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
if (!str) {
perror("malloc error");
exit(1);
}
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
tap_plan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
diag("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
if (!test) {
printf("not ");
}
printf("ok %d", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
printf("# Failed ");
if (todo_mesg)
printf("(TODO) ");
printf("test ");
if (*name)
printf("'%s'\n# ", name);
printf("at %s line %d.\n", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static int
find_mem_diff (const char *a, const char *b, size_t n, size_t *offset) {
size_t i;
if (a == b)
return 0;
if (!a || !b)
return 2;
for (i = 0; i < n; i++) {
if (a[i] != b[i]) {
*offset = i;
return 1;
}
}
return 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]);
+ diag(" got: 0x%02x", ((const unsigned char *)got)[offset]);
+ diag(" expected: 0x%02x", ((const unsigned char *)expected)[offset]);
}
else if (diff == 2) {
diag(" got: %s", got ? "not NULL" : "NULL");
diag(" expected: %s", expected ? "not NULL" : "NULL");
}
return !diff;
}
int
diag (const char *fmt, ...) {
va_list args;
char *mesg, *line;
int i;
va_start(args, fmt);
if (!fmt) {
va_end(args);
return 0;
}
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
printf("# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 2;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
retval = 1;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
(void) ignore;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
tap_skip (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
diag("skip %s\n", why);
}
free(why);
}
void
tap_todo (int ignore, const char *fmt, ...) {
va_list args;
(void) ignore;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
tap_end_todo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
#ifndef MAP_ANONYMOUS
#ifdef MAP_ANON
#define MAP_ANONYMOUS MAP_ANON
#else
#error "System does not support mapping anonymous pages"
#endif
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros. */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
|
zorgnax/libtap
|
cb611c1f054bdce02eefc6e038558427018edb88
|
Forcibly disable optimization on tests
|
diff --git a/Makefile b/Makefile
index c00bef1..f020c28 100644
--- a/Makefile
+++ b/Makefile
@@ -1,72 +1,73 @@
CC ?= gcc
CFLAGS += -Wall -I. -fPIC
PREFIX ?= $(DESTDIR)/usr/local
TESTS = $(patsubst %.c, %, $(wildcard t/*.c))
ifdef ANSI
# -D_BSD_SOURCE for MAP_ANONYMOUS
CFLAGS += -ansi -D_BSD_SOURCE
LDLIBS += -lbsd-compat
endif
%:
$(CC) $(LDFLAGS) $(TARGET_ARCH) $(filter %.o %.a %.so, $^) $(LDLIBS) -o $@
%.o:
$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $(filter %.c, $^) $(LDLIBS) -o $@
%.a:
$(AR) rcs $@ $(filter %.o, $^)
%.so:
$(CC) -shared $(LDFLAGS) $(TARGET_ARCH) $(filter %.o, $^) $(LDLIBS) -o $@
all: libtap.a libtap.so tap.pc tests
tap.pc:
@echo generating tap.pc
@echo 'prefix='$(PREFIX) > tap.pc
@echo 'exec_prefix=$${prefix}' >> tap.pc
@echo 'libdir=$${prefix}/lib' >> tap.pc
@echo 'includedir=$${prefix}/include' >> tap.pc
@echo '' >> tap.pc
@echo 'Name: libtap' >> tap.pc
@echo 'Description: Write tests in C' >> tap.pc
@echo 'Version: 0.1.0' >> tap.pc
@echo 'URL: https://github.com/zorgnax/libtap' >> tap.pc
@echo 'Libs: -L$${libdir} -ltap' >> tap.pc
@echo 'Cflags: -I$${includedir}' >> tap.pc
libtap.a: tap.o
libtap.so: tap.o
tap.o: tap.c tap.h
tests: $(TESTS)
$(TESTS): %: %.o libtap.a
$(patsubst %, %.o, $(TESTS)): %.o: %.c tap.h
+ $(CC) $(CFLAGS) -O0 $(CPPFLAGS) $(TARGET_ARCH) -c $(filter %.c, $^) $(LDLIBS) -o $@
clean:
rm -rf *.o t/*.o tap.pc libtap.a libtap.so $(TESTS)
install: libtap.a tap.h libtap.so tap.pc
mkdir -p $(PREFIX)/lib $(PREFIX)/include $(PREFIX)/lib/pkgconfig
install -c libtap.a $(PREFIX)/lib
install -c libtap.so $(PREFIX)/lib
install -c tap.pc $(PREFIX)/lib/pkgconfig
install -c tap.h $(PREFIX)/include
uninstall:
rm $(PREFIX)/lib/libtap.a $(PREFIX)/lib/libtap.so $(PREFIX)/include/tap.h
dist:
rm libtap.zip
zip -r libtap *
check test: all
./t/test
.PHONY: all clean install uninstall dist check test tests
|
zorgnax/libtap
|
a9eb032378085bed04f65fd01bb3c45fe6aa18ac
|
Include additional headers
|
diff --git a/tap.c b/tap.c
index 788970a..eea43dc 100644
--- a/tap.c
+++ b/tap.c
@@ -1,362 +1,364 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the LGPL
*/
#define _DEFAULT_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
+#include <sys/types.h>
+#include <sys/mman.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
if (!str) {
perror("malloc error");
exit(1);
}
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
tap_plan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
diag("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
if (!test) {
printf("not ");
}
printf("ok %d", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
printf("# Failed ");
if (todo_mesg)
printf("(TODO) ");
printf("test ");
if (*name)
printf("'%s'\n# ", name);
printf("at %s line %d.\n", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static int
find_mem_diff (const char *a, const char *b, size_t n, size_t *offset) {
size_t i;
if (a == b)
return 0;
if (!a || !b)
return 2;
for (i = 0; i < n; i++) {
if (a[i] != b[i]) {
*offset = i;
return 1;
}
}
return 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;
}
int
diag (const char *fmt, ...) {
va_list args;
char *mesg, *line;
int i;
va_start(args, fmt);
if (!fmt) {
va_end(args);
return 0;
}
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
printf("# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 2;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
retval = 1;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
(void) ignore;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
tap_skip (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
diag("skip %s\n", why);
}
free(why);
}
void
tap_todo (int ignore, const char *fmt, ...) {
va_list args;
(void) ignore;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
tap_end_todo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
#ifndef MAP_ANONYMOUS
#ifdef MAP_ANON
#define MAP_ANONYMOUS MAP_ANON
#else
#error "System does not support mapping anonymous pages"
#endif
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros. */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
|
zorgnax/libtap
|
72bbe878d38856b0f68dd6b261f3f77be5f8e2e2
|
Make division by zero test fail
|
diff --git a/t/diesok.c b/t/diesok.c
index e5471bf..4f531e8 100644
--- a/t/diesok.c
+++ b/t/diesok.c
@@ -1,14 +1,14 @@
#include "tap.h"
int main () {
plan(5);
ok(1, "sanity");
- dies_ok({int x = 0; x = x/x;}, "can't divide by zero");
+ dies_ok({int x = 0; x = 1/x;}, "can't divide by zero");
lives_ok({int x = 3; x = x/7;}, "this is a perfectly fine statement");
dies_ok({abort();}, "abort kills the program");
dies_ok(
{printf("stdout\n"); fprintf(stderr, "stderr\n"); abort();},
"supress output");
done_testing();
}
|
zorgnax/libtap
|
14e6708db5215a657e615171682a1741023c9c0c
|
Add spacing
|
diff --git a/tap.c b/tap.c
index e7b1cef..788970a 100644
--- a/tap.c
+++ b/tap.c
@@ -1,362 +1,362 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the LGPL
*/
#define _DEFAULT_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
if (!str) {
perror("malloc error");
exit(1);
}
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
tap_plan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
diag("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
if (!test) {
printf("not ");
}
printf("ok %d", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
printf("# Failed ");
if (todo_mesg)
printf("(TODO) ");
printf("test ");
if (*name)
printf("'%s'\n# ", name);
printf("at %s line %d.\n", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static int
find_mem_diff (const char *a, const char *b, size_t n, size_t *offset) {
size_t i;
if (a == b)
return 0;
if (!a || !b)
return 2;
for (i = 0; i < n; i++) {
if (a[i] != b[i]) {
*offset = i;
return 1;
}
}
return 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;
}
int
diag (const char *fmt, ...) {
va_list args;
char *mesg, *line;
int i;
va_start(args, fmt);
if (!fmt) {
va_end(args);
return 0;
}
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
printf("# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 2;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
retval = 1;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
- (void)ignore;
+ (void) ignore;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
tap_skip (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
diag("skip %s\n", why);
}
free(why);
}
void
tap_todo (int ignore, const char *fmt, ...) {
va_list args;
- (void)ignore;
+ (void) ignore;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
tap_end_todo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
#ifndef MAP_ANONYMOUS
#ifdef MAP_ANON
#define MAP_ANONYMOUS MAP_ANON
#else
#error "System does not support mapping anonymous pages"
#endif
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros. */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
|
zorgnax/libtap
|
72f3c06fa5f924767be49809446f8b645d14bdb7
|
Fixing a bug which prevents builds for Windows targets.
|
diff --git a/tap.h b/tap.h
index d1f9af3..e366a6a 100644
--- a/tap.h
+++ b/tap.h
@@ -1,115 +1,115 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the LGPL
*/
#ifndef __TAP_H__
#define __TAP_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifndef va_copy
#ifdef __va_copy
#define va_copy __va_copy
#else
#define va_copy(d, s) ((d) = (s))
#endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args);
int ok_at_loc (const char *file, int line, int test, const char *fmt,
...);
int is_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int isnt_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int cmp_ok_at_loc (const char *file, int line, int a, const char *op,
int b, const char *fmt, ...);
int cmp_mem_at_loc (const char *file, int line, const void *got,
const void *expected, size_t n, const char *fmt, ...);
int bail_out (int ignore, const char *fmt, ...);
void tap_plan (int tests, const char *fmt, ...);
int diag (const char *fmt, ...);
int exit_status (void);
void tap_skip (int n, const char *fmt, ...);
void tap_todo (int ignore, const char *fmt, ...);
void tap_end_todo (void);
#define NO_PLAN -1
#define SKIP_ALL -2
#define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_mem(...) cmp_mem_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define plan(...) tap_plan(__VA_ARGS__, NULL)
#define done_testing() return exit_status()
#define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
#define pass(...) ok(1, "" __VA_ARGS__)
#define fail(...) ok(0, "" __VA_ARGS__)
#define skip(test, ...) do {if (test) {tap_skip(__VA_ARGS__, NULL); break;}
#define end_skip } while (0)
#define todo(...) tap_todo(0, "" __VA_ARGS__, NULL)
#define end_todo tap_end_todo()
#define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
#define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
#ifdef _WIN32
#define like(...) tap_skip(1, "like is not implemented on Windows")
-#define unlike tap_skip(1, "unlike is not implemented on Windows")
+#define unlike(...) tap_skip(1, "unlike is not implemented on Windows")
#define dies_ok_common(...) \
tap_skip(1, "Death detection is not supported on Windows")
#else
#define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
#define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
int like_at_loc (int for_match, const char *file, int line,
const char *got, const char *expected,
const char *fmt, ...);
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int tap_test_died (int status);
#define dies_ok_common(for_death, code, ...) \
do { \
int cpid; \
int it_died; \
tap_test_died(1); \
cpid = fork(); \
switch (cpid) { \
case -1: \
perror("fork error"); \
exit(1); \
case 0: \
close(1); \
close(2); \
code \
tap_test_died(0); \
exit(0); \
} \
if (waitpid(cpid, NULL, 0) < 0) { \
perror("waitpid error"); \
exit(1); \
} \
it_died = tap_test_died(0); \
if (!it_died) \
{code} \
ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \
} while (0)
#endif
#ifdef __cplusplus
}
#endif
#endif
|
zorgnax/libtap
|
96cc218b4fbbafe506805c53fa35e1fa88fdaa34
|
tap.c: fix unused parameter warnings
|
diff --git a/tap.c b/tap.c
index 39c2bc2..e7b1cef 100644
--- a/tap.c
+++ b/tap.c
@@ -1,360 +1,362 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the LGPL
*/
#define _DEFAULT_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
if (!str) {
perror("malloc error");
exit(1);
}
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
tap_plan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
diag("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
if (!test) {
printf("not ");
}
printf("ok %d", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
printf("# Failed ");
if (todo_mesg)
printf("(TODO) ");
printf("test ");
if (*name)
printf("'%s'\n# ", name);
printf("at %s line %d.\n", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static int
find_mem_diff (const char *a, const char *b, size_t n, size_t *offset) {
size_t i;
if (a == b)
return 0;
if (!a || !b)
return 2;
for (i = 0; i < n; i++) {
if (a[i] != b[i]) {
*offset = i;
return 1;
}
}
return 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;
}
int
diag (const char *fmt, ...) {
va_list args;
char *mesg, *line;
int i;
va_start(args, fmt);
if (!fmt) {
va_end(args);
return 0;
}
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
printf("# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 2;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
retval = 1;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
+ (void)ignore;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
tap_skip (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
diag("skip %s\n", why);
}
free(why);
}
void
tap_todo (int ignore, const char *fmt, ...) {
va_list args;
+ (void)ignore;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
tap_end_todo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
#ifndef MAP_ANONYMOUS
#ifdef MAP_ANON
#define MAP_ANONYMOUS MAP_ANON
#else
#error "System does not support mapping anonymous pages"
#endif
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros. */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
|
zorgnax/libtap
|
593108e0006b67761bfeecfa46673560afe2eaf7
|
tap:c don't leak arg va_list if format string is NULL
|
diff --git a/tap.c b/tap.c
index bde6189..39c2bc2 100644
--- a/tap.c
+++ b/tap.c
@@ -1,358 +1,360 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the LGPL
*/
#define _DEFAULT_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
if (!str) {
perror("malloc error");
exit(1);
}
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
tap_plan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
diag("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
if (!test) {
printf("not ");
}
printf("ok %d", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
printf("# Failed ");
if (todo_mesg)
printf("(TODO) ");
printf("test ");
if (*name)
printf("'%s'\n# ", name);
printf("at %s line %d.\n", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static int
find_mem_diff (const char *a, const char *b, size_t n, size_t *offset) {
size_t i;
if (a == b)
return 0;
if (!a || !b)
return 2;
for (i = 0; i < n; i++) {
if (a[i] != b[i]) {
*offset = i;
return 1;
}
}
return 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;
}
int
diag (const char *fmt, ...) {
va_list args;
char *mesg, *line;
int i;
va_start(args, fmt);
- if (!fmt)
+ if (!fmt) {
+ va_end(args);
return 0;
+ }
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
printf("# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 2;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
retval = 1;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
tap_skip (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
diag("skip %s\n", why);
}
free(why);
}
void
tap_todo (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
tap_end_todo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
#ifndef MAP_ANONYMOUS
#ifdef MAP_ANON
#define MAP_ANONYMOUS MAP_ANON
#else
#error "System does not support mapping anonymous pages"
#endif
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros. */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
|
zorgnax/libtap
|
3c99c3d1c745149aaa80c0af9bef75fad3a55e64
|
Only define define MAP_ANONYMOUS when necessary
|
diff --git a/tap.c b/tap.c
index 152e39e..bde6189 100644
--- a/tap.c
+++ b/tap.c
@@ -1,354 +1,358 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the LGPL
*/
#define _DEFAULT_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
if (!str) {
perror("malloc error");
exit(1);
}
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
tap_plan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
diag("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
if (!test) {
printf("not ");
}
printf("ok %d", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
printf("# Failed ");
if (todo_mesg)
printf("(TODO) ");
printf("test ");
if (*name)
printf("'%s'\n# ", name);
printf("at %s line %d.\n", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static int
find_mem_diff (const char *a, const char *b, size_t n, size_t *offset) {
size_t i;
if (a == b)
return 0;
if (!a || !b)
return 2;
for (i = 0; i < n; i++) {
if (a[i] != b[i]) {
*offset = i;
return 1;
}
}
return 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;
}
int
diag (const char *fmt, ...) {
va_list args;
char *mesg, *line;
int i;
va_start(args, fmt);
if (!fmt)
return 0;
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
printf("# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 2;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
retval = 1;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
tap_skip (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
diag("skip %s\n", why);
}
free(why);
}
void
tap_todo (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
tap_end_todo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
-#if defined __APPLE__ || defined BSD
+#ifndef MAP_ANONYMOUS
+#ifdef MAP_ANON
#define MAP_ANONYMOUS MAP_ANON
+#else
+#error "System does not support mapping anonymous pages"
+#endif
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros. */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
|
zorgnax/libtap
|
699f2f5561bd1cf6620d3e4e18b51645ae85beb6
|
Change the synopsis a little bit
|
diff --git a/README.md b/README.md
index f89ea6c..5332d52 100644
--- a/README.md
+++ b/README.md
@@ -1,273 +1,268 @@
NAME
====
libtap - Write tests in C
SYNOPSIS
========
#include <tap.h>
int main () {
plan(5);
- ok(3 == 3);
- is("fnord", "eek", "two different strings not that way?");
- ok(3 <= 8732, "%d <= %d", 3, 8732);
- like("fnord", "f(yes|no)r*[a-f]$");
- cmp_ok(3, ">=", 10);
+ int bronze = 1, silver = 2, gold = 3;
+ ok(bronze < silver, "bronze is less than silver");
+ ok(bronze > silver, "not quite");
+ is("gold", "gold", "gold is gold");
+ cmp_ok(silver, "<", gold, "%d <= %d", silver, gold);
+ like("platinum", ".*inum", "platinum matches .*inum");
done_testing();
}
results in:
1..5
- ok 1
- not ok 2 - two different strings not that way?
- # Failed test 'two different strings not that way?'
+ ok 1 - bronze is less than silver
+ not ok 2 - not quite
+ # Failed test 'not quite'
# at t/synopsis.c line 7.
- # got: 'fnord'
- # expected: 'eek'
- ok 3 - 3 <= 8732
- ok 4
- not ok 5
- # Failed test at t/synopsis.c line 10.
- # 3
- # >=
- # 10
- # Looks like you failed 2 tests of 5 run.
+ ok 3 - gold is gold
+ ok 4 - 2 <= 3
+ ok 5 - platinum matches .*inum
+ # Looks like you failed 1 test of 5 run.
DESCRIPTION
===========
tap is an easy to read and easy to write way of creating tests for
your software. This library creates functions that can be used to
generate it for your C programs. It is implemented using macros
that include file and line info automatically, and makes it so that
the format message of each test is optional. It is mostly based on
the Test::More Perl module.
INSTALL
=======
On **Unix** systems:
$ make
$ make install
For more detailed installation instructions (eg, for **Windows**), see `INSTALL`.
FUNCTIONS
=========
- plan(tests)
- plan(NO_PLAN)
- plan(SKIP_ALL);
- plan(SKIP_ALL, fmt, ...)
Use this to start a series of tests. When you know how many tests there
will be, you can put a number as a number of tests you expect to run. If
you do not know how many tests there will be, you can use plan(NO_PLAN)
or not call this function. When you pass it a number of tests to run, a
message similar to the following will appear in the output:
1..5
If you pass it SKIP_ALL, the whole test will be skipped.
- ok(test)
- ok(test, fmt, ...)
Specify a test. the test can be any statement returning a true or false
value. You may optionally pass a format string describing the test.
ok(r = reader_new("Of Mice and Men"), "create a new reader");
ok(reader_go_to_page(r, 55), "can turn the page");
ok(r->page == 55, "page turned to the right one");
Should print out:
ok 1 - create a new reader
ok 2 - can turn the page
ok 3 - page turned to the right one
On failure, a diagnostic message will be printed out.
not ok 3 - page turned to the right one
# Failed test 'page turned to the right one'
# at reader.c line 13.
- is(got, expected)
- is(got, expected, fmt, ...)
- isnt(got, unexpected)
- isnt(got, unexpected, fmt, ...)
Tests that the string you got is what you expected. with isnt, it is the
reverse.
is("this", "that", "this is that");
prints:
not ok 1 - this is that
# Failed test 'this is that'
# at is.c line 6.
# got: 'this'
# expected: 'that'
- cmp_ok(a, op, b)
- cmp_ok(a, op, b, fmt, ...)
Compares two ints with any binary operator that doesn't require an lvalue.
This is nice to use since it provides a better error message than an
equivalent ok.
cmp_ok(420, ">", 666);
prints:
not ok 1
# Failed test at cmpok.c line 5.
# 420
# >
# 666
- cmp_mem(got, expected, n)
- cmp_mem(got, expected, n, fmt, ...)
Tests that the first n bytes of the memory you got is what you expected.
NULL pointers for got and expected are handled (if either is NULL,
the test fails), but you need to ensure n is not too large.
char *a = "foo";
char *b = "bar";
cmp_mem(a, b, 3)
prints
not ok 1
# Failed test at t/cmp_mem.c line 9.
# Difference starts at offset 0
# got: 0x66
# expected: 0x62
- like(got, expected)
- like(got, expected, fmt, ...)
- unlike(got, unexpected)
- unlike(got, unexpected, fmt, ...)
Tests that the string you got matches the expected extended POSIX regex.
unlike is the reverse. These macros are the equivalent of a skip on
Windows.
like("stranger", "^s.(r).*\\1$", "matches the regex");
prints:
ok 1 - matches the regex
- pass()
- pass(fmt, ...)
- fail()
- fail(fmt, ...)
Speciy that a test succeeded or failed. Use these when the statement is
longer than you can fit into the argument given to an ok() test.
- dies_ok(code)
- dies_ok(code, fmt, ...)
- lives_ok(code)
- lives_ok(code, fmt, ...)
Tests whether the given code causes your program to exit. The code gets
passed to a macro that will test it in a forked process. If the code
succeeds it will be executed in the parent process. You can test things
like passing a function a null pointer and make sure it doesnt
dereference it and crash.
dies_ok({abort();}, "abort does close your program");
dies_ok({int x = 0/0;}, "divide by zero crash");
lives_ok({pow(3.0, 5.0);}, "nothing wrong with taking 3**5");
On Windows, these macros are the equivalent of a skip.
- done_testing()
Summarizes the tests that occurred and exits the main function. If
there was no plan, it will print out the number of tests as.
1..5
It will also print a diagnostic message about how many
failures there were.
# Looks like you failed 2 tests of 3 run.
If all planned tests were successful, it will return 0. If any
test fails, it will return 1. If they all passed, but there
were missing tests, it will return 2.
- diag(fmt, ...)
print out a message to the tap output on stdout. Each line is
preceeded by a "# " so that you know its a diagnostic message.
diag("This is\na diag\nto describe\nsomething.");
prints:
# This is
# a diag
# to describe
# something
ok() and this function return an int so you can use it like:
ok(0) || diag("doh!");
- skip(test, n)
- skip(test, n, fmt, ...)
- end_skip
Skip a series of n tests if test is true. You may give a reason why you are
skipping them or not. The (possibly) skipped tests must occur between the
skip and end_skip macros.
skip(TRUE, 2);
ok(1);
ok(0);
end_skip;
prints:
ok 1 # skip
ok 2 # skip
- todo()
- todo(fmt, ...)
- end_todo
Specifies a series of tests that you expect to fail because they are not
yet implemented.
todo()
ok(0);
end_todo;
prints:
not ok 1 # TODO
# Failed (TODO) test at todo.c line 7
- BAIL_OUT()
- BAIL_OUT(fmt, ...)
Immediately stops all testing.
BAIL_OUT("Can't go no further");
prints
Bail out! Can't go no further
and exits with 255.
diff --git a/t/synopsis.c b/t/synopsis.c
index 86314d5..36675b7 100644
--- a/t/synopsis.c
+++ b/t/synopsis.c
@@ -1,12 +1,13 @@
#include "tap.h"
int main () {
plan(5);
- ok(3 == 3);
- is("fnord", "eek", "two different strings not that way?");
- ok(3 <= 8732, "%d <= %d", 3, 8732);
- like("fnord", "f(yes|no)r*[a-f]$");
- cmp_ok(3, ">=", 10);
+ int bronze = 1, silver = 2, gold = 3;
+ ok(bronze < silver, "bronze is less than silver");
+ ok(bronze > silver, "not quite");
+ is("gold", "gold", "gold is gold");
+ cmp_ok(silver, "<", gold, "%d <= %d", silver, gold);
+ like("platinum", ".*inum", "platinum matches .*inum");
done_testing();
}
diff --git a/t/synopsis.expected b/t/synopsis.expected
index 5b39a01..832878f 100644
--- a/t/synopsis.expected
+++ b/t/synopsis.expected
@@ -1,15 +1,9 @@
1..5
-ok 1
-not ok 2 - two different strings not that way?
-# Failed test 'two different strings not that way?'
-# at t/synopsis.c line 6.
-# got: 'fnord'
-# expected: 'eek'
-ok 3 - 3 <= 8732
-ok 4
-not ok 5
-# Failed test at t/synopsis.c line 9.
-# 3
-# >=
-# 10
-# Looks like you failed 2 tests of 5 run.
+ok 1 - bronze is less than silver
+not ok 2 - not quite
+# Failed test 'not quite'
+# at t/synopsis.c line 7.
+ok 3 - gold is gold
+ok 4 - 2 <= 3
+ok 5 - platinum matches .*inum
+# Looks like you failed 1 test of 5 run.
|
zorgnax/libtap
|
71d6d2ea7e33a24b90c89fee6bed92d5834c4f4d
|
They will have diff installed, no need to mention it
|
diff --git a/INSTALL b/INSTALL
index 05197cc..5b2c76d 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,43 +1,41 @@
-To install libtap on a unix-like system:
+To install libtap on a Unix-like system:
$ make
$ make check
$ make install
-Note that `make check` makes use of diff(1), so if you run it, make
-sure you have those tools installed first. To compile with gcc
--ansi, run:
+To compile with gcc -ansi, run:
$ ANSI=1 make
To install to a different directory than /usr/local, supply the
PREFIX variable to make:
$ PREFIX=/usr make install
On Windows, the library can be created by first setting up the
correct development environment variables. Usually this is done by
-running vcvars32.bat included in the visual studio distribution.
+running vcvars32.bat included in the Visual Studio distribution.
You should also install gnu make which can be found at
http://gnuwin32.sourceforge.net/packages/make.htm. Once this is
done, you should be able to run the following:
> make -f Makefile.win
If you want to use it directly in another project, you can copy tap.c
and tap.h there and it shouldn't have a problem compiling.
$ ls
tap.c tap.h test.c
$ cat test.c
#include "tap.h"
int main () {
plan(1);
ok(50 + 5, "foo %s", "bar");
done_testing();
}
$ gcc test.c tap.c
$ a.out
1..1
ok 1 - foo bar
|
zorgnax/libtap
|
503bcc45368c0343b28a5391cedcb6bfdc279c75
|
Do not auto cast first argument to an int in the ok macro
|
diff --git a/tap.h b/tap.h
index 7cccdba..d1f9af3 100644
--- a/tap.h
+++ b/tap.h
@@ -1,115 +1,115 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the LGPL
*/
#ifndef __TAP_H__
#define __TAP_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifndef va_copy
#ifdef __va_copy
#define va_copy __va_copy
#else
#define va_copy(d, s) ((d) = (s))
#endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args);
int ok_at_loc (const char *file, int line, int test, const char *fmt,
...);
int is_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int isnt_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int cmp_ok_at_loc (const char *file, int line, int a, const char *op,
int b, const char *fmt, ...);
int cmp_mem_at_loc (const char *file, int line, const void *got,
const void *expected, size_t n, const char *fmt, ...);
int bail_out (int ignore, const char *fmt, ...);
void tap_plan (int tests, const char *fmt, ...);
int diag (const char *fmt, ...);
int exit_status (void);
void tap_skip (int n, const char *fmt, ...);
void tap_todo (int ignore, const char *fmt, ...);
void tap_end_todo (void);
#define NO_PLAN -1
#define SKIP_ALL -2
-#define ok(...) ok_at_loc(__FILE__, __LINE__, (int) __VA_ARGS__, NULL)
+#define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_mem(...) cmp_mem_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define plan(...) tap_plan(__VA_ARGS__, NULL)
#define done_testing() return exit_status()
#define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
#define pass(...) ok(1, "" __VA_ARGS__)
#define fail(...) ok(0, "" __VA_ARGS__)
#define skip(test, ...) do {if (test) {tap_skip(__VA_ARGS__, NULL); break;}
#define end_skip } while (0)
#define todo(...) tap_todo(0, "" __VA_ARGS__, NULL)
#define end_todo tap_end_todo()
#define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
#define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
#ifdef _WIN32
#define like(...) tap_skip(1, "like is not implemented on Windows")
#define unlike tap_skip(1, "unlike is not implemented on Windows")
#define dies_ok_common(...) \
tap_skip(1, "Death detection is not supported on Windows")
#else
#define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
#define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
int like_at_loc (int for_match, const char *file, int line,
const char *got, const char *expected,
const char *fmt, ...);
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int tap_test_died (int status);
#define dies_ok_common(for_death, code, ...) \
do { \
int cpid; \
int it_died; \
tap_test_died(1); \
cpid = fork(); \
switch (cpid) { \
case -1: \
perror("fork error"); \
exit(1); \
case 0: \
close(1); \
close(2); \
code \
tap_test_died(0); \
exit(0); \
} \
if (waitpid(cpid, NULL, 0) < 0) { \
perror("waitpid error"); \
exit(1); \
} \
it_died = tap_test_died(0); \
if (!it_died) \
{code} \
ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \
} while (0)
#endif
#ifdef __cplusplus
}
#endif
#endif
|
zorgnax/libtap
|
e08bb1df1ff5029e5f3b9978f79b86211ba22ab2
|
Add a note about the use of macros
|
diff --git a/README.md b/README.md
index 711fece..f89ea6c 100644
--- a/README.md
+++ b/README.md
@@ -1,270 +1,273 @@
NAME
====
libtap - Write tests in C
SYNOPSIS
========
#include <tap.h>
int main () {
plan(5);
ok(3 == 3);
is("fnord", "eek", "two different strings not that way?");
ok(3 <= 8732, "%d <= %d", 3, 8732);
like("fnord", "f(yes|no)r*[a-f]$");
cmp_ok(3, ">=", 10);
done_testing();
}
results in:
1..5
ok 1
not ok 2 - two different strings not that way?
# Failed test 'two different strings not that way?'
# at t/synopsis.c line 7.
# got: 'fnord'
# expected: 'eek'
ok 3 - 3 <= 8732
ok 4
not ok 5
# Failed test at t/synopsis.c line 10.
# 3
# >=
# 10
# Looks like you failed 2 tests of 5 run.
DESCRIPTION
===========
-tap is an easy to read and easy to write way of creating tests for your
-software. This library creates functions that can be used to generate it for
-your C programs. It is mostly based on the Test::More Perl module.
+tap is an easy to read and easy to write way of creating tests for
+your software. This library creates functions that can be used to
+generate it for your C programs. It is implemented using macros
+that include file and line info automatically, and makes it so that
+the format message of each test is optional. It is mostly based on
+the Test::More Perl module.
INSTALL
=======
On **Unix** systems:
$ make
$ make install
For more detailed installation instructions (eg, for **Windows**), see `INSTALL`.
FUNCTIONS
=========
- plan(tests)
- plan(NO_PLAN)
- plan(SKIP_ALL);
- plan(SKIP_ALL, fmt, ...)
Use this to start a series of tests. When you know how many tests there
will be, you can put a number as a number of tests you expect to run. If
you do not know how many tests there will be, you can use plan(NO_PLAN)
or not call this function. When you pass it a number of tests to run, a
message similar to the following will appear in the output:
1..5
If you pass it SKIP_ALL, the whole test will be skipped.
- ok(test)
- ok(test, fmt, ...)
Specify a test. the test can be any statement returning a true or false
value. You may optionally pass a format string describing the test.
ok(r = reader_new("Of Mice and Men"), "create a new reader");
ok(reader_go_to_page(r, 55), "can turn the page");
ok(r->page == 55, "page turned to the right one");
Should print out:
ok 1 - create a new reader
ok 2 - can turn the page
ok 3 - page turned to the right one
On failure, a diagnostic message will be printed out.
not ok 3 - page turned to the right one
# Failed test 'page turned to the right one'
# at reader.c line 13.
- is(got, expected)
- is(got, expected, fmt, ...)
- isnt(got, unexpected)
- isnt(got, unexpected, fmt, ...)
Tests that the string you got is what you expected. with isnt, it is the
reverse.
is("this", "that", "this is that");
prints:
not ok 1 - this is that
# Failed test 'this is that'
# at is.c line 6.
# got: 'this'
# expected: 'that'
- cmp_ok(a, op, b)
- cmp_ok(a, op, b, fmt, ...)
Compares two ints with any binary operator that doesn't require an lvalue.
This is nice to use since it provides a better error message than an
equivalent ok.
cmp_ok(420, ">", 666);
prints:
not ok 1
# Failed test at cmpok.c line 5.
# 420
# >
# 666
- cmp_mem(got, expected, n)
- cmp_mem(got, expected, n, fmt, ...)
Tests that the first n bytes of the memory you got is what you expected.
NULL pointers for got and expected are handled (if either is NULL,
the test fails), but you need to ensure n is not too large.
char *a = "foo";
char *b = "bar";
cmp_mem(a, b, 3)
prints
not ok 1
# Failed test at t/cmp_mem.c line 9.
# Difference starts at offset 0
# got: 0x66
# expected: 0x62
- like(got, expected)
- like(got, expected, fmt, ...)
- unlike(got, unexpected)
- unlike(got, unexpected, fmt, ...)
Tests that the string you got matches the expected extended POSIX regex.
unlike is the reverse. These macros are the equivalent of a skip on
Windows.
like("stranger", "^s.(r).*\\1$", "matches the regex");
prints:
ok 1 - matches the regex
- pass()
- pass(fmt, ...)
- fail()
- fail(fmt, ...)
Speciy that a test succeeded or failed. Use these when the statement is
longer than you can fit into the argument given to an ok() test.
- dies_ok(code)
- dies_ok(code, fmt, ...)
- lives_ok(code)
- lives_ok(code, fmt, ...)
Tests whether the given code causes your program to exit. The code gets
passed to a macro that will test it in a forked process. If the code
succeeds it will be executed in the parent process. You can test things
like passing a function a null pointer and make sure it doesnt
dereference it and crash.
dies_ok({abort();}, "abort does close your program");
dies_ok({int x = 0/0;}, "divide by zero crash");
lives_ok({pow(3.0, 5.0);}, "nothing wrong with taking 3**5");
On Windows, these macros are the equivalent of a skip.
- done_testing()
Summarizes the tests that occurred and exits the main function. If
there was no plan, it will print out the number of tests as.
1..5
It will also print a diagnostic message about how many
failures there were.
# Looks like you failed 2 tests of 3 run.
If all planned tests were successful, it will return 0. If any
test fails, it will return 1. If they all passed, but there
were missing tests, it will return 2.
- diag(fmt, ...)
print out a message to the tap output on stdout. Each line is
preceeded by a "# " so that you know its a diagnostic message.
diag("This is\na diag\nto describe\nsomething.");
prints:
# This is
# a diag
# to describe
# something
ok() and this function return an int so you can use it like:
ok(0) || diag("doh!");
- skip(test, n)
- skip(test, n, fmt, ...)
- end_skip
Skip a series of n tests if test is true. You may give a reason why you are
skipping them or not. The (possibly) skipped tests must occur between the
skip and end_skip macros.
skip(TRUE, 2);
ok(1);
ok(0);
end_skip;
prints:
ok 1 # skip
ok 2 # skip
- todo()
- todo(fmt, ...)
- end_todo
Specifies a series of tests that you expect to fail because they are not
yet implemented.
todo()
ok(0);
end_todo;
prints:
not ok 1 # TODO
# Failed (TODO) test at todo.c line 7
- BAIL_OUT()
- BAIL_OUT(fmt, ...)
Immediately stops all testing.
BAIL_OUT("Can't go no further");
prints
Bail out! Can't go no further
and exits with 255.
|
zorgnax/libtap
|
6278b5c958802a70f02dab77f26fd16756232903
|
Remove the ; at the end of cmp_mem macro
|
diff --git a/tap.h b/tap.h
index 85f776a..7cccdba 100644
--- a/tap.h
+++ b/tap.h
@@ -1,115 +1,115 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the LGPL
*/
#ifndef __TAP_H__
#define __TAP_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifndef va_copy
#ifdef __va_copy
#define va_copy __va_copy
#else
#define va_copy(d, s) ((d) = (s))
#endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args);
int ok_at_loc (const char *file, int line, int test, const char *fmt,
...);
int is_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int isnt_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int cmp_ok_at_loc (const char *file, int line, int a, const char *op,
int b, const char *fmt, ...);
int cmp_mem_at_loc (const char *file, int line, const void *got,
const void *expected, size_t n, const char *fmt, ...);
int bail_out (int ignore, const char *fmt, ...);
void tap_plan (int tests, const char *fmt, ...);
int diag (const char *fmt, ...);
int exit_status (void);
void tap_skip (int n, const char *fmt, ...);
void tap_todo (int ignore, const char *fmt, ...);
void tap_end_todo (void);
#define NO_PLAN -1
#define SKIP_ALL -2
#define ok(...) ok_at_loc(__FILE__, __LINE__, (int) __VA_ARGS__, NULL)
#define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
-#define cmp_mem(...) cmp_mem_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL);
+#define cmp_mem(...) cmp_mem_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define plan(...) tap_plan(__VA_ARGS__, NULL)
#define done_testing() return exit_status()
#define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
#define pass(...) ok(1, "" __VA_ARGS__)
#define fail(...) ok(0, "" __VA_ARGS__)
#define skip(test, ...) do {if (test) {tap_skip(__VA_ARGS__, NULL); break;}
#define end_skip } while (0)
#define todo(...) tap_todo(0, "" __VA_ARGS__, NULL)
#define end_todo tap_end_todo()
#define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
#define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
#ifdef _WIN32
#define like(...) tap_skip(1, "like is not implemented on Windows")
#define unlike tap_skip(1, "unlike is not implemented on Windows")
#define dies_ok_common(...) \
tap_skip(1, "Death detection is not supported on Windows")
#else
#define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
#define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
int like_at_loc (int for_match, const char *file, int line,
const char *got, const char *expected,
const char *fmt, ...);
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int tap_test_died (int status);
#define dies_ok_common(for_death, code, ...) \
do { \
int cpid; \
int it_died; \
tap_test_died(1); \
cpid = fork(); \
switch (cpid) { \
case -1: \
perror("fork error"); \
exit(1); \
case 0: \
close(1); \
close(2); \
code \
tap_test_died(0); \
exit(0); \
} \
if (waitpid(cpid, NULL, 0) < 0) { \
perror("waitpid error"); \
exit(1); \
} \
it_died = tap_test_died(0); \
if (!it_died) \
{code} \
ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \
} while (0)
#endif
#ifdef __cplusplus
}
#endif
#endif
|
zorgnax/libtap
|
275a69de3d4ee32b8729b07c12c2d79bd5223356
|
Makefile variable changes to help overrides on command line
|
diff --git a/INSTALL b/INSTALL
index a74527b..05197cc 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,43 +1,43 @@
To install libtap on a unix-like system:
$ make
$ make check
$ make install
Note that `make check` makes use of diff(1), so if you run it, make
sure you have those tools installed first. To compile with gcc
-ansi, run:
- $ make ANSI=1
+ $ ANSI=1 make
To install to a different directory than /usr/local, supply the
PREFIX variable to make:
- $ make PREFIX=/usr install
+ $ PREFIX=/usr make install
On Windows, the library can be created by first setting up the
correct development environment variables. Usually this is done by
running vcvars32.bat included in the visual studio distribution.
You should also install gnu make which can be found at
http://gnuwin32.sourceforge.net/packages/make.htm. Once this is
done, you should be able to run the following:
> make -f Makefile.win
If you want to use it directly in another project, you can copy tap.c
and tap.h there and it shouldn't have a problem compiling.
$ ls
tap.c tap.h test.c
$ cat test.c
#include "tap.h"
int main () {
plan(1);
ok(50 + 5, "foo %s", "bar");
done_testing();
}
$ gcc test.c tap.c
$ a.out
1..1
ok 1 - foo bar
diff --git a/Makefile b/Makefile
index 180ada2..c00bef1 100644
--- a/Makefile
+++ b/Makefile
@@ -1,72 +1,72 @@
-CFLAGS += -g -Wall -I. -fPIC
CC ?= gcc
-PREFIX = $(DESTDIR)/usr/local
+CFLAGS += -Wall -I. -fPIC
+PREFIX ?= $(DESTDIR)/usr/local
TESTS = $(patsubst %.c, %, $(wildcard t/*.c))
ifdef ANSI
# -D_BSD_SOURCE for MAP_ANONYMOUS
CFLAGS += -ansi -D_BSD_SOURCE
LDLIBS += -lbsd-compat
endif
%:
$(CC) $(LDFLAGS) $(TARGET_ARCH) $(filter %.o %.a %.so, $^) $(LDLIBS) -o $@
%.o:
$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $(filter %.c, $^) $(LDLIBS) -o $@
%.a:
$(AR) rcs $@ $(filter %.o, $^)
%.so:
$(CC) -shared $(LDFLAGS) $(TARGET_ARCH) $(filter %.o, $^) $(LDLIBS) -o $@
all: libtap.a libtap.so tap.pc tests
tap.pc:
@echo generating tap.pc
@echo 'prefix='$(PREFIX) > tap.pc
@echo 'exec_prefix=$${prefix}' >> tap.pc
@echo 'libdir=$${prefix}/lib' >> tap.pc
@echo 'includedir=$${prefix}/include' >> tap.pc
@echo '' >> tap.pc
@echo 'Name: libtap' >> tap.pc
@echo 'Description: Write tests in C' >> tap.pc
@echo 'Version: 0.1.0' >> tap.pc
@echo 'URL: https://github.com/zorgnax/libtap' >> tap.pc
@echo 'Libs: -L$${libdir} -ltap' >> tap.pc
@echo 'Cflags: -I$${includedir}' >> tap.pc
libtap.a: tap.o
libtap.so: tap.o
tap.o: tap.c tap.h
tests: $(TESTS)
$(TESTS): %: %.o libtap.a
$(patsubst %, %.o, $(TESTS)): %.o: %.c tap.h
clean:
rm -rf *.o t/*.o tap.pc libtap.a libtap.so $(TESTS)
install: libtap.a tap.h libtap.so tap.pc
mkdir -p $(PREFIX)/lib $(PREFIX)/include $(PREFIX)/lib/pkgconfig
install -c libtap.a $(PREFIX)/lib
install -c libtap.so $(PREFIX)/lib
install -c tap.pc $(PREFIX)/lib/pkgconfig
install -c tap.h $(PREFIX)/include
uninstall:
rm $(PREFIX)/lib/libtap.a $(PREFIX)/lib/libtap.so $(PREFIX)/include/tap.h
dist:
rm libtap.zip
zip -r libtap *
check test: all
./t/test
.PHONY: all clean install uninstall dist check test tests
|
zorgnax/libtap
|
3d442fc68c722346982015292fbeb72a6a862de7
|
Allow CFLAGS and CC to be append and set
|
diff --git a/Makefile b/Makefile
index 1bec192..180ada2 100644
--- a/Makefile
+++ b/Makefile
@@ -1,72 +1,72 @@
-CFLAGS = -g -Wall -I. -fPIC
-CC = gcc
+CFLAGS += -g -Wall -I. -fPIC
+CC ?= gcc
PREFIX = $(DESTDIR)/usr/local
TESTS = $(patsubst %.c, %, $(wildcard t/*.c))
ifdef ANSI
# -D_BSD_SOURCE for MAP_ANONYMOUS
CFLAGS += -ansi -D_BSD_SOURCE
LDLIBS += -lbsd-compat
endif
%:
$(CC) $(LDFLAGS) $(TARGET_ARCH) $(filter %.o %.a %.so, $^) $(LDLIBS) -o $@
%.o:
$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $(filter %.c, $^) $(LDLIBS) -o $@
%.a:
$(AR) rcs $@ $(filter %.o, $^)
%.so:
$(CC) -shared $(LDFLAGS) $(TARGET_ARCH) $(filter %.o, $^) $(LDLIBS) -o $@
all: libtap.a libtap.so tap.pc tests
tap.pc:
@echo generating tap.pc
@echo 'prefix='$(PREFIX) > tap.pc
@echo 'exec_prefix=$${prefix}' >> tap.pc
@echo 'libdir=$${prefix}/lib' >> tap.pc
@echo 'includedir=$${prefix}/include' >> tap.pc
@echo '' >> tap.pc
@echo 'Name: libtap' >> tap.pc
@echo 'Description: Write tests in C' >> tap.pc
@echo 'Version: 0.1.0' >> tap.pc
@echo 'URL: https://github.com/zorgnax/libtap' >> tap.pc
@echo 'Libs: -L$${libdir} -ltap' >> tap.pc
@echo 'Cflags: -I$${includedir}' >> tap.pc
libtap.a: tap.o
libtap.so: tap.o
tap.o: tap.c tap.h
tests: $(TESTS)
$(TESTS): %: %.o libtap.a
$(patsubst %, %.o, $(TESTS)): %.o: %.c tap.h
clean:
rm -rf *.o t/*.o tap.pc libtap.a libtap.so $(TESTS)
install: libtap.a tap.h libtap.so tap.pc
mkdir -p $(PREFIX)/lib $(PREFIX)/include $(PREFIX)/lib/pkgconfig
install -c libtap.a $(PREFIX)/lib
install -c libtap.so $(PREFIX)/lib
install -c tap.pc $(PREFIX)/lib/pkgconfig
install -c tap.h $(PREFIX)/include
uninstall:
rm $(PREFIX)/lib/libtap.a $(PREFIX)/lib/libtap.so $(PREFIX)/include/tap.h
dist:
rm libtap.zip
zip -r libtap *
check test: all
./t/test
.PHONY: all clean install uninstall dist check test tests
|
zorgnax/libtap
|
d2109aa9d3898359bb8c5f8dabe0221169ed4bd2
|
Use x variable so compiler doesn't complain about it
|
diff --git a/t/diesok.c b/t/diesok.c
index 2ec156f..e5471bf 100644
--- a/t/diesok.c
+++ b/t/diesok.c
@@ -1,14 +1,14 @@
#include "tap.h"
int main () {
plan(5);
ok(1, "sanity");
dies_ok({int x = 0; x = x/x;}, "can't divide by zero");
- lives_ok({int x; x = 3/7;}, "this is a perfectly fine statement");
+ lives_ok({int x = 3; x = x/7;}, "this is a perfectly fine statement");
dies_ok({abort();}, "abort kills the program");
dies_ok(
{printf("stdout\n"); fprintf(stderr, "stderr\n"); abort();},
"supress output");
done_testing();
}
|
zorgnax/libtap
|
16681aa47681cabadf71cc0ecaa4a3e3ccd80366
|
Cast argument to int to avoid possibly compiler warnings
|
diff --git a/tap.h b/tap.h
index 8269e7e..85f776a 100644
--- a/tap.h
+++ b/tap.h
@@ -1,115 +1,115 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the LGPL
*/
#ifndef __TAP_H__
#define __TAP_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifndef va_copy
#ifdef __va_copy
#define va_copy __va_copy
#else
#define va_copy(d, s) ((d) = (s))
#endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args);
int ok_at_loc (const char *file, int line, int test, const char *fmt,
...);
int is_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int isnt_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int cmp_ok_at_loc (const char *file, int line, int a, const char *op,
int b, const char *fmt, ...);
int cmp_mem_at_loc (const char *file, int line, const void *got,
const void *expected, size_t n, const char *fmt, ...);
int bail_out (int ignore, const char *fmt, ...);
void tap_plan (int tests, const char *fmt, ...);
int diag (const char *fmt, ...);
int exit_status (void);
void tap_skip (int n, const char *fmt, ...);
void tap_todo (int ignore, const char *fmt, ...);
void tap_end_todo (void);
#define NO_PLAN -1
#define SKIP_ALL -2
-#define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
+#define ok(...) ok_at_loc(__FILE__, __LINE__, (int) __VA_ARGS__, NULL)
#define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_mem(...) cmp_mem_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL);
#define plan(...) tap_plan(__VA_ARGS__, NULL)
#define done_testing() return exit_status()
#define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
#define pass(...) ok(1, "" __VA_ARGS__)
#define fail(...) ok(0, "" __VA_ARGS__)
#define skip(test, ...) do {if (test) {tap_skip(__VA_ARGS__, NULL); break;}
#define end_skip } while (0)
#define todo(...) tap_todo(0, "" __VA_ARGS__, NULL)
#define end_todo tap_end_todo()
#define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
#define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
#ifdef _WIN32
#define like(...) tap_skip(1, "like is not implemented on Windows")
#define unlike tap_skip(1, "unlike is not implemented on Windows")
#define dies_ok_common(...) \
tap_skip(1, "Death detection is not supported on Windows")
#else
#define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
#define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
int like_at_loc (int for_match, const char *file, int line,
const char *got, const char *expected,
const char *fmt, ...);
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int tap_test_died (int status);
#define dies_ok_common(for_death, code, ...) \
do { \
int cpid; \
int it_died; \
tap_test_died(1); \
cpid = fork(); \
switch (cpid) { \
case -1: \
perror("fork error"); \
exit(1); \
case 0: \
close(1); \
close(2); \
code \
tap_test_died(0); \
exit(0); \
} \
if (waitpid(cpid, NULL, 0) < 0) { \
perror("waitpid error"); \
exit(1); \
} \
it_died = tap_test_died(0); \
if (!it_died) \
{code} \
ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \
} while (0)
#endif
#ifdef __cplusplus
}
#endif
#endif
|
zorgnax/libtap
|
5a85bec45f052a6756dbecba8c71bfaa4cfb15f2
|
Make all diagnostic messages go to STDOUT to avoid out of order display issues
|
diff --git a/README.md b/README.md
index 0a60767..711fece 100644
--- a/README.md
+++ b/README.md
@@ -1,273 +1,270 @@
NAME
====
libtap - Write tests in C
SYNOPSIS
========
#include <tap.h>
int main () {
plan(5);
ok(3 == 3);
is("fnord", "eek", "two different strings not that way?");
ok(3 <= 8732, "%d <= %d", 3, 8732);
like("fnord", "f(yes|no)r*[a-f]$");
cmp_ok(3, ">=", 10);
done_testing();
}
results in:
1..5
ok 1
not ok 2 - two different strings not that way?
# Failed test 'two different strings not that way?'
# at t/synopsis.c line 7.
# got: 'fnord'
# expected: 'eek'
ok 3 - 3 <= 8732
ok 4
not ok 5
# Failed test at t/synopsis.c line 10.
# 3
# >=
# 10
# Looks like you failed 2 tests of 5 run.
DESCRIPTION
===========
tap is an easy to read and easy to write way of creating tests for your
software. This library creates functions that can be used to generate it for
your C programs. It is mostly based on the Test::More Perl module.
INSTALL
=======
On **Unix** systems:
$ make
$ make install
For more detailed installation instructions (eg, for **Windows**), see `INSTALL`.
FUNCTIONS
=========
- plan(tests)
- plan(NO_PLAN)
- plan(SKIP_ALL);
- plan(SKIP_ALL, fmt, ...)
Use this to start a series of tests. When you know how many tests there
will be, you can put a number as a number of tests you expect to run. If
you do not know how many tests there will be, you can use plan(NO_PLAN)
or not call this function. When you pass it a number of tests to run, a
message similar to the following will appear in the output:
1..5
If you pass it SKIP_ALL, the whole test will be skipped.
- ok(test)
- ok(test, fmt, ...)
Specify a test. the test can be any statement returning a true or false
value. You may optionally pass a format string describing the test.
ok(r = reader_new("Of Mice and Men"), "create a new reader");
ok(reader_go_to_page(r, 55), "can turn the page");
ok(r->page == 55, "page turned to the right one");
Should print out:
ok 1 - create a new reader
ok 2 - can turn the page
ok 3 - page turned to the right one
On failure, a diagnostic message will be printed out.
not ok 3 - page turned to the right one
# Failed test 'page turned to the right one'
# at reader.c line 13.
- is(got, expected)
- is(got, expected, fmt, ...)
- isnt(got, unexpected)
- isnt(got, unexpected, fmt, ...)
Tests that the string you got is what you expected. with isnt, it is the
reverse.
is("this", "that", "this is that");
prints:
not ok 1 - this is that
# Failed test 'this is that'
# at is.c line 6.
# got: 'this'
# expected: 'that'
- cmp_ok(a, op, b)
- cmp_ok(a, op, b, fmt, ...)
Compares two ints with any binary operator that doesn't require an lvalue.
This is nice to use since it provides a better error message than an
equivalent ok.
cmp_ok(420, ">", 666);
prints:
not ok 1
# Failed test at cmpok.c line 5.
# 420
# >
# 666
- cmp_mem(got, expected, n)
- cmp_mem(got, expected, n, fmt, ...)
Tests that the first n bytes of the memory you got is what you expected.
NULL pointers for got and expected are handled (if either is NULL,
the test fails), but you need to ensure n is not too large.
char *a = "foo";
char *b = "bar";
cmp_mem(a, b, 3)
prints
not ok 1
# Failed test at t/cmp_mem.c line 9.
# Difference starts at offset 0
# got: 0x66
# expected: 0x62
- like(got, expected)
- like(got, expected, fmt, ...)
- unlike(got, unexpected)
- unlike(got, unexpected, fmt, ...)
Tests that the string you got matches the expected extended POSIX regex.
unlike is the reverse. These macros are the equivalent of a skip on
Windows.
like("stranger", "^s.(r).*\\1$", "matches the regex");
prints:
ok 1 - matches the regex
- pass()
- pass(fmt, ...)
- fail()
- fail(fmt, ...)
Speciy that a test succeeded or failed. Use these when the statement is
longer than you can fit into the argument given to an ok() test.
- dies_ok(code)
- dies_ok(code, fmt, ...)
- lives_ok(code)
- lives_ok(code, fmt, ...)
Tests whether the given code causes your program to exit. The code gets
passed to a macro that will test it in a forked process. If the code
succeeds it will be executed in the parent process. You can test things
like passing a function a null pointer and make sure it doesnt
dereference it and crash.
dies_ok({abort();}, "abort does close your program");
dies_ok({int x = 0/0;}, "divide by zero crash");
lives_ok({pow(3.0, 5.0);}, "nothing wrong with taking 3**5");
On Windows, these macros are the equivalent of a skip.
- done_testing()
Summarizes the tests that occurred and exits the main function. If
there was no plan, it will print out the number of tests as.
1..5
It will also print a diagnostic message about how many
failures there were.
# Looks like you failed 2 tests of 3 run.
If all planned tests were successful, it will return 0. If any
test fails, it will return 1. If they all passed, but there
were missing tests, it will return 2.
-- note(fmt, ...)
- diag(fmt, ...)
- print out a message to the tap output. note prints to stdout and diag
- prints to stderr. Each line is preceeded by a "# " so that you know its a
- diagnostic message.
+ print out a message to the tap output on stdout. Each line is
+ preceeded by a "# " so that you know its a diagnostic message.
- note("This is\na note\nto describe\nsomething.");
+ diag("This is\na diag\nto describe\nsomething.");
prints:
# This is
- # a note
+ # a diag
# to describe
# something
- ok() and these functions return ints so you can use them like:
+ ok() and this function return an int so you can use it like:
- ok(1) && note("yo!");
- ok(0) || diag("I have no idea what just happened");
+ ok(0) || diag("doh!");
- skip(test, n)
- skip(test, n, fmt, ...)
- end_skip
Skip a series of n tests if test is true. You may give a reason why you are
skipping them or not. The (possibly) skipped tests must occur between the
skip and end_skip macros.
skip(TRUE, 2);
ok(1);
ok(0);
end_skip;
prints:
ok 1 # skip
ok 2 # skip
- todo()
- todo(fmt, ...)
- end_todo
Specifies a series of tests that you expect to fail because they are not
yet implemented.
todo()
ok(0);
end_todo;
prints:
not ok 1 # TODO
# Failed (TODO) test at todo.c line 7
- BAIL_OUT()
- BAIL_OUT(fmt, ...)
Immediately stops all testing.
BAIL_OUT("Can't go no further");
prints
Bail out! Can't go no further
and exits with 255.
diff --git a/t/cmp_mem.c b/t/cmp_mem.c
index ac2e150..09f8a99 100644
--- a/t/cmp_mem.c
+++ b/t/cmp_mem.c
@@ -1,21 +1,20 @@
#include "tap.h"
int main () {
- setvbuf(stdout, NULL, _IONBF, 0);
unsigned char all_0[] = {0, 0, 0, 0};
unsigned char all_255[] = {255, 255, 255, 255};
unsigned char half[] = {0, 0, 255, 255};
unsigned char half_2[] = {0, 0, 255, 255};
plan(8);
cmp_mem(half, half_2, 4, "Same array different address");
cmp_mem(all_0, all_0, 4, "Array must be equal to itself");
cmp_mem(all_0, all_255, 4, "Arrays with different contents");
cmp_mem(all_0, half, 4, "Arrays differ, but start the same");
cmp_mem(all_0, all_255, 0, "Comparing 0 bytes of different arrays");
cmp_mem(NULL, all_0, 4, "got == NULL");
cmp_mem(all_0, NULL, 4, "expected == NULL");
cmp_mem(NULL, NULL, 4, "got == expected == NULL");
done_testing();
}
diff --git a/t/cmp_mem.expected b/t/cmp_mem.expected
index b47ba92..2a2c81b 100644
--- a/t/cmp_mem.expected
+++ b/t/cmp_mem.expected
@@ -1,28 +1,28 @@
1..8
ok 1 - Same array different address
ok 2 - Array must be equal to itself
not ok 3 - Arrays with different contents
# Failed test 'Arrays with different contents'
-# at t/cmp_mem.c line 13.
+# at t/cmp_mem.c line 12.
# Difference starts at offset 0
# got: 0x00
# expected: 0xff
not ok 4 - Arrays differ, but start the same
# Failed test 'Arrays differ, but start the same'
-# at t/cmp_mem.c line 14.
+# at t/cmp_mem.c line 13.
# Difference starts at offset 2
# got: 0x00
# expected: 0xff
ok 5 - Comparing 0 bytes of different arrays
not ok 6 - got == NULL
# Failed test 'got == NULL'
-# at t/cmp_mem.c line 16.
+# at t/cmp_mem.c line 15.
# got: NULL
# expected: not NULL
not ok 7 - expected == NULL
# Failed test 'expected == NULL'
-# at t/cmp_mem.c line 17.
+# at t/cmp_mem.c line 16.
# got: not NULL
# expected: NULL
ok 8 - got == expected == NULL
# Looks like you failed 4 tests of 8 run.
diff --git a/t/cmpok.c b/t/cmpok.c
index 72e8d16..6c25062 100644
--- a/t/cmpok.c
+++ b/t/cmpok.c
@@ -1,17 +1,16 @@
#include "tap.h"
int main () {
- setvbuf(stdout, NULL, _IONBF, 0);
plan(9);
cmp_ok(420, ">", 666);
cmp_ok(23, "==", 55, "the number 23 is definitely 55");
cmp_ok(23, "==", 55);
cmp_ok(23, "!=", 55);
cmp_ok(23, "frob", 55);
cmp_ok(23, "<=", 55);
cmp_ok(55, "+", -55);
cmp_ok(23, "%", 5);
cmp_ok(55, "%", 5);
done_testing();
}
diff --git a/t/cmpok.expected b/t/cmpok.expected
index a369023..4489df5 100644
--- a/t/cmpok.expected
+++ b/t/cmpok.expected
@@ -1,37 +1,37 @@
1..9
not ok 1
-# Failed test at t/cmpok.c line 6.
+# Failed test at t/cmpok.c line 5.
# 420
# >
# 666
not ok 2 - the number 23 is definitely 55
# Failed test 'the number 23 is definitely 55'
-# at t/cmpok.c line 7.
+# at t/cmpok.c line 6.
# 23
# ==
# 55
not ok 3
-# Failed test at t/cmpok.c line 8.
+# Failed test at t/cmpok.c line 7.
# 23
# ==
# 55
ok 4
# unrecognized operator 'frob'
not ok 5
-# Failed test at t/cmpok.c line 10.
+# Failed test at t/cmpok.c line 9.
# 23
# frob
# 55
ok 6
not ok 7
-# Failed test at t/cmpok.c line 12.
+# Failed test at t/cmpok.c line 11.
# 55
# +
# -55
ok 8
not ok 9
-# Failed test at t/cmpok.c line 14.
+# Failed test at t/cmpok.c line 13.
# 55
# %
# 5
# Looks like you failed 6 tests of 9 run.
diff --git a/t/diag.c b/t/diag.c
new file mode 100644
index 0000000..9b16977
--- /dev/null
+++ b/t/diag.c
@@ -0,0 +1,10 @@
+#include "tap.h"
+
+int main () {
+ diag("diag no new line");
+ diag("diag new line\n");
+ diag("");
+ diag(NULL);
+ return 1;
+}
+
diff --git a/t/notediag.expected b/t/diag.expected
similarity index 50%
rename from t/notediag.expected
rename to t/diag.expected
index ec1603c..51db520 100644
--- a/t/notediag.expected
+++ b/t/diag.expected
@@ -1,4 +1,2 @@
-# note no new line
-# note new line
# diag no new line
# diag new line
diff --git a/t/diesok.c b/t/diesok.c
index d101014..2ec156f 100644
--- a/t/diesok.c
+++ b/t/diesok.c
@@ -1,15 +1,14 @@
#include "tap.h"
int main () {
- setvbuf(stdout, NULL, _IONBF, 0);
plan(5);
ok(1, "sanity");
dies_ok({int x = 0; x = x/x;}, "can't divide by zero");
lives_ok({int x; x = 3/7;}, "this is a perfectly fine statement");
dies_ok({abort();}, "abort kills the program");
dies_ok(
{printf("stdout\n"); fprintf(stderr, "stderr\n"); abort();},
"supress output");
done_testing();
}
diff --git a/t/is.c b/t/is.c
index ecc6d75..a1f7bad 100644
--- a/t/is.c
+++ b/t/is.c
@@ -1,25 +1,24 @@
#include "tap.h"
int main () {
- setvbuf(stdout, NULL, _IONBF, 0);
plan(18);
is("this", "that", "this is that"); /* bang */
is("this", "this", "this is this");
is("this", "that"); /* bang */
is("this", "this");
is(NULL, NULL, "null is null");
is(NULL, "this", "null is this"); /* bang */
is("this", NULL, "this is null"); /* bang */
is("foo\nfoo\nfoo", "bar\nbar\nbar"); /* bang */
is("foo\nfoo\nfoo", "foo\nfoo\nfoo");
isnt("this", "that", "this isnt that");
isnt("this", "this", "this isnt this"); /* bang */
isnt("this", "that");
isnt("this", "this"); /* bang */
isnt(NULL, NULL, "null isnt null"); /* bang */
isnt(NULL, "this", "null isnt this");
isnt("this", NULL, "this isnt null");
isnt("foo\nfoo\nfoo", "bar\nbar\nbar");
isnt("foo\nfoo\nfoo", "foo\nfoo\nfoo"); /* bang */
done_testing();
}
diff --git a/t/is.expected b/t/is.expected
index d2598fb..5d3491a 100644
--- a/t/is.expected
+++ b/t/is.expected
@@ -1,58 +1,58 @@
1..18
not ok 1 - this is that
# Failed test 'this is that'
-# at t/is.c line 6.
+# at t/is.c line 5.
# got: 'this'
# expected: 'that'
ok 2 - this is this
not ok 3
-# Failed test at t/is.c line 8.
+# Failed test at t/is.c line 7.
# got: 'this'
# expected: 'that'
ok 4
ok 5 - null is null
not ok 6 - null is this
# Failed test 'null is this'
-# at t/is.c line 11.
+# at t/is.c line 10.
# got: '(null)'
# expected: 'this'
not ok 7 - this is null
# Failed test 'this is null'
-# at t/is.c line 12.
+# at t/is.c line 11.
# got: 'this'
# expected: '(null)'
not ok 8
-# Failed test at t/is.c line 13.
+# Failed test at t/is.c line 12.
# got: 'foo
# foo
# foo'
# expected: 'bar
# bar
# bar'
ok 9
ok 10 - this isnt that
not ok 11 - this isnt this
# Failed test 'this isnt this'
-# at t/is.c line 16.
+# at t/is.c line 15.
# got: 'this'
# expected: anything else
ok 12
not ok 13
-# Failed test at t/is.c line 18.
+# Failed test at t/is.c line 17.
# got: 'this'
# expected: anything else
not ok 14 - null isnt null
# Failed test 'null isnt null'
-# at t/is.c line 19.
+# at t/is.c line 18.
# got: '(null)'
# expected: anything else
ok 15 - null isnt this
ok 16 - this isnt null
ok 17
not ok 18
-# Failed test at t/is.c line 23.
+# Failed test at t/is.c line 22.
# got: 'foo
# foo
# foo'
# expected: anything else
# Looks like you failed 9 tests of 18 run.
diff --git a/t/like.c b/t/like.c
index 1623183..253a07a 100644
--- a/t/like.c
+++ b/t/like.c
@@ -1,11 +1,10 @@
#include "tap.h"
int main () {
- setvbuf(stdout, NULL, _IONBF, 0);
plan(3);
like("strange", "range", "strange ~~ /range/");
unlike("strange", "anger", "strange !~~ /anger/");
like("stranger", "^s.(r).*$", "matches the regex");
done_testing();
}
diff --git a/t/notediag.c b/t/notediag.c
deleted file mode 100644
index d1e50f9..0000000
--- a/t/notediag.c
+++ /dev/null
@@ -1,15 +0,0 @@
-#include "tap.h"
-
-int main () {
- setvbuf(stdout, NULL, _IONBF, 0);
- note("note no new line");
- note("note new line\n");
- note("");
- note(NULL);
- diag("diag no new line");
- diag("diag new line\n");
- diag("");
- diag(NULL);
- return 1;
-}
-
diff --git a/t/simple.c b/t/simple.c
index 7b89254..94df125 100644
--- a/t/simple.c
+++ b/t/simple.c
@@ -1,32 +1,31 @@
#include "tap.h"
int main () {
- setvbuf(stdout, NULL, _IONBF, 0);
plan(24);
ok(1);
ok(1);
ok(1);
ok(0);
ok(1, "foo");
ok(1, "bar");
ok(1, "baz");
ok(1, "quux");
ok(1, "thud");
ok(1, "wombat");
ok(1, "blurgle");
ok(1, "frob");
ok(0, "frobnicate");
ok(1, "eek");
ok(1, "ook");
ok(1, "frodo");
ok(1, "bilbo");
ok(1, "wubble");
ok(1, "flarp");
ok(1, "fnord");
pass();
fail();
pass("good");
fail("bad");
done_testing();
}
diff --git a/t/simple.expected b/t/simple.expected
index 476fe51..3b6a247 100644
--- a/t/simple.expected
+++ b/t/simple.expected
@@ -1,32 +1,32 @@
1..24
ok 1
ok 2
ok 3
not ok 4
-# Failed test at t/simple.c line 9.
+# Failed test at t/simple.c line 8.
ok 5 - foo
ok 6 - bar
ok 7 - baz
ok 8 - quux
ok 9 - thud
ok 10 - wombat
ok 11 - blurgle
ok 12 - frob
not ok 13 - frobnicate
# Failed test 'frobnicate'
-# at t/simple.c line 18.
+# at t/simple.c line 17.
ok 14 - eek
ok 15 - ook
ok 16 - frodo
ok 17 - bilbo
ok 18 - wubble
ok 19 - flarp
ok 20 - fnord
ok 21
not ok 22
-# Failed test at t/simple.c line 27.
+# Failed test at t/simple.c line 26.
ok 23 - good
not ok 24 - bad
# Failed test 'bad'
-# at t/simple.c line 29.
+# at t/simple.c line 28.
# Looks like you failed 4 tests of 24 run.
diff --git a/t/skip.c b/t/skip.c
index 92faca8..159334e 100644
--- a/t/skip.c
+++ b/t/skip.c
@@ -1,24 +1,23 @@
#include "tap.h"
int main () {
- setvbuf(stdout, NULL, _IONBF, 0);
plan(8);
skip(0, 3, "%s cannot fork", "windows");
ok(1, "quux");
ok(1, "thud");
ok(1, "wombat");
end_skip;
skip(1, 1, "need to be on windows");
ok(0, "blurgle");
end_skip;
skip(0, 3);
ok(1, "quux");
ok(1, "thud");
ok(1, "wombat");
end_skip;
skip(1, 1);
ok(0, "blurgle");
end_skip;
done_testing();
}
diff --git a/t/synopsis.c b/t/synopsis.c
index b83b11c..86314d5 100644
--- a/t/synopsis.c
+++ b/t/synopsis.c
@@ -1,13 +1,12 @@
#include "tap.h"
int main () {
- setvbuf(stdout, NULL, _IONBF, 0);
plan(5);
ok(3 == 3);
is("fnord", "eek", "two different strings not that way?");
ok(3 <= 8732, "%d <= %d", 3, 8732);
like("fnord", "f(yes|no)r*[a-f]$");
cmp_ok(3, ">=", 10);
done_testing();
}
diff --git a/t/synopsis.expected b/t/synopsis.expected
index d611258..5b39a01 100644
--- a/t/synopsis.expected
+++ b/t/synopsis.expected
@@ -1,15 +1,15 @@
1..5
ok 1
not ok 2 - two different strings not that way?
# Failed test 'two different strings not that way?'
-# at t/synopsis.c line 7.
+# at t/synopsis.c line 6.
# got: 'fnord'
# expected: 'eek'
ok 3 - 3 <= 8732
ok 4
not ok 5
-# Failed test at t/synopsis.c line 10.
+# Failed test at t/synopsis.c line 9.
# 3
# >=
# 10
# Looks like you failed 2 tests of 5 run.
diff --git a/t/todo.c b/t/todo.c
index 2493667..5d973a9 100644
--- a/t/todo.c
+++ b/t/todo.c
@@ -1,18 +1,17 @@
#include "tap.h"
int main () {
- setvbuf(stdout, NULL, _IONBF, 0);
plan(6);
todo();
ok(0, "foo");
ok(1, "bar");
ok(1, "baz");
end_todo;
todo("im not ready");
ok(0, "quux");
ok(1, "thud");
ok(1, "wombat");
end_todo;
done_testing();
}
diff --git a/t/todo.expected b/t/todo.expected
index 32b5207..8cf8cef 100644
--- a/t/todo.expected
+++ b/t/todo.expected
@@ -1,11 +1,11 @@
1..6
not ok 1 - foo # TODO
# Failed (TODO) test 'foo'
-# at t/todo.c line 7.
+# at t/todo.c line 6.
ok 2 - bar # TODO
ok 3 - baz # TODO
not ok 4 - quux # TODO im not ready
# Failed (TODO) test 'quux'
-# at t/todo.c line 12.
+# at t/todo.c line 11.
ok 5 - thud # TODO im not ready
ok 6 - wombat # TODO im not ready
diff --git a/tap.c b/tap.c
index 2fd3b12..152e39e 100644
--- a/tap.c
+++ b/tap.c
@@ -1,369 +1,354 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the LGPL
*/
#define _DEFAULT_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
if (!str) {
perror("malloc error");
exit(1);
}
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
tap_plan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
- note("SKIP %s\n", why);
+ diag("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
if (!test) {
printf("not ");
}
printf("ok %d", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
- fprintf(stderr, "# Failed ");
+ printf("# Failed ");
if (todo_mesg)
- fprintf(stderr, "(TODO) ");
- fprintf(stderr, "test ");
+ printf("(TODO) ");
+ printf("test ");
if (*name)
- fprintf(stderr, "'%s'\n# ", name);
- fprintf(stderr, "at %s line %d.\n", file, line);
+ printf("'%s'\n# ", name);
+ printf("at %s line %d.\n", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static int
find_mem_diff (const char *a, const char *b, size_t n, size_t *offset) {
size_t i;
if (a == b)
return 0;
if (!a || !b)
return 2;
for (i = 0; i < n; i++) {
if (a[i] != b[i]) {
*offset = i;
return 1;
}
}
return 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;
}
-static void
-vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
+int
+diag (const char *fmt, ...) {
+ va_list args;
char *mesg, *line;
int i;
+ va_start(args, fmt);
if (!fmt)
- return;
+ return 0;
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
- fprintf(fh, "# %s\n", line);
+ printf("# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
- return;
-}
-
-int
-diag (const char *fmt, ...) {
- va_list args;
- va_start(args, fmt);
- vdiag_to_fh(stderr, fmt, args);
- va_end(args);
- return 0;
-}
-
-int
-note (const char *fmt, ...) {
- va_list args;
- va_start(args, fmt);
- vdiag_to_fh(stdout, fmt, args);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 2;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
retval = 1;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
tap_skip (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
- note("skip %s\n", why);
+ diag("skip %s\n", why);
}
free(why);
}
void
tap_todo (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
tap_end_todo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
#if defined __APPLE__ || defined BSD
#define MAP_ANONYMOUS MAP_ANON
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros. */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
diff --git a/tap.h b/tap.h
index 605765c..8269e7e 100644
--- a/tap.h
+++ b/tap.h
@@ -1,116 +1,115 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the LGPL
*/
#ifndef __TAP_H__
#define __TAP_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifndef va_copy
#ifdef __va_copy
#define va_copy __va_copy
#else
#define va_copy(d, s) ((d) = (s))
#endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args);
int ok_at_loc (const char *file, int line, int test, const char *fmt,
...);
int is_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int isnt_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int cmp_ok_at_loc (const char *file, int line, int a, const char *op,
int b, const char *fmt, ...);
int cmp_mem_at_loc (const char *file, int line, const void *got,
const void *expected, size_t n, const char *fmt, ...);
int bail_out (int ignore, const char *fmt, ...);
void tap_plan (int tests, const char *fmt, ...);
int diag (const char *fmt, ...);
-int note (const char *fmt, ...);
int exit_status (void);
void tap_skip (int n, const char *fmt, ...);
void tap_todo (int ignore, const char *fmt, ...);
void tap_end_todo (void);
#define NO_PLAN -1
#define SKIP_ALL -2
#define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_mem(...) cmp_mem_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL);
#define plan(...) tap_plan(__VA_ARGS__, NULL)
#define done_testing() return exit_status()
#define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
#define pass(...) ok(1, "" __VA_ARGS__)
#define fail(...) ok(0, "" __VA_ARGS__)
#define skip(test, ...) do {if (test) {tap_skip(__VA_ARGS__, NULL); break;}
#define end_skip } while (0)
#define todo(...) tap_todo(0, "" __VA_ARGS__, NULL)
#define end_todo tap_end_todo()
#define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
#define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
#ifdef _WIN32
#define like(...) tap_skip(1, "like is not implemented on Windows")
#define unlike tap_skip(1, "unlike is not implemented on Windows")
#define dies_ok_common(...) \
tap_skip(1, "Death detection is not supported on Windows")
#else
#define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
#define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
int like_at_loc (int for_match, const char *file, int line,
const char *got, const char *expected,
const char *fmt, ...);
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int tap_test_died (int status);
#define dies_ok_common(for_death, code, ...) \
do { \
int cpid; \
int it_died; \
tap_test_died(1); \
cpid = fork(); \
switch (cpid) { \
case -1: \
perror("fork error"); \
exit(1); \
case 0: \
close(1); \
close(2); \
code \
tap_test_died(0); \
exit(0); \
} \
if (waitpid(cpid, NULL, 0) < 0) { \
perror("waitpid error"); \
exit(1); \
} \
it_died = tap_test_died(0); \
if (!it_died) \
{code} \
ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \
} while (0)
#endif
#ifdef __cplusplus
}
#endif
#endif
|
zorgnax/libtap
|
72a57250e3f55e67ce4749771d251db58532ae0c
|
Rely on prove (or another tap consumer) to provide color results
|
diff --git a/Makefile b/Makefile
index ac843df..1bec192 100644
--- a/Makefile
+++ b/Makefile
@@ -1,76 +1,72 @@
CFLAGS = -g -Wall -I. -fPIC
CC = gcc
PREFIX = $(DESTDIR)/usr/local
TESTS = $(patsubst %.c, %, $(wildcard t/*.c))
ifdef ANSI
# -D_BSD_SOURCE for MAP_ANONYMOUS
CFLAGS += -ansi -D_BSD_SOURCE
LDLIBS += -lbsd-compat
endif
-ifdef TAP_COLOR_OUTPUT
- CFLAGS += -DTAP_COLOR_OUTPUT
-endif
-
%:
$(CC) $(LDFLAGS) $(TARGET_ARCH) $(filter %.o %.a %.so, $^) $(LDLIBS) -o $@
%.o:
$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $(filter %.c, $^) $(LDLIBS) -o $@
%.a:
$(AR) rcs $@ $(filter %.o, $^)
%.so:
$(CC) -shared $(LDFLAGS) $(TARGET_ARCH) $(filter %.o, $^) $(LDLIBS) -o $@
all: libtap.a libtap.so tap.pc tests
tap.pc:
@echo generating tap.pc
@echo 'prefix='$(PREFIX) > tap.pc
@echo 'exec_prefix=$${prefix}' >> tap.pc
@echo 'libdir=$${prefix}/lib' >> tap.pc
@echo 'includedir=$${prefix}/include' >> tap.pc
@echo '' >> tap.pc
@echo 'Name: libtap' >> tap.pc
@echo 'Description: Write tests in C' >> tap.pc
@echo 'Version: 0.1.0' >> tap.pc
@echo 'URL: https://github.com/zorgnax/libtap' >> tap.pc
@echo 'Libs: -L$${libdir} -ltap' >> tap.pc
@echo 'Cflags: -I$${includedir}' >> tap.pc
libtap.a: tap.o
libtap.so: tap.o
tap.o: tap.c tap.h
tests: $(TESTS)
$(TESTS): %: %.o libtap.a
$(patsubst %, %.o, $(TESTS)): %.o: %.c tap.h
clean:
rm -rf *.o t/*.o tap.pc libtap.a libtap.so $(TESTS)
install: libtap.a tap.h libtap.so tap.pc
mkdir -p $(PREFIX)/lib $(PREFIX)/include $(PREFIX)/lib/pkgconfig
install -c libtap.a $(PREFIX)/lib
install -c libtap.so $(PREFIX)/lib
install -c tap.pc $(PREFIX)/lib/pkgconfig
install -c tap.h $(PREFIX)/include
uninstall:
rm $(PREFIX)/lib/libtap.a $(PREFIX)/lib/libtap.so $(PREFIX)/include/tap.h
dist:
rm libtap.zip
zip -r libtap *
check test: all
./t/test
.PHONY: all clean install uninstall dist check test tests
diff --git a/tap.c b/tap.c
index c68beff..2fd3b12 100644
--- a/tap.c
+++ b/tap.c
@@ -1,371 +1,369 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the LGPL
*/
#define _DEFAULT_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
if (!str) {
perror("malloc error");
exit(1);
}
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
tap_plan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
note("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
if (!test) {
- printf(AC_BAD("not ok") " %d", ++current_test);
- }
- else {
- printf(AC_OK("ok") " %d", ++current_test);
+ printf("not ");
}
+ printf("ok %d", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
fprintf(stderr, "# Failed ");
if (todo_mesg)
fprintf(stderr, "(TODO) ");
fprintf(stderr, "test ");
if (*name)
fprintf(stderr, "'%s'\n# ", name);
fprintf(stderr, "at %s line %d.\n", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static int
find_mem_diff (const char *a, const char *b, size_t n, size_t *offset) {
size_t i;
if (a == b)
return 0;
if (!a || !b)
return 2;
for (i = 0; i < n; i++) {
if (a[i] != b[i]) {
*offset = i;
return 1;
}
}
return 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;
}
static void
vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
char *mesg, *line;
int i;
if (!fmt)
return;
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
fprintf(fh, "# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
return;
}
int
diag (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stderr, fmt, args);
va_end(args);
return 0;
}
int
note (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stdout, fmt, args);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 2;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
retval = 1;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
tap_skip (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
note("skip %s\n", why);
}
free(why);
}
void
tap_todo (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
tap_end_todo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
#if defined __APPLE__ || defined BSD
#define MAP_ANONYMOUS MAP_ANON
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros. */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
diff --git a/tap.h b/tap.h
index 2c3c84c..605765c 100644
--- a/tap.h
+++ b/tap.h
@@ -1,133 +1,116 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the LGPL
*/
#ifndef __TAP_H__
#define __TAP_H__
-#ifdef TAP_COLOR_OUTPUT
-#define AC_RED "\x1b[31m"
-#define AC_GREEN "\x1b[32m"
-#define AC_YELLOW "\x1b[33m"
-#define AC_BLUE "\x1b[34m"
-#define AC_MAGENTA "\x1b[35m"
-#define AC_CYAN "\x1b[36m"
-#define AC_RESET "\x1b[0m"
-
-#define AC_CLR(color, text) AC_##color text AC_RESET
-#define AC_OK(text) AC_CLR(GREEN, text)
-#define AC_BAD(text) AC_CLR(RED, text)
-#else
-#define AC_OK(text) text
-#define AC_BAD(text) text
-#endif
-
#ifdef __cplusplus
extern "C" {
#endif
#ifndef va_copy
#ifdef __va_copy
#define va_copy __va_copy
#else
#define va_copy(d, s) ((d) = (s))
#endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args);
int ok_at_loc (const char *file, int line, int test, const char *fmt,
...);
int is_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int isnt_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int cmp_ok_at_loc (const char *file, int line, int a, const char *op,
int b, const char *fmt, ...);
int cmp_mem_at_loc (const char *file, int line, const void *got,
const void *expected, size_t n, const char *fmt, ...);
int bail_out (int ignore, const char *fmt, ...);
void tap_plan (int tests, const char *fmt, ...);
int diag (const char *fmt, ...);
int note (const char *fmt, ...);
int exit_status (void);
void tap_skip (int n, const char *fmt, ...);
void tap_todo (int ignore, const char *fmt, ...);
void tap_end_todo (void);
#define NO_PLAN -1
#define SKIP_ALL -2
#define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_mem(...) cmp_mem_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL);
#define plan(...) tap_plan(__VA_ARGS__, NULL)
#define done_testing() return exit_status()
#define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
#define pass(...) ok(1, "" __VA_ARGS__)
#define fail(...) ok(0, "" __VA_ARGS__)
#define skip(test, ...) do {if (test) {tap_skip(__VA_ARGS__, NULL); break;}
#define end_skip } while (0)
#define todo(...) tap_todo(0, "" __VA_ARGS__, NULL)
#define end_todo tap_end_todo()
#define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
#define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
#ifdef _WIN32
#define like(...) tap_skip(1, "like is not implemented on Windows")
#define unlike tap_skip(1, "unlike is not implemented on Windows")
#define dies_ok_common(...) \
tap_skip(1, "Death detection is not supported on Windows")
#else
#define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
#define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
int like_at_loc (int for_match, const char *file, int line,
const char *got, const char *expected,
const char *fmt, ...);
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int tap_test_died (int status);
#define dies_ok_common(for_death, code, ...) \
do { \
int cpid; \
int it_died; \
tap_test_died(1); \
cpid = fork(); \
switch (cpid) { \
case -1: \
perror("fork error"); \
exit(1); \
case 0: \
close(1); \
close(2); \
code \
tap_test_died(0); \
exit(0); \
} \
if (waitpid(cpid, NULL, 0) < 0) { \
perror("waitpid error"); \
exit(1); \
} \
it_died = tap_test_died(0); \
if (!it_died) \
{code} \
ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \
} while (0)
#endif
#ifdef __cplusplus
}
#endif
#endif
|
zorgnax/libtap
|
8e03f5ddcfa39b159be1f171fbef3db8563d301a
|
Remove the extra whitespace
|
diff --git a/tap.c b/tap.c
index bfb6cbd..c68beff 100644
--- a/tap.c
+++ b/tap.c
@@ -1,371 +1,371 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the LGPL
*/
#define _DEFAULT_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
if (!str) {
perror("malloc error");
exit(1);
}
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
tap_plan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
note("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
if (!test) {
- printf(AC_BAD("not ok") " %d", ++current_test);
+ printf(AC_BAD("not ok") " %d", ++current_test);
}
else {
- printf(AC_OK("ok") " %d", ++current_test);
+ printf(AC_OK("ok") " %d", ++current_test);
}
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
fprintf(stderr, "# Failed ");
if (todo_mesg)
fprintf(stderr, "(TODO) ");
fprintf(stderr, "test ");
if (*name)
fprintf(stderr, "'%s'\n# ", name);
fprintf(stderr, "at %s line %d.\n", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static int
find_mem_diff (const char *a, const char *b, size_t n, size_t *offset) {
size_t i;
if (a == b)
return 0;
if (!a || !b)
return 2;
for (i = 0; i < n; i++) {
if (a[i] != b[i]) {
*offset = i;
return 1;
}
}
return 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;
}
static void
vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
char *mesg, *line;
int i;
if (!fmt)
return;
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
fprintf(fh, "# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
return;
}
int
diag (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stderr, fmt, args);
va_end(args);
return 0;
}
int
note (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stdout, fmt, args);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 2;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
retval = 1;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
tap_skip (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
note("skip %s\n", why);
}
free(why);
}
void
tap_todo (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
tap_end_todo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
#if defined __APPLE__ || defined BSD
#define MAP_ANONYMOUS MAP_ANON
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros. */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
|
zorgnax/libtap
|
50c89465fcbc79d955180fd50fb4901274a89070
|
Make color optional
|
diff --git a/Makefile b/Makefile
index 2ab04a5..0903c99 100644
--- a/Makefile
+++ b/Makefile
@@ -1,73 +1,76 @@
CFLAGS = -g -Wall -I. -fPIC
CC = gcc
PREFIX = $(DESTDIR)/usr/local
TESTS = $(patsubst %.c, %, $(wildcard t/*.c))
ifdef ANSI
# -D_BSD_SOURCE for MAP_ANONYMOUS
CFLAGS += -ansi -D_BSD_SOURCE
LDLIBS += -lbsd-compat
endif
+ifdef TAP_COLOR_OUTPUT
+ CFLAGS += -DTAP_COLOR_OUTPUT
+endif
+
%:
$(CC) $(LDFLAGS) $(TARGET_ARCH) $(filter %.o %.a %.so, $^) $(LDLIBS) -o $@
%.o:
$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $(filter %.c, $^) $(LDLIBS) -o $@
%.a:
$(AR) rcs $@ $(filter %.o, $^)
%.so:
$(CC) -shared $(LDFLAGS) $(TARGET_ARCH) $(filter %.o, $^) $(LDLIBS) -o $@
all: libtap.a libtap.so tap.pc tests
tap.pc:
@echo generating tap.pc
@echo 'prefix='$(PREFIX) > tap.pc
@echo 'exec_prefix=$${prefix}' >> tap.pc
@echo 'libdir=$${prefix}/lib' >> tap.pc
@echo 'includedir=$${prefix}/include' >> tap.pc
@echo '' >> tap.pc
@echo 'Name: libtap' >> tap.pc
@echo 'Description: Write tests in C' >> tap.pc
@echo 'Version: 0.1.0' >> tap.pc
@echo 'URL: https://github.com/zorgnax/libtap' >> tap.pc
@echo 'Libs: -L$${libdir} -ltap' >> tap.pc
@echo 'Cflags: -I$${includedir}' >> tap.pc
libtap.a: tap.o
libtap.so: tap.o
tap.o: tap.c tap.h
tests: $(TESTS)
$(TESTS): %: %.o libtap.a
$(patsubst %, %.o, $(TESTS)): %.o: %.c tap.h
clean:
rm -rf *.o t/*.o tap.pc libtap.a libtap.so $(TESTS)
install: libtap.a tap.h libtap.so tap.pc
mkdir -p $(PREFIX)/lib $(PREFIX)/include $(PREFIX)/lib/pkgconfig
install -c libtap.a $(PREFIX)/lib
install -c libtap.so $(PREFIX)/lib
install -c tap.pc $(PREFIX)/lib/pkgconfig
install -c tap.h $(PREFIX)/include
uninstall:
rm $(PREFIX)/lib/libtap.a $(PREFIX)/lib/libtap.so $(PREFIX)/include/tap.h
dist:
rm libtap.zip
zip -r libtap *
check test: all
perl t/test.t
.PHONY: all clean install uninstall dist check test tests
-
diff --git a/tap.h b/tap.h
index 58b773c..2c3c84c 100644
--- a/tap.h
+++ b/tap.h
@@ -1,129 +1,133 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the LGPL
*/
#ifndef __TAP_H__
#define __TAP_H__
+#ifdef TAP_COLOR_OUTPUT
#define AC_RED "\x1b[31m"
#define AC_GREEN "\x1b[32m"
#define AC_YELLOW "\x1b[33m"
#define AC_BLUE "\x1b[34m"
#define AC_MAGENTA "\x1b[35m"
#define AC_CYAN "\x1b[36m"
#define AC_RESET "\x1b[0m"
#define AC_CLR(color, text) AC_##color text AC_RESET
#define AC_OK(text) AC_CLR(GREEN, text)
#define AC_BAD(text) AC_CLR(RED, text)
+#else
+#define AC_OK(text) text
+#define AC_BAD(text) text
+#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifndef va_copy
#ifdef __va_copy
#define va_copy __va_copy
#else
#define va_copy(d, s) ((d) = (s))
#endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args);
int ok_at_loc (const char *file, int line, int test, const char *fmt,
...);
int is_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int isnt_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int cmp_ok_at_loc (const char *file, int line, int a, const char *op,
int b, const char *fmt, ...);
int cmp_mem_at_loc (const char *file, int line, const void *got,
const void *expected, size_t n, const char *fmt, ...);
int bail_out (int ignore, const char *fmt, ...);
void tap_plan (int tests, const char *fmt, ...);
int diag (const char *fmt, ...);
int note (const char *fmt, ...);
int exit_status (void);
void tap_skip (int n, const char *fmt, ...);
void tap_todo (int ignore, const char *fmt, ...);
void tap_end_todo (void);
#define NO_PLAN -1
#define SKIP_ALL -2
#define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_mem(...) cmp_mem_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL);
#define plan(...) tap_plan(__VA_ARGS__, NULL)
#define done_testing() return exit_status()
#define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
#define pass(...) ok(1, "" __VA_ARGS__)
#define fail(...) ok(0, "" __VA_ARGS__)
#define skip(test, ...) do {if (test) {tap_skip(__VA_ARGS__, NULL); break;}
#define end_skip } while (0)
#define todo(...) tap_todo(0, "" __VA_ARGS__, NULL)
#define end_todo tap_end_todo()
#define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
#define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
#ifdef _WIN32
#define like(...) tap_skip(1, "like is not implemented on Windows")
#define unlike tap_skip(1, "unlike is not implemented on Windows")
#define dies_ok_common(...) \
tap_skip(1, "Death detection is not supported on Windows")
#else
#define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
#define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
int like_at_loc (int for_match, const char *file, int line,
const char *got, const char *expected,
const char *fmt, ...);
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int tap_test_died (int status);
#define dies_ok_common(for_death, code, ...) \
do { \
int cpid; \
int it_died; \
tap_test_died(1); \
cpid = fork(); \
switch (cpid) { \
case -1: \
perror("fork error"); \
exit(1); \
case 0: \
close(1); \
close(2); \
code \
tap_test_died(0); \
exit(0); \
} \
if (waitpid(cpid, NULL, 0) < 0) { \
perror("waitpid error"); \
exit(1); \
} \
it_died = tap_test_died(0); \
if (!it_died) \
{code} \
ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \
} while (0)
#endif
#ifdef __cplusplus
}
#endif
#endif
-
|
zorgnax/libtap
|
b78ba661a40b48dc1094382ee8b270da9243d414
|
Add color text
|
diff --git a/tap.c b/tap.c
index b4f306d..bfb6cbd 100644
--- a/tap.c
+++ b/tap.c
@@ -1,369 +1,371 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the LGPL
*/
#define _DEFAULT_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
if (!str) {
perror("malloc error");
exit(1);
}
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
tap_plan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
note("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
- if (!test)
- printf("not ");
- printf("ok %d", ++current_test);
+ if (!test) {
+ printf(AC_BAD("not ok") " %d", ++current_test);
+ }
+ else {
+ printf(AC_OK("ok") " %d", ++current_test);
+ }
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
fprintf(stderr, "# Failed ");
if (todo_mesg)
fprintf(stderr, "(TODO) ");
fprintf(stderr, "test ");
if (*name)
fprintf(stderr, "'%s'\n# ", name);
fprintf(stderr, "at %s line %d.\n", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static int
find_mem_diff (const char *a, const char *b, size_t n, size_t *offset) {
size_t i;
if (a == b)
return 0;
if (!a || !b)
return 2;
for (i = 0; i < n; i++) {
if (a[i] != b[i]) {
*offset = i;
return 1;
}
}
return 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;
}
static void
vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
char *mesg, *line;
int i;
if (!fmt)
return;
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
fprintf(fh, "# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
return;
}
int
diag (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stderr, fmt, args);
va_end(args);
return 0;
}
int
note (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stdout, fmt, args);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 2;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
retval = 1;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
tap_skip (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
note("skip %s\n", why);
}
free(why);
}
void
tap_todo (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
tap_end_todo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
#if defined __APPLE__ || defined BSD
#define MAP_ANONYMOUS MAP_ANON
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros. */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
-
diff --git a/tap.h b/tap.h
index 595d03b..58b773c 100644
--- a/tap.h
+++ b/tap.h
@@ -1,117 +1,129 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the LGPL
*/
#ifndef __TAP_H__
#define __TAP_H__
+#define AC_RED "\x1b[31m"
+#define AC_GREEN "\x1b[32m"
+#define AC_YELLOW "\x1b[33m"
+#define AC_BLUE "\x1b[34m"
+#define AC_MAGENTA "\x1b[35m"
+#define AC_CYAN "\x1b[36m"
+#define AC_RESET "\x1b[0m"
+
+#define AC_CLR(color, text) AC_##color text AC_RESET
+#define AC_OK(text) AC_CLR(GREEN, text)
+#define AC_BAD(text) AC_CLR(RED, text)
+
#ifdef __cplusplus
extern "C" {
#endif
#ifndef va_copy
#ifdef __va_copy
#define va_copy __va_copy
#else
#define va_copy(d, s) ((d) = (s))
#endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args);
int ok_at_loc (const char *file, int line, int test, const char *fmt,
...);
int is_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int isnt_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int cmp_ok_at_loc (const char *file, int line, int a, const char *op,
int b, const char *fmt, ...);
int cmp_mem_at_loc (const char *file, int line, const void *got,
const void *expected, size_t n, const char *fmt, ...);
int bail_out (int ignore, const char *fmt, ...);
void tap_plan (int tests, const char *fmt, ...);
int diag (const char *fmt, ...);
int note (const char *fmt, ...);
int exit_status (void);
void tap_skip (int n, const char *fmt, ...);
void tap_todo (int ignore, const char *fmt, ...);
void tap_end_todo (void);
#define NO_PLAN -1
#define SKIP_ALL -2
#define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_mem(...) cmp_mem_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL);
#define plan(...) tap_plan(__VA_ARGS__, NULL)
#define done_testing() return exit_status()
#define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
#define pass(...) ok(1, "" __VA_ARGS__)
#define fail(...) ok(0, "" __VA_ARGS__)
#define skip(test, ...) do {if (test) {tap_skip(__VA_ARGS__, NULL); break;}
#define end_skip } while (0)
#define todo(...) tap_todo(0, "" __VA_ARGS__, NULL)
#define end_todo tap_end_todo()
#define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
#define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
#ifdef _WIN32
#define like(...) tap_skip(1, "like is not implemented on Windows")
#define unlike tap_skip(1, "unlike is not implemented on Windows")
#define dies_ok_common(...) \
tap_skip(1, "Death detection is not supported on Windows")
#else
#define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
#define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
int like_at_loc (int for_match, const char *file, int line,
const char *got, const char *expected,
const char *fmt, ...);
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int tap_test_died (int status);
#define dies_ok_common(for_death, code, ...) \
do { \
int cpid; \
int it_died; \
tap_test_died(1); \
cpid = fork(); \
switch (cpid) { \
case -1: \
perror("fork error"); \
exit(1); \
case 0: \
close(1); \
close(2); \
code \
tap_test_died(0); \
exit(0); \
} \
if (waitpid(cpid, NULL, 0) < 0) { \
perror("waitpid error"); \
exit(1); \
} \
it_died = tap_test_died(0); \
if (!it_died) \
{code} \
ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \
} while (0)
#endif
#ifdef __cplusplus
}
#endif
#endif
|
zorgnax/libtap
|
6317aa3e2c6b0d98ee365078fbef2e299ec4930c
|
Move tap.pc section down so all section stays the default
|
diff --git a/Makefile b/Makefile
index f038714..2ab04a5 100644
--- a/Makefile
+++ b/Makefile
@@ -1,72 +1,73 @@
CFLAGS = -g -Wall -I. -fPIC
CC = gcc
PREFIX = $(DESTDIR)/usr/local
TESTS = $(patsubst %.c, %, $(wildcard t/*.c))
ifdef ANSI
# -D_BSD_SOURCE for MAP_ANONYMOUS
CFLAGS += -ansi -D_BSD_SOURCE
LDLIBS += -lbsd-compat
endif
%:
$(CC) $(LDFLAGS) $(TARGET_ARCH) $(filter %.o %.a %.so, $^) $(LDLIBS) -o $@
%.o:
$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $(filter %.c, $^) $(LDLIBS) -o $@
%.a:
$(AR) rcs $@ $(filter %.o, $^)
%.so:
$(CC) -shared $(LDFLAGS) $(TARGET_ARCH) $(filter %.o, $^) $(LDLIBS) -o $@
+all: libtap.a libtap.so tap.pc tests
+
tap.pc:
+ @echo generating tap.pc
@echo 'prefix='$(PREFIX) > tap.pc
@echo 'exec_prefix=$${prefix}' >> tap.pc
@echo 'libdir=$${prefix}/lib' >> tap.pc
@echo 'includedir=$${prefix}/include' >> tap.pc
@echo '' >> tap.pc
@echo 'Name: libtap' >> tap.pc
@echo 'Description: Write tests in C' >> tap.pc
@echo 'Version: 0.1.0' >> tap.pc
@echo 'URL: https://github.com/zorgnax/libtap' >> tap.pc
@echo 'Libs: -L$${libdir} -ltap' >> tap.pc
@echo 'Cflags: -I$${includedir}' >> tap.pc
-all: libtap.a libtap.so tap.pc tests
-
libtap.a: tap.o
libtap.so: tap.o
tap.o: tap.c tap.h
tests: $(TESTS)
$(TESTS): %: %.o libtap.a
$(patsubst %, %.o, $(TESTS)): %.o: %.c tap.h
clean:
rm -rf *.o t/*.o tap.pc libtap.a libtap.so $(TESTS)
install: libtap.a tap.h libtap.so tap.pc
mkdir -p $(PREFIX)/lib $(PREFIX)/include $(PREFIX)/lib/pkgconfig
install -c libtap.a $(PREFIX)/lib
install -c libtap.so $(PREFIX)/lib
install -c tap.pc $(PREFIX)/lib/pkgconfig
install -c tap.h $(PREFIX)/include
uninstall:
rm $(PREFIX)/lib/libtap.a $(PREFIX)/lib/libtap.so $(PREFIX)/include/tap.h
dist:
rm libtap.zip
zip -r libtap *
check test: all
perl t/test.t
.PHONY: all clean install uninstall dist check test tests
|
zorgnax/libtap
|
6c87a037f2fa8361dec9f2968fb4168bac1d0cf6
|
Adding pkgconfig file
|
diff --git a/.gitignore b/.gitignore
index 778a470..2c95d04 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,12 +1,13 @@
/t/*
!/t/*.*
/t/*.exe
/t/*.got
*.a
*.lo
*.o
*.so
+*.pc
usr/
*.sw?
/.deps
/.dirstamp
diff --git a/Makefile b/Makefile
index 0da18e7..f038714 100644
--- a/Makefile
+++ b/Makefile
@@ -1,58 +1,72 @@
CFLAGS = -g -Wall -I. -fPIC
CC = gcc
PREFIX = $(DESTDIR)/usr/local
TESTS = $(patsubst %.c, %, $(wildcard t/*.c))
ifdef ANSI
# -D_BSD_SOURCE for MAP_ANONYMOUS
CFLAGS += -ansi -D_BSD_SOURCE
LDLIBS += -lbsd-compat
endif
%:
$(CC) $(LDFLAGS) $(TARGET_ARCH) $(filter %.o %.a %.so, $^) $(LDLIBS) -o $@
%.o:
$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $(filter %.c, $^) $(LDLIBS) -o $@
%.a:
$(AR) rcs $@ $(filter %.o, $^)
%.so:
$(CC) -shared $(LDFLAGS) $(TARGET_ARCH) $(filter %.o, $^) $(LDLIBS) -o $@
-all: libtap.a libtap.so tests
+tap.pc:
+ @echo 'prefix='$(PREFIX) > tap.pc
+ @echo 'exec_prefix=$${prefix}' >> tap.pc
+ @echo 'libdir=$${prefix}/lib' >> tap.pc
+ @echo 'includedir=$${prefix}/include' >> tap.pc
+ @echo '' >> tap.pc
+ @echo 'Name: libtap' >> tap.pc
+ @echo 'Description: Write tests in C' >> tap.pc
+ @echo 'Version: 0.1.0' >> tap.pc
+ @echo 'URL: https://github.com/zorgnax/libtap' >> tap.pc
+ @echo 'Libs: -L$${libdir} -ltap' >> tap.pc
+ @echo 'Cflags: -I$${includedir}' >> tap.pc
+
+all: libtap.a libtap.so tap.pc tests
libtap.a: tap.o
libtap.so: tap.o
tap.o: tap.c tap.h
tests: $(TESTS)
$(TESTS): %: %.o libtap.a
$(patsubst %, %.o, $(TESTS)): %.o: %.c tap.h
clean:
- rm -rf *.o t/*.o libtap.a libtap.so $(TESTS)
+ rm -rf *.o t/*.o tap.pc libtap.a libtap.so $(TESTS)
-install: libtap.a tap.h libtap.so
- mkdir -p $(PREFIX)/lib $(PREFIX)/include
+install: libtap.a tap.h libtap.so tap.pc
+ mkdir -p $(PREFIX)/lib $(PREFIX)/include $(PREFIX)/lib/pkgconfig
install -c libtap.a $(PREFIX)/lib
install -c libtap.so $(PREFIX)/lib
+ install -c tap.pc $(PREFIX)/lib/pkgconfig
install -c tap.h $(PREFIX)/include
uninstall:
rm $(PREFIX)/lib/libtap.a $(PREFIX)/lib/libtap.so $(PREFIX)/include/tap.h
dist:
rm libtap.zip
zip -r libtap *
check test: all
perl t/test.t
.PHONY: all clean install uninstall dist check test tests
|
zorgnax/libtap
|
a5076cea862a535c93003d50fb32e430b15c92dc
|
License under LGPL
|
diff --git a/COPYING b/COPYING
index d159169..65c5ca8 100644
--- a/COPYING
+++ b/COPYING
@@ -1,339 +1,165 @@
- GNU GENERAL PUBLIC LICENSE
- Version 2, June 1991
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users. This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it. (Some other Free Software Foundation software is covered by
-the GNU Lesser General Public License instead.) You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
- To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must show them these terms so they know their
-rights.
-
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
- 1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
- 2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) You must cause the modified files to carry prominent notices
- stating that you changed the files and the date of any change.
-
- b) You must cause any work that you distribute or publish, that in
- whole or in part contains or is derived from the Program or any
- part thereof, to be licensed as a whole at no charge to all third
- parties under the terms of this License.
-
- c) If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the most ordinary way, to print or display an
- announcement including an appropriate copyright notice and a
- notice that there is no warranty (or else, saying that you provide
- a warranty) and that users may redistribute the program under
- these conditions, and telling the user how to view a copy of this
- License. (Exception: if the Program itself is interactive but
- does not normally print such an announcement, your work based on
- the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
- a) Accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of Sections
- 1 and 2 above on a medium customarily used for software interchange; or,
-
- b) Accompany it with a written offer, valid for at least three
- years, to give any third party, for a charge no more than your
- cost of physically performing source distribution, a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Sections 1 and 2 above on a medium
- customarily used for software interchange; or,
-
- c) Accompany it with the information you received as to the offer
- to distribute corresponding source code. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form with such
- an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
- 5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
- 6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
- 7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
-
- 9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
- 10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
- NO WARRANTY
-
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
- <one line to give the program's name and a brief idea of what it does.>
- Copyright (C) <year> <name of author>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
- Gnomovision version 69, Copyright (C) year name of author
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
- <signature of Ty Coon>, 1 April 1989
- Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs. If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library. If this is what you want to do, use the GNU Lesser General
-Public License instead of this License.
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
diff --git a/tap.c b/tap.c
index 37f509e..b4f306d 100644
--- a/tap.c
+++ b/tap.c
@@ -1,369 +1,369 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
-This file is licensed under the GPLv2 or any later version
+This file is licensed under the LGPL
*/
#define _DEFAULT_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
if (!str) {
perror("malloc error");
exit(1);
}
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
tap_plan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
note("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
if (!test)
printf("not ");
printf("ok %d", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
fprintf(stderr, "# Failed ");
if (todo_mesg)
fprintf(stderr, "(TODO) ");
fprintf(stderr, "test ");
if (*name)
fprintf(stderr, "'%s'\n# ", name);
fprintf(stderr, "at %s line %d.\n", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static int
find_mem_diff (const char *a, const char *b, size_t n, size_t *offset) {
size_t i;
if (a == b)
return 0;
if (!a || !b)
return 2;
for (i = 0; i < n; i++) {
if (a[i] != b[i]) {
*offset = i;
return 1;
}
}
return 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;
}
static void
vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
char *mesg, *line;
int i;
if (!fmt)
return;
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
fprintf(fh, "# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
return;
}
int
diag (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stderr, fmt, args);
va_end(args);
return 0;
}
int
note (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stdout, fmt, args);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 2;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
retval = 1;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
tap_skip (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
note("skip %s\n", why);
}
free(why);
}
void
tap_todo (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
tap_end_todo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
#if defined __APPLE__ || defined BSD
#define MAP_ANONYMOUS MAP_ANON
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros. */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
diff --git a/tap.h b/tap.h
index 302e6d8..595d03b 100644
--- a/tap.h
+++ b/tap.h
@@ -1,117 +1,117 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
-This file is licensed under the GPLv2 or any later version
+This file is licensed under the LGPL
*/
#ifndef __TAP_H__
#define __TAP_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifndef va_copy
#ifdef __va_copy
#define va_copy __va_copy
#else
#define va_copy(d, s) ((d) = (s))
#endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args);
int ok_at_loc (const char *file, int line, int test, const char *fmt,
...);
int is_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int isnt_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int cmp_ok_at_loc (const char *file, int line, int a, const char *op,
int b, const char *fmt, ...);
int cmp_mem_at_loc (const char *file, int line, const void *got,
const void *expected, size_t n, const char *fmt, ...);
int bail_out (int ignore, const char *fmt, ...);
void tap_plan (int tests, const char *fmt, ...);
int diag (const char *fmt, ...);
int note (const char *fmt, ...);
int exit_status (void);
void tap_skip (int n, const char *fmt, ...);
void tap_todo (int ignore, const char *fmt, ...);
void tap_end_todo (void);
#define NO_PLAN -1
#define SKIP_ALL -2
#define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_mem(...) cmp_mem_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL);
#define plan(...) tap_plan(__VA_ARGS__, NULL)
#define done_testing() return exit_status()
#define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
#define pass(...) ok(1, "" __VA_ARGS__)
#define fail(...) ok(0, "" __VA_ARGS__)
#define skip(test, ...) do {if (test) {tap_skip(__VA_ARGS__, NULL); break;}
#define end_skip } while (0)
#define todo(...) tap_todo(0, "" __VA_ARGS__, NULL)
#define end_todo tap_end_todo()
#define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
#define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
#ifdef _WIN32
#define like(...) tap_skip(1, "like is not implemented on Windows")
#define unlike tap_skip(1, "unlike is not implemented on Windows")
#define dies_ok_common(...) \
tap_skip(1, "Death detection is not supported on Windows")
#else
#define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
#define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
int like_at_loc (int for_match, const char *file, int line,
const char *got, const char *expected,
const char *fmt, ...);
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int tap_test_died (int status);
#define dies_ok_common(for_death, code, ...) \
do { \
int cpid; \
int it_died; \
tap_test_died(1); \
cpid = fork(); \
switch (cpid) { \
case -1: \
perror("fork error"); \
exit(1); \
case 0: \
close(1); \
close(2); \
code \
tap_test_died(0); \
exit(0); \
} \
if (waitpid(cpid, NULL, 0) < 0) { \
perror("waitpid error"); \
exit(1); \
} \
it_died = tap_test_died(0); \
if (!it_died) \
{code} \
ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \
} while (0)
#endif
#ifdef __cplusplus
}
#endif
#endif
|
zorgnax/libtap
|
c7b93973fd09532ad71e94f486b10131b0ad1052
|
done_testing to return 0, 1, or 2 not the number of tests failed
|
diff --git a/README.md b/README.md
index ea47173..0a60767 100644
--- a/README.md
+++ b/README.md
@@ -1,274 +1,273 @@
NAME
====
libtap - Write tests in C
SYNOPSIS
========
#include <tap.h>
int main () {
plan(5);
ok(3 == 3);
is("fnord", "eek", "two different strings not that way?");
ok(3 <= 8732, "%d <= %d", 3, 8732);
like("fnord", "f(yes|no)r*[a-f]$");
cmp_ok(3, ">=", 10);
done_testing();
}
results in:
1..5
ok 1
not ok 2 - two different strings not that way?
# Failed test 'two different strings not that way?'
# at t/synopsis.c line 7.
# got: 'fnord'
# expected: 'eek'
ok 3 - 3 <= 8732
ok 4
not ok 5
# Failed test at t/synopsis.c line 10.
# 3
# >=
# 10
# Looks like you failed 2 tests of 5 run.
DESCRIPTION
===========
tap is an easy to read and easy to write way of creating tests for your
software. This library creates functions that can be used to generate it for
your C programs. It is mostly based on the Test::More Perl module.
INSTALL
=======
On **Unix** systems:
$ make
$ make install
For more detailed installation instructions (eg, for **Windows**), see `INSTALL`.
FUNCTIONS
=========
- plan(tests)
- plan(NO_PLAN)
- plan(SKIP_ALL);
- plan(SKIP_ALL, fmt, ...)
Use this to start a series of tests. When you know how many tests there
will be, you can put a number as a number of tests you expect to run. If
you do not know how many tests there will be, you can use plan(NO_PLAN)
or not call this function. When you pass it a number of tests to run, a
message similar to the following will appear in the output:
1..5
If you pass it SKIP_ALL, the whole test will be skipped.
- ok(test)
- ok(test, fmt, ...)
Specify a test. the test can be any statement returning a true or false
value. You may optionally pass a format string describing the test.
ok(r = reader_new("Of Mice and Men"), "create a new reader");
ok(reader_go_to_page(r, 55), "can turn the page");
ok(r->page == 55, "page turned to the right one");
Should print out:
ok 1 - create a new reader
ok 2 - can turn the page
ok 3 - page turned to the right one
On failure, a diagnostic message will be printed out.
not ok 3 - page turned to the right one
# Failed test 'page turned to the right one'
# at reader.c line 13.
- is(got, expected)
- is(got, expected, fmt, ...)
- isnt(got, unexpected)
- isnt(got, unexpected, fmt, ...)
Tests that the string you got is what you expected. with isnt, it is the
reverse.
is("this", "that", "this is that");
prints:
not ok 1 - this is that
# Failed test 'this is that'
# at is.c line 6.
# got: 'this'
# expected: 'that'
- cmp_ok(a, op, b)
- cmp_ok(a, op, b, fmt, ...)
Compares two ints with any binary operator that doesn't require an lvalue.
This is nice to use since it provides a better error message than an
equivalent ok.
cmp_ok(420, ">", 666);
prints:
not ok 1
# Failed test at cmpok.c line 5.
# 420
# >
# 666
- cmp_mem(got, expected, n)
- cmp_mem(got, expected, n, fmt, ...)
Tests that the first n bytes of the memory you got is what you expected.
NULL pointers for got and expected are handled (if either is NULL,
the test fails), but you need to ensure n is not too large.
char *a = "foo";
char *b = "bar";
cmp_mem(a, b, 3)
prints
not ok 1
# Failed test at t/cmp_mem.c line 9.
# Difference starts at offset 0
# got: 0x66
# expected: 0x62
- like(got, expected)
- like(got, expected, fmt, ...)
- unlike(got, unexpected)
- unlike(got, unexpected, fmt, ...)
Tests that the string you got matches the expected extended POSIX regex.
unlike is the reverse. These macros are the equivalent of a skip on
Windows.
like("stranger", "^s.(r).*\\1$", "matches the regex");
prints:
ok 1 - matches the regex
- pass()
- pass(fmt, ...)
- fail()
- fail(fmt, ...)
Speciy that a test succeeded or failed. Use these when the statement is
longer than you can fit into the argument given to an ok() test.
- dies_ok(code)
- dies_ok(code, fmt, ...)
- lives_ok(code)
- lives_ok(code, fmt, ...)
Tests whether the given code causes your program to exit. The code gets
passed to a macro that will test it in a forked process. If the code
succeeds it will be executed in the parent process. You can test things
like passing a function a null pointer and make sure it doesnt
dereference it and crash.
dies_ok({abort();}, "abort does close your program");
dies_ok({int x = 0/0;}, "divide by zero crash");
lives_ok({pow(3.0, 5.0);}, "nothing wrong with taking 3**5");
On Windows, these macros are the equivalent of a skip.
- done_testing()
Summarizes the tests that occurred and exits the main function. If
there was no plan, it will print out the number of tests as.
1..5
It will also print a diagnostic message about how many
failures there were.
# Looks like you failed 2 tests of 3 run.
- If all planned tests were successful, it will return 0. If any test fails,
- it will return the number of failed tests (including ones that were
- missing). If they all passed, but there were missing tests, it will return
- 255.
+ If all planned tests were successful, it will return 0. If any
+ test fails, it will return 1. If they all passed, but there
+ were missing tests, it will return 2.
- note(fmt, ...)
- diag(fmt, ...)
print out a message to the tap output. note prints to stdout and diag
prints to stderr. Each line is preceeded by a "# " so that you know its a
diagnostic message.
note("This is\na note\nto describe\nsomething.");
prints:
# This is
# a note
# to describe
# something
ok() and these functions return ints so you can use them like:
ok(1) && note("yo!");
ok(0) || diag("I have no idea what just happened");
- skip(test, n)
- skip(test, n, fmt, ...)
- end_skip
Skip a series of n tests if test is true. You may give a reason why you are
skipping them or not. The (possibly) skipped tests must occur between the
skip and end_skip macros.
skip(TRUE, 2);
ok(1);
ok(0);
end_skip;
prints:
ok 1 # skip
ok 2 # skip
- todo()
- todo(fmt, ...)
- end_todo
Specifies a series of tests that you expect to fail because they are not
yet implemented.
todo()
ok(0);
end_todo;
prints:
not ok 1 # TODO
# Failed (TODO) test at todo.c line 7
- BAIL_OUT()
- BAIL_OUT(fmt, ...)
Immediately stops all testing.
BAIL_OUT("Can't go no further");
prints
Bail out! Can't go no further
and exits with 255.
diff --git a/tap.c b/tap.c
index 580b050..37f509e 100644
--- a/tap.c
+++ b/tap.c
@@ -1,372 +1,369 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the GPLv2 or any later version
*/
#define _DEFAULT_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
if (!str) {
perror("malloc error");
exit(1);
}
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
tap_plan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
note("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
if (!test)
printf("not ");
printf("ok %d", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
fprintf(stderr, "# Failed ");
if (todo_mesg)
fprintf(stderr, "(TODO) ");
fprintf(stderr, "test ");
if (*name)
fprintf(stderr, "'%s'\n# ", name);
fprintf(stderr, "at %s line %d.\n", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static int
find_mem_diff (const char *a, const char *b, size_t n, size_t *offset) {
size_t i;
if (a == b)
return 0;
if (!a || !b)
return 2;
for (i = 0; i < n; i++) {
if (a[i] != b[i]) {
*offset = i;
return 1;
}
}
return 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;
}
static void
vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
char *mesg, *line;
int i;
if (!fmt)
return;
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
fprintf(fh, "# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
return;
}
int
diag (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stderr, fmt, args);
va_end(args);
return 0;
}
int
note (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stdout, fmt, args);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
- retval = 255;
+ retval = 2;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
- if (expected_tests == NO_PLAN)
- retval = failed_tests;
- else
- retval = expected_tests - current_test + failed_tests;
+ retval = 1;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
tap_skip (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
note("skip %s\n", why);
}
free(why);
}
void
tap_todo (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
tap_end_todo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
#if defined __APPLE__ || defined BSD
#define MAP_ANONYMOUS MAP_ANON
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros. */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
|
zorgnax/libtap
|
4ebdef73989f407a1deeb20957f6f6c6e0c0ea1a
|
Link tests with the static library to avoid LD_LIBRARY_PATH errors
|
diff --git a/Makefile b/Makefile
index 6d774f5..0da18e7 100644
--- a/Makefile
+++ b/Makefile
@@ -1,58 +1,58 @@
CFLAGS = -g -Wall -I. -fPIC
CC = gcc
PREFIX = $(DESTDIR)/usr/local
TESTS = $(patsubst %.c, %, $(wildcard t/*.c))
ifdef ANSI
# -D_BSD_SOURCE for MAP_ANONYMOUS
CFLAGS += -ansi -D_BSD_SOURCE
LDLIBS += -lbsd-compat
endif
%:
$(CC) $(LDFLAGS) $(TARGET_ARCH) $(filter %.o %.a %.so, $^) $(LDLIBS) -o $@
%.o:
$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $(filter %.c, $^) $(LDLIBS) -o $@
%.a:
$(AR) rcs $@ $(filter %.o, $^)
%.so:
$(CC) -shared $(LDFLAGS) $(TARGET_ARCH) $(filter %.o, $^) $(LDLIBS) -o $@
all: libtap.a libtap.so tests
libtap.a: tap.o
libtap.so: tap.o
tap.o: tap.c tap.h
tests: $(TESTS)
-$(TESTS): %: %.o libtap.so
+$(TESTS): %: %.o libtap.a
$(patsubst %, %.o, $(TESTS)): %.o: %.c tap.h
clean:
rm -rf *.o t/*.o libtap.a libtap.so $(TESTS)
install: libtap.a tap.h libtap.so
mkdir -p $(PREFIX)/lib $(PREFIX)/include
install -c libtap.a $(PREFIX)/lib
install -c libtap.so $(PREFIX)/lib
install -c tap.h $(PREFIX)/include
uninstall:
rm $(PREFIX)/lib/libtap.a $(PREFIX)/lib/libtap.so $(PREFIX)/include/tap.h
dist:
rm libtap.zip
zip -r libtap *
check test: all
- prove
+ perl t/test.t
.PHONY: all clean install uninstall dist check test tests
|
zorgnax/libtap
|
2d23c18824a6023cda2d01bb351c5e00bbd00c3c
|
Remove the Visual Studio project file since it might be out of date
|
diff --git a/INSTALL b/INSTALL
index 8df7ce3..acd3cae 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,49 +1,46 @@
To install libtap on a unix-like system:
$ make
$ make check
$ make install
Note that `make check` runs a perl unit test. It makes use of
diff(1), so if you run it, make sure you have those tools installed
first. To compile with gcc -ansi, run
$ make ANSI=1
To install to a different directory than /usr/local, supply the
PREFIX variable to make:
$ make PREFIX=/usr install
On Windows, the library can be created by first setting up
the correct development environment variables. Usually this
is done by running vcvars32.bat included in the visual studio
distribution. You should also install gnu make which can be
found at http://gnuwin32.sourceforge.net/packages/make.htm.
-And you should have perl to run the tests although this isnt
+And you should have perl to run the tests although this isn't
absolutely necessary. Once this is done, you should be able to
run the following:
> make -f Makefile.win
> make check
-Alternatively, you might want to use the visual studio project file
-included by Alexander Kahl (e-user).
-
If you want to use it directly in another project, you can copy tap.c
and tap.h there and it shouldn't have a problem compiling.
$ ls
tap.c tap.h test.c
$ cat test.c
#include "tap.h"
int main () {
plan(1);
ok(50 + 5, "foo %s", "bar");
done_testing();
}
$ gcc test.c tap.c
$ a.out
1..1
ok 1 - foo bar
diff --git a/libtap.vcxproj b/libtap.vcxproj
deleted file mode 100644
index a790da4..0000000
--- a/libtap.vcxproj
+++ /dev/null
@@ -1,80 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <ItemGroup Label="ProjectConfigurations">
- <ProjectConfiguration Include="Debug|Win32">
- <Configuration>Debug</Configuration>
- <Platform>Win32</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Release|Win32">
- <Configuration>Release</Configuration>
- <Platform>Win32</Platform>
- </ProjectConfiguration>
- </ItemGroup>
- <PropertyGroup Label="Globals">
- <ProjectGuid>{4DFC985A-83D7-4E61-85FE-C6EA6E43E3AA}</ProjectGuid>
- <Keyword>Win32Proj</Keyword>
- <RootNamespace>libtap</RootNamespace>
- </PropertyGroup>
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
- <ConfigurationType>StaticLibrary</ConfigurationType>
- <UseDebugLibraries>true</UseDebugLibraries>
- <CharacterSet>Unicode</CharacterSet>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
- <ConfigurationType>StaticLibrary</ConfigurationType>
- <UseDebugLibraries>false</UseDebugLibraries>
- <WholeProgramOptimization>true</WholeProgramOptimization>
- <CharacterSet>Unicode</CharacterSet>
- </PropertyGroup>
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
- <ImportGroup Label="ExtensionSettings">
- </ImportGroup>
- <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- </ImportGroup>
- <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- </ImportGroup>
- <PropertyGroup Label="UserMacros" />
- <PropertyGroup />
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <ClCompile>
- <PrecompiledHeader>
- </PrecompiledHeader>
- <WarningLevel>Level3</WarningLevel>
- <Optimization>Disabled</Optimization>
- <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- </ClCompile>
- <Link>
- <SubSystem>Windows</SubSystem>
- <GenerateDebugInformation>true</GenerateDebugInformation>
- </Link>
- </ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <ClCompile>
- <WarningLevel>Level3</WarningLevel>
- <PrecompiledHeader>
- </PrecompiledHeader>
- <Optimization>MaxSpeed</Optimization>
- <FunctionLevelLinking>true</FunctionLevelLinking>
- <IntrinsicFunctions>true</IntrinsicFunctions>
- <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- </ClCompile>
- <Link>
- <SubSystem>Windows</SubSystem>
- <GenerateDebugInformation>true</GenerateDebugInformation>
- <EnableCOMDATFolding>true</EnableCOMDATFolding>
- <OptimizeReferences>true</OptimizeReferences>
- </Link>
- </ItemDefinitionGroup>
- <ItemGroup>
- <ClInclude Include="tap.h" />
- </ItemGroup>
- <ItemGroup>
- <ClCompile Include="tap.c" />
- </ItemGroup>
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
- <ImportGroup Label="ExtensionTargets">
- </ImportGroup>
-</Project>
|
zorgnax/libtap
|
cf2c7c3b0722eac365613b03a9f2b8c027273043
|
Create libtap.so by default
|
diff --git a/Makefile b/Makefile
index 76d0941..6d774f5 100644
--- a/Makefile
+++ b/Makefile
@@ -1,56 +1,58 @@
CFLAGS = -g -Wall -I. -fPIC
CC = gcc
PREFIX = $(DESTDIR)/usr/local
TESTS = $(patsubst %.c, %, $(wildcard t/*.c))
ifdef ANSI
# -D_BSD_SOURCE for MAP_ANONYMOUS
CFLAGS += -ansi -D_BSD_SOURCE
LDLIBS += -lbsd-compat
endif
%:
$(CC) $(LDFLAGS) $(TARGET_ARCH) $(filter %.o %.a %.so, $^) $(LDLIBS) -o $@
%.o:
$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $(filter %.c, $^) $(LDLIBS) -o $@
%.a:
$(AR) rcs $@ $(filter %.o, $^)
-%.so: tap.o
+%.so:
$(CC) -shared $(LDFLAGS) $(TARGET_ARCH) $(filter %.o, $^) $(LDLIBS) -o $@
-all: libtap.a tests
+all: libtap.a libtap.so tests
libtap.a: tap.o
+libtap.so: tap.o
+
tap.o: tap.c tap.h
tests: $(TESTS)
-$(TESTS): %: %.o libtap.a
+$(TESTS): %: %.o libtap.so
$(patsubst %, %.o, $(TESTS)): %.o: %.c tap.h
clean:
rm -rf *.o t/*.o libtap.a libtap.so $(TESTS)
install: libtap.a tap.h libtap.so
mkdir -p $(PREFIX)/lib $(PREFIX)/include
- install -D libtap.a $(PREFIX)/lib
- install -D libtap.so $(PREFIX)/lib
- install -D tap.h $(PREFIX)/include
+ install -c libtap.a $(PREFIX)/lib
+ install -c libtap.so $(PREFIX)/lib
+ install -c tap.h $(PREFIX)/include
uninstall:
rm $(PREFIX)/lib/libtap.a $(PREFIX)/lib/libtap.so $(PREFIX)/include/tap.h
dist:
rm libtap.zip
zip -r libtap *
check test: all
prove
.PHONY: all clean install uninstall dist check test tests
|
zorgnax/libtap
|
db4aa0d7e8a7b2a9f48dd7d50f0beb2734851446
|
Create shared objects by default
|
diff --git a/.gitignore b/.gitignore
index 0e470a3..778a470 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,10 +1,12 @@
/t/*
!/t/*.*
/t/*.exe
/t/*.got
*.a
*.lo
*.o
+*.so
+usr/
*.sw?
/.deps
/.dirstamp
diff --git a/Makefile b/Makefile
index 16e8ca5..76d0941 100644
--- a/Makefile
+++ b/Makefile
@@ -1,54 +1,56 @@
-CFLAGS = -g -Wall -I.
+CFLAGS = -g -Wall -I. -fPIC
CC = gcc
-PREFIX = /usr/local
+PREFIX = $(DESTDIR)/usr/local
TESTS = $(patsubst %.c, %, $(wildcard t/*.c))
ifdef ANSI
# -D_BSD_SOURCE for MAP_ANONYMOUS
CFLAGS += -ansi -D_BSD_SOURCE
LDLIBS += -lbsd-compat
endif
%:
$(CC) $(LDFLAGS) $(TARGET_ARCH) $(filter %.o %.a %.so, $^) $(LDLIBS) -o $@
%.o:
$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $(filter %.c, $^) $(LDLIBS) -o $@
%.a:
$(AR) rcs $@ $(filter %.o, $^)
-%.so:
+%.so: tap.o
$(CC) -shared $(LDFLAGS) $(TARGET_ARCH) $(filter %.o, $^) $(LDLIBS) -o $@
all: libtap.a tests
libtap.a: tap.o
tap.o: tap.c tap.h
tests: $(TESTS)
$(TESTS): %: %.o libtap.a
$(patsubst %, %.o, $(TESTS)): %.o: %.c tap.h
clean:
- rm -rf *.o t/*.o libtap.a $(TESTS)
+ rm -rf *.o t/*.o libtap.a libtap.so $(TESTS)
-install: libtap.a tap.h
- install -c libtap.a $(PREFIX)/lib
- install -c tap.h $(PREFIX)/include
+install: libtap.a tap.h libtap.so
+ mkdir -p $(PREFIX)/lib $(PREFIX)/include
+ install -D libtap.a $(PREFIX)/lib
+ install -D libtap.so $(PREFIX)/lib
+ install -D tap.h $(PREFIX)/include
uninstall:
- rm $(PREFIX)/lib/libtap.a $(PREFIX)/include/tap.h
+ rm $(PREFIX)/lib/libtap.a $(PREFIX)/lib/libtap.so $(PREFIX)/include/tap.h
dist:
rm libtap.zip
zip -r libtap *
check test: all
prove
.PHONY: all clean install uninstall dist check test tests
|
zorgnax/libtap
|
78de74db6028a4a7efaa90f4e8924a4d06a5100a
|
Add a PREFIX variable to the Makefile
|
diff --git a/INSTALL b/INSTALL
index 13b5a70..a268542 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,44 +1,49 @@
To install libtap on a unix-like system:
$ make
$ make check
$ make install
Note that `make check` runs Perl unit-tests, which require the
Test::Differences module from CPAN; if you run them, make sure to install it.
To compile with gcc -ansi, run
$ make ANSI=1
+To install to a different directory than /usr/local, supply the
+PREFIX variable to make:
+
+ $ make PREFIX=/usr install
+
On Windows, the library can be created by first setting up
the correct development environment variables. Usually this
is done by running vcvars32.bat included in the visual studio
distribution. You should also install gnu make which can be
found at http://gnuwin32.sourceforge.net/packages/make.htm.
And you should have perl to run the tests although this isnt
absolutely necessary. Once this is done, you should be able to
run the following:
> make -f Makefile.win
> make check
Alternatively, you might want to use the visual studio project file
included by Alexander Kahl (e-user).
If you want to use it directly in another project, you can copy tap.c
and tap.h there and it shouldn't have a problem compiling.
$ ls
tap.c tap.h test.c
$ cat test.c
#include "tap.h"
int main () {
plan(1);
ok(50 + 5, "foo %s", "bar");
done_testing();
}
$ gcc test.c tap.c
$ a.out
1..1
ok 1 - foo bar
diff --git a/Makefile b/Makefile
index 750ae44..16e8ca5 100644
--- a/Makefile
+++ b/Makefile
@@ -1,53 +1,54 @@
CFLAGS = -g -Wall -I.
CC = gcc
+PREFIX = /usr/local
TESTS = $(patsubst %.c, %, $(wildcard t/*.c))
ifdef ANSI
# -D_BSD_SOURCE for MAP_ANONYMOUS
CFLAGS += -ansi -D_BSD_SOURCE
LDLIBS += -lbsd-compat
endif
%:
$(CC) $(LDFLAGS) $(TARGET_ARCH) $(filter %.o %.a %.so, $^) $(LDLIBS) -o $@
%.o:
$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $(filter %.c, $^) $(LDLIBS) -o $@
%.a:
$(AR) rcs $@ $(filter %.o, $^)
%.so:
$(CC) -shared $(LDFLAGS) $(TARGET_ARCH) $(filter %.o, $^) $(LDLIBS) -o $@
all: libtap.a tests
libtap.a: tap.o
tap.o: tap.c tap.h
tests: $(TESTS)
$(TESTS): %: %.o libtap.a
$(patsubst %, %.o, $(TESTS)): %.o: %.c tap.h
clean:
rm -rf *.o t/*.o libtap.a $(TESTS)
install: libtap.a tap.h
- sudo cp libtap.a /usr/lib
- sudo cp tap.h /usr/include
+ install -c libtap.a $(PREFIX)/lib
+ install -c tap.h $(PREFIX)/include
uninstall:
- sudo rm /usr/lib/libtap.a /usr/include/tap.h
+ rm $(PREFIX)/lib/libtap.a $(PREFIX)/include/tap.h
dist:
rm libtap.zip
zip -r libtap *
check test: all
prove
.PHONY: all clean install uninstall dist check test tests
|
zorgnax/libtap
|
4f14d706ac2bfa2e7dfa40b7dc9f1a88a4f66af0
|
_BSD_SOURCE is deprecated so use _DEFAULT_SOURCE instead
|
diff --git a/tap.c b/tap.c
index e037ba6..580b050 100644
--- a/tap.c
+++ b/tap.c
@@ -1,372 +1,372 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the GPLv2 or any later version
*/
-#define _BSD_SOURCE 1
+#define _DEFAULT_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
if (!str) {
perror("malloc error");
exit(1);
}
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
tap_plan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
note("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
if (!test)
printf("not ");
printf("ok %d", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
fprintf(stderr, "# Failed ");
if (todo_mesg)
fprintf(stderr, "(TODO) ");
fprintf(stderr, "test ");
if (*name)
fprintf(stderr, "'%s'\n# ", name);
fprintf(stderr, "at %s line %d.\n", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static int
find_mem_diff (const char *a, const char *b, size_t n, size_t *offset) {
size_t i;
if (a == b)
return 0;
if (!a || !b)
return 2;
for (i = 0; i < n; i++) {
if (a[i] != b[i]) {
*offset = i;
return 1;
}
}
return 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;
}
static void
vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
char *mesg, *line;
int i;
if (!fmt)
return;
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
fprintf(fh, "# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
return;
}
int
diag (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stderr, fmt, args);
va_end(args);
return 0;
}
int
note (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stdout, fmt, args);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 255;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
if (expected_tests == NO_PLAN)
retval = failed_tests;
else
retval = expected_tests - current_test + failed_tests;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
tap_skip (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
note("skip %s\n", why);
}
free(why);
}
void
tap_todo (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
tap_end_todo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
#if defined __APPLE__ || defined BSD
#define MAP_ANONYMOUS MAP_ANON
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros. */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
|
zorgnax/libtap
|
0bdd9778f610c974295fb0199a85953f01cd13dc
|
Ignore more junk
|
diff --git a/.gitignore b/.gitignore
index 2e45fcb..a603eee 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,8 @@
/t/*
!/t/*.*
*.a
+*.lo
*.o
*.sw?
+/.deps
+/.dirstamp
|
zorgnax/libtap
|
de94575882012b112babb049ab9a1bfb1679b432
|
Add install section to README; add make check note.
|
diff --git a/INSTALL b/INSTALL
index 2ed4543..13b5a70 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,42 +1,44 @@
To install libtap on a unix-like system:
$ make
$ make check
$ make install
+Note that `make check` runs Perl unit-tests, which require the
+Test::Differences module from CPAN; if you run them, make sure to install it.
To compile with gcc -ansi, run
$ make ANSI=1
On Windows, the library can be created by first setting up
the correct development environment variables. Usually this
is done by running vcvars32.bat included in the visual studio
distribution. You should also install gnu make which can be
found at http://gnuwin32.sourceforge.net/packages/make.htm.
And you should have perl to run the tests although this isnt
absolutely necessary. Once this is done, you should be able to
run the following:
> make -f Makefile.win
> make check
Alternatively, you might want to use the visual studio project file
included by Alexander Kahl (e-user).
If you want to use it directly in another project, you can copy tap.c
and tap.h there and it shouldn't have a problem compiling.
$ ls
tap.c tap.h test.c
$ cat test.c
#include "tap.h"
int main () {
plan(1);
ok(50 + 5, "foo %s", "bar");
done_testing();
}
$ gcc test.c tap.c
$ a.out
1..1
ok 1 - foo bar
diff --git a/README.md b/README.md
index 09366dc..ea47173 100644
--- a/README.md
+++ b/README.md
@@ -1,264 +1,274 @@
NAME
====
libtap - Write tests in C
SYNOPSIS
========
#include <tap.h>
int main () {
plan(5);
ok(3 == 3);
is("fnord", "eek", "two different strings not that way?");
ok(3 <= 8732, "%d <= %d", 3, 8732);
like("fnord", "f(yes|no)r*[a-f]$");
cmp_ok(3, ">=", 10);
done_testing();
}
results in:
1..5
ok 1
not ok 2 - two different strings not that way?
# Failed test 'two different strings not that way?'
# at t/synopsis.c line 7.
# got: 'fnord'
# expected: 'eek'
ok 3 - 3 <= 8732
ok 4
not ok 5
# Failed test at t/synopsis.c line 10.
# 3
# >=
# 10
# Looks like you failed 2 tests of 5 run.
DESCRIPTION
===========
tap is an easy to read and easy to write way of creating tests for your
software. This library creates functions that can be used to generate it for
your C programs. It is mostly based on the Test::More Perl module.
+INSTALL
+=======
+
+On **Unix** systems:
+
+ $ make
+ $ make install
+
+For more detailed installation instructions (eg, for **Windows**), see `INSTALL`.
+
FUNCTIONS
=========
- plan(tests)
- plan(NO_PLAN)
- plan(SKIP_ALL);
- plan(SKIP_ALL, fmt, ...)
Use this to start a series of tests. When you know how many tests there
will be, you can put a number as a number of tests you expect to run. If
you do not know how many tests there will be, you can use plan(NO_PLAN)
or not call this function. When you pass it a number of tests to run, a
message similar to the following will appear in the output:
1..5
If you pass it SKIP_ALL, the whole test will be skipped.
- ok(test)
- ok(test, fmt, ...)
Specify a test. the test can be any statement returning a true or false
value. You may optionally pass a format string describing the test.
ok(r = reader_new("Of Mice and Men"), "create a new reader");
ok(reader_go_to_page(r, 55), "can turn the page");
ok(r->page == 55, "page turned to the right one");
Should print out:
ok 1 - create a new reader
ok 2 - can turn the page
ok 3 - page turned to the right one
On failure, a diagnostic message will be printed out.
not ok 3 - page turned to the right one
# Failed test 'page turned to the right one'
# at reader.c line 13.
- is(got, expected)
- is(got, expected, fmt, ...)
- isnt(got, unexpected)
- isnt(got, unexpected, fmt, ...)
Tests that the string you got is what you expected. with isnt, it is the
reverse.
is("this", "that", "this is that");
prints:
not ok 1 - this is that
# Failed test 'this is that'
# at is.c line 6.
# got: 'this'
# expected: 'that'
- cmp_ok(a, op, b)
- cmp_ok(a, op, b, fmt, ...)
Compares two ints with any binary operator that doesn't require an lvalue.
This is nice to use since it provides a better error message than an
equivalent ok.
cmp_ok(420, ">", 666);
prints:
not ok 1
# Failed test at cmpok.c line 5.
# 420
# >
# 666
- cmp_mem(got, expected, n)
- cmp_mem(got, expected, n, fmt, ...)
Tests that the first n bytes of the memory you got is what you expected.
NULL pointers for got and expected are handled (if either is NULL,
the test fails), but you need to ensure n is not too large.
char *a = "foo";
char *b = "bar";
cmp_mem(a, b, 3)
prints
not ok 1
# Failed test at t/cmp_mem.c line 9.
# Difference starts at offset 0
# got: 0x66
# expected: 0x62
- like(got, expected)
- like(got, expected, fmt, ...)
- unlike(got, unexpected)
- unlike(got, unexpected, fmt, ...)
Tests that the string you got matches the expected extended POSIX regex.
unlike is the reverse. These macros are the equivalent of a skip on
Windows.
like("stranger", "^s.(r).*\\1$", "matches the regex");
prints:
ok 1 - matches the regex
- pass()
- pass(fmt, ...)
- fail()
- fail(fmt, ...)
Speciy that a test succeeded or failed. Use these when the statement is
longer than you can fit into the argument given to an ok() test.
- dies_ok(code)
- dies_ok(code, fmt, ...)
- lives_ok(code)
- lives_ok(code, fmt, ...)
Tests whether the given code causes your program to exit. The code gets
passed to a macro that will test it in a forked process. If the code
succeeds it will be executed in the parent process. You can test things
like passing a function a null pointer and make sure it doesnt
dereference it and crash.
dies_ok({abort();}, "abort does close your program");
dies_ok({int x = 0/0;}, "divide by zero crash");
lives_ok({pow(3.0, 5.0);}, "nothing wrong with taking 3**5");
On Windows, these macros are the equivalent of a skip.
- done_testing()
Summarizes the tests that occurred and exits the main function. If
there was no plan, it will print out the number of tests as.
1..5
It will also print a diagnostic message about how many
failures there were.
# Looks like you failed 2 tests of 3 run.
If all planned tests were successful, it will return 0. If any test fails,
it will return the number of failed tests (including ones that were
missing). If they all passed, but there were missing tests, it will return
255.
- note(fmt, ...)
- diag(fmt, ...)
print out a message to the tap output. note prints to stdout and diag
prints to stderr. Each line is preceeded by a "# " so that you know its a
diagnostic message.
note("This is\na note\nto describe\nsomething.");
prints:
# This is
# a note
# to describe
# something
ok() and these functions return ints so you can use them like:
ok(1) && note("yo!");
ok(0) || diag("I have no idea what just happened");
- skip(test, n)
- skip(test, n, fmt, ...)
- end_skip
Skip a series of n tests if test is true. You may give a reason why you are
skipping them or not. The (possibly) skipped tests must occur between the
skip and end_skip macros.
skip(TRUE, 2);
ok(1);
ok(0);
end_skip;
prints:
ok 1 # skip
ok 2 # skip
- todo()
- todo(fmt, ...)
- end_todo
Specifies a series of tests that you expect to fail because they are not
yet implemented.
todo()
ok(0);
end_todo;
prints:
not ok 1 # TODO
# Failed (TODO) test at todo.c line 7
- BAIL_OUT()
- BAIL_OUT(fmt, ...)
Immediately stops all testing.
BAIL_OUT("Can't go no further");
prints
Bail out! Can't go no further
and exits with 255.
|
zorgnax/libtap
|
56f9c06bab324e9680c40b22ca995f8b8c02a080
|
Make a function for finding memory difference offsets
|
diff --git a/README.md b/README.md
index eaaa2ba..09366dc 100644
--- a/README.md
+++ b/README.md
@@ -1,264 +1,264 @@
NAME
====
libtap - Write tests in C
SYNOPSIS
========
#include <tap.h>
int main () {
plan(5);
ok(3 == 3);
is("fnord", "eek", "two different strings not that way?");
ok(3 <= 8732, "%d <= %d", 3, 8732);
like("fnord", "f(yes|no)r*[a-f]$");
cmp_ok(3, ">=", 10);
done_testing();
}
results in:
1..5
ok 1
not ok 2 - two different strings not that way?
# Failed test 'two different strings not that way?'
# at t/synopsis.c line 7.
# got: 'fnord'
# expected: 'eek'
ok 3 - 3 <= 8732
ok 4
not ok 5
# Failed test at t/synopsis.c line 10.
# 3
# >=
# 10
# Looks like you failed 2 tests of 5 run.
DESCRIPTION
===========
tap is an easy to read and easy to write way of creating tests for your
software. This library creates functions that can be used to generate it for
your C programs. It is mostly based on the Test::More Perl module.
FUNCTIONS
=========
- plan(tests)
- plan(NO_PLAN)
- plan(SKIP_ALL);
- plan(SKIP_ALL, fmt, ...)
Use this to start a series of tests. When you know how many tests there
will be, you can put a number as a number of tests you expect to run. If
you do not know how many tests there will be, you can use plan(NO_PLAN)
or not call this function. When you pass it a number of tests to run, a
message similar to the following will appear in the output:
1..5
If you pass it SKIP_ALL, the whole test will be skipped.
- ok(test)
- ok(test, fmt, ...)
Specify a test. the test can be any statement returning a true or false
value. You may optionally pass a format string describing the test.
ok(r = reader_new("Of Mice and Men"), "create a new reader");
ok(reader_go_to_page(r, 55), "can turn the page");
ok(r->page == 55, "page turned to the right one");
Should print out:
ok 1 - create a new reader
ok 2 - can turn the page
ok 3 - page turned to the right one
On failure, a diagnostic message will be printed out.
not ok 3 - page turned to the right one
# Failed test 'page turned to the right one'
# at reader.c line 13.
- is(got, expected)
- is(got, expected, fmt, ...)
- isnt(got, unexpected)
- isnt(got, unexpected, fmt, ...)
Tests that the string you got is what you expected. with isnt, it is the
reverse.
is("this", "that", "this is that");
prints:
not ok 1 - this is that
# Failed test 'this is that'
# at is.c line 6.
# got: 'this'
# expected: 'that'
- cmp_ok(a, op, b)
- cmp_ok(a, op, b, fmt, ...)
Compares two ints with any binary operator that doesn't require an lvalue.
This is nice to use since it provides a better error message than an
equivalent ok.
cmp_ok(420, ">", 666);
prints:
not ok 1
# Failed test at cmpok.c line 5.
# 420
# >
# 666
- cmp_mem(got, expected, n)
- cmp_mem(got, expected, n, fmt, ...)
Tests that the first n bytes of the memory you got is what you expected.
- NULL pointers for got and expected are handled (if either or both are NULL,
+ NULL pointers for got and expected are handled (if either is NULL,
the test fails), but you need to ensure n is not too large.
char *a = "foo";
char *b = "bar";
cmp_mem(a, b, 3)
prints
not ok 1
# Failed test at t/cmp_mem.c line 9.
# Difference starts at offset 0
# got: 0x66
# expected: 0x62
- like(got, expected)
- like(got, expected, fmt, ...)
- unlike(got, unexpected)
- unlike(got, unexpected, fmt, ...)
Tests that the string you got matches the expected extended POSIX regex.
unlike is the reverse. These macros are the equivalent of a skip on
Windows.
like("stranger", "^s.(r).*\\1$", "matches the regex");
prints:
ok 1 - matches the regex
- pass()
- pass(fmt, ...)
- fail()
- fail(fmt, ...)
Speciy that a test succeeded or failed. Use these when the statement is
longer than you can fit into the argument given to an ok() test.
- dies_ok(code)
- dies_ok(code, fmt, ...)
- lives_ok(code)
- lives_ok(code, fmt, ...)
Tests whether the given code causes your program to exit. The code gets
passed to a macro that will test it in a forked process. If the code
succeeds it will be executed in the parent process. You can test things
like passing a function a null pointer and make sure it doesnt
dereference it and crash.
dies_ok({abort();}, "abort does close your program");
dies_ok({int x = 0/0;}, "divide by zero crash");
lives_ok({pow(3.0, 5.0);}, "nothing wrong with taking 3**5");
On Windows, these macros are the equivalent of a skip.
- done_testing()
Summarizes the tests that occurred and exits the main function. If
there was no plan, it will print out the number of tests as.
1..5
It will also print a diagnostic message about how many
failures there were.
# Looks like you failed 2 tests of 3 run.
If all planned tests were successful, it will return 0. If any test fails,
it will return the number of failed tests (including ones that were
missing). If they all passed, but there were missing tests, it will return
255.
- note(fmt, ...)
- diag(fmt, ...)
print out a message to the tap output. note prints to stdout and diag
prints to stderr. Each line is preceeded by a "# " so that you know its a
diagnostic message.
note("This is\na note\nto describe\nsomething.");
prints:
# This is
# a note
# to describe
# something
ok() and these functions return ints so you can use them like:
ok(1) && note("yo!");
ok(0) || diag("I have no idea what just happened");
- skip(test, n)
- skip(test, n, fmt, ...)
- end_skip
Skip a series of n tests if test is true. You may give a reason why you are
skipping them or not. The (possibly) skipped tests must occur between the
skip and end_skip macros.
skip(TRUE, 2);
ok(1);
ok(0);
end_skip;
prints:
ok 1 # skip
ok 2 # skip
- todo()
- todo(fmt, ...)
- end_todo
Specifies a series of tests that you expect to fail because they are not
yet implemented.
todo()
ok(0);
end_todo;
prints:
not ok 1 # TODO
# Failed (TODO) test at todo.c line 7
- BAIL_OUT()
- BAIL_OUT(fmt, ...)
Immediately stops all testing.
BAIL_OUT("Can't go no further");
prints
Bail out! Can't go no further
and exits with 255.
diff --git a/t/cmp_mem.c b/t/cmp_mem.c
index 2d7d160..ac2e150 100644
--- a/t/cmp_mem.c
+++ b/t/cmp_mem.c
@@ -1,19 +1,21 @@
#include "tap.h"
int main () {
setvbuf(stdout, NULL, _IONBF, 0);
- unsigned char all_0[] = { 0, 0, 0, 0 };
- unsigned char all_255[] = { 255, 255, 255, 255 };
- unsigned char half[] = { 0, 0, 255, 255 };
+ unsigned char all_0[] = {0, 0, 0, 0};
+ unsigned char all_255[] = {255, 255, 255, 255};
+ unsigned char half[] = {0, 0, 255, 255};
+ unsigned char half_2[] = {0, 0, 255, 255};
- plan(7);
+ plan(8);
+ cmp_mem(half, half_2, 4, "Same array different address");
cmp_mem(all_0, all_0, 4, "Array must be equal to itself");
cmp_mem(all_0, all_255, 4, "Arrays with different contents");
cmp_mem(all_0, half, 4, "Arrays differ, but start the same");
cmp_mem(all_0, all_255, 0, "Comparing 0 bytes of different arrays");
cmp_mem(NULL, all_0, 4, "got == NULL");
cmp_mem(all_0, NULL, 4, "expected == NULL");
cmp_mem(NULL, NULL, 4, "got == expected == NULL");
done_testing();
}
diff --git a/t/test.t b/t/test.t
index 726e67f..78f4012 100755
--- a/t/test.t
+++ b/t/test.t
@@ -1,254 +1,248 @@
#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 10;
use Test::Differences;
my $x = $^O eq 'MSWin32' ? ".exe" : "";
sub cmd_eq_or_diff {
my ($command, $expected) = @_;
my $output = `$command$x 2>&1`;
eq_or_diff($output, $expected, $command);
}
cmd_eq_or_diff "t/cmpok", <<END;
1..9
not ok 1
# Failed test at t/cmpok.c line 6.
# 420
# >
# 666
not ok 2 - the number 23 is definitely 55
# Failed test 'the number 23 is definitely 55'
# at t/cmpok.c line 7.
# 23
# ==
# 55
not ok 3
# Failed test at t/cmpok.c line 8.
# 23
# ==
# 55
ok 4
# unrecognized operator 'frob'
not ok 5
# Failed test at t/cmpok.c line 10.
# 23
# frob
# 55
ok 6
not ok 7
# Failed test at t/cmpok.c line 12.
# 55
# +
# -55
ok 8
not ok 9
# Failed test at t/cmpok.c line 14.
# 55
# %
# 5
# Looks like you failed 6 tests of 9 run.
END
cmd_eq_or_diff "t/cmp_mem", <<END;
-1..7
-ok 1 - Array must be equal to itself
-not ok 2 - Arrays with different contents
+1..8
+ok 1 - Same array different address
+ok 2 - Array must be equal to itself
+not ok 3 - Arrays with different contents
# Failed test 'Arrays with different contents'
-# at t/cmp_mem.c line 11.
+# at t/cmp_mem.c line 13.
# Difference starts at offset 0
# got: 0x00
# expected: 0xff
-not ok 3 - Arrays differ, but start the same
+not ok 4 - Arrays differ, but start the same
# Failed test 'Arrays differ, but start the same'
-# at t/cmp_mem.c line 12.
+# at t/cmp_mem.c line 14.
# Difference starts at offset 2
# got: 0x00
# expected: 0xff
-ok 4 - Comparing 0 bytes of different arrays
-not ok 5 - got == NULL
+ok 5 - Comparing 0 bytes of different arrays
+not ok 6 - got == NULL
# Failed test 'got == NULL'
-# at t/cmp_mem.c line 14.
-# got and/or expected are NULL
+# at t/cmp_mem.c line 16.
# got: NULL
# expected: not NULL
-not ok 6 - expected == NULL
+not ok 7 - expected == NULL
# Failed test 'expected == NULL'
-# at t/cmp_mem.c line 15.
-# got and/or expected are NULL
+# at t/cmp_mem.c line 17.
# got: not NULL
# expected: NULL
-not ok 7 - got == expected == NULL
-# Failed test 'got == expected == NULL'
-# at t/cmp_mem.c line 16.
-# got and/or expected are NULL
-# got: NULL
-# expected: NULL
-# Looks like you failed 5 tests of 7 run.
+ok 8 - got == expected == NULL
+# Looks like you failed 4 tests of 8 run.
END
cmd_eq_or_diff "t/diesok", <<END;
1..5
ok 1 - sanity
ok 2 - can't divide by zero
ok 3 - this is a perfectly fine statement
ok 4 - abort kills the program
ok 5 - supress output
END
cmd_eq_or_diff "t/is", <<END;
1..18
not ok 1 - this is that
# Failed test 'this is that'
# at t/is.c line 6.
# got: 'this'
# expected: 'that'
ok 2 - this is this
not ok 3
# Failed test at t/is.c line 8.
# got: 'this'
# expected: 'that'
ok 4
ok 5 - null is null
not ok 6 - null is this
# Failed test 'null is this'
# at t/is.c line 11.
# got: '(null)'
# expected: 'this'
not ok 7 - this is null
# Failed test 'this is null'
# at t/is.c line 12.
# got: 'this'
# expected: '(null)'
not ok 8
# Failed test at t/is.c line 13.
# got: 'foo
# foo
# foo'
# expected: 'bar
# bar
# bar'
ok 9
ok 10 - this isnt that
not ok 11 - this isnt this
# Failed test 'this isnt this'
# at t/is.c line 16.
# got: 'this'
# expected: anything else
ok 12
not ok 13
# Failed test at t/is.c line 18.
# got: 'this'
# expected: anything else
not ok 14 - null isnt null
# Failed test 'null isnt null'
# at t/is.c line 19.
# got: '(null)'
# expected: anything else
ok 15 - null isnt this
ok 16 - this isnt null
ok 17
not ok 18
# Failed test at t/is.c line 23.
# got: 'foo
# foo
# foo'
# expected: anything else
# Looks like you failed 9 tests of 18 run.
END
cmd_eq_or_diff "t/like", <<END;
1..3
ok 1 - strange ~~ /range/
ok 2 - strange !~~ /anger/
ok 3 - matches the regex
END
cmd_eq_or_diff "t/notediag", <<END;
# note no new line
# note new line
# diag no new line
# diag new line
END
cmd_eq_or_diff "t/simple", <<END;
1..24
ok 1
ok 2
ok 3
not ok 4
# Failed test at t/simple.c line 9.
ok 5 - foo
ok 6 - bar
ok 7 - baz
ok 8 - quux
ok 9 - thud
ok 10 - wombat
ok 11 - blurgle
ok 12 - frob
not ok 13 - frobnicate
# Failed test 'frobnicate'
# at t/simple.c line 18.
ok 14 - eek
ok 15 - ook
ok 16 - frodo
ok 17 - bilbo
ok 18 - wubble
ok 19 - flarp
ok 20 - fnord
ok 21
not ok 22
# Failed test at t/simple.c line 27.
ok 23 - good
not ok 24 - bad
# Failed test 'bad'
# at t/simple.c line 29.
# Looks like you failed 4 tests of 24 run.
END
cmd_eq_or_diff "t/skip", <<END;
1..8
ok 1 - quux
ok 2 - thud
ok 3 - wombat
ok 4 # skip need to be on windows
ok 5 - quux
ok 6 - thud
ok 7 - wombat
ok 8 # skip
END
cmd_eq_or_diff "t/synopsis", <<END;
1..5
ok 1
not ok 2 - two different strings not that way?
# Failed test 'two different strings not that way?'
# at t/synopsis.c line 7.
# got: 'fnord'
# expected: 'eek'
ok 3 - 3 <= 8732
ok 4
not ok 5
# Failed test at t/synopsis.c line 10.
# 3
# >=
# 10
# Looks like you failed 2 tests of 5 run.
END
cmd_eq_or_diff "t/todo", <<END;
1..6
not ok 1 - foo # TODO
# Failed (TODO) test 'foo'
# at t/todo.c line 7.
ok 2 - bar # TODO
ok 3 - baz # TODO
not ok 4 - quux # TODO im not ready
# Failed (TODO) test 'quux'
# at t/todo.c line 12.
ok 5 - thud # TODO im not ready
ok 6 - wombat # TODO im not ready
END
diff --git a/tap.c b/tap.c
index ae23a24..e037ba6 100644
--- a/tap.c
+++ b/tap.c
@@ -1,374 +1,372 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the GPLv2 or any later version
*/
#define _BSD_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
if (!str) {
perror("malloc error");
exit(1);
}
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
tap_plan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
note("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
if (!test)
printf("not ");
printf("ok %d", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
fprintf(stderr, "# Failed ");
if (todo_mesg)
fprintf(stderr, "(TODO) ");
fprintf(stderr, "test ");
if (*name)
fprintf(stderr, "'%s'\n# ", name);
fprintf(stderr, "at %s line %d.\n", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
+static int
+find_mem_diff (const char *a, const char *b, size_t n, size_t *offset) {
+ size_t i;
+ if (a == b)
+ return 0;
+ if (!a || !b)
+ return 2;
+ for (i = 0; i < n; i++) {
+ if (a[i] != b[i]) {
+ *offset = i;
+ return 1;
+ }
+ }
+ return 0;
+}
+
int
cmp_mem_at_loc (const char *file, int line, const void *got,
const void *expected, size_t n, const char *fmt, ...)
{
- int i = 0;
- int test = 1; /* assume success */
-
- if ((got == NULL) || (expected == NULL)) {
- test = 0;
- }
- else if (got != expected) {
- /* got and expected point to different memory: compare byte per byte */
- for (i = 0; i < n; ++i) {
- if (((char *)got)[i] != ((char *)expected)[i]) {
- test = 0;
- break;
- }
- }
- }
-
+ size_t offset;
+ int diff = find_mem_diff(got, expected, n, &offset);
va_list args;
va_start(args, fmt);
- vok_at_loc(file, line, test, fmt, args);
+ vok_at_loc(file, line, !diff, fmt, args);
va_end(args);
- if (!test) {
-
- if ((got == NULL) || (expected == NULL)) {
- diag(" got and/or expected are NULL");
- diag(" got: %s", got ? "not NULL" : "NULL");
- diag(" expected: %s", expected ? "not NULL" : "NULL");
- }
- else {
- diag(" Difference starts at offset %d", i);
- diag(" got: 0x%02x", ((unsigned char *)got)[i]);
- diag(" expected: 0x%02x", ((unsigned char *)expected)[i]);
- }
+ 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]);
}
- return test;
+ else if (diff == 2) {
+ diag(" got: %s", got ? "not NULL" : "NULL");
+ diag(" expected: %s", expected ? "not NULL" : "NULL");
+ }
+ return !diff;
}
static void
vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
char *mesg, *line;
int i;
if (!fmt)
return;
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
fprintf(fh, "# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
return;
}
int
diag (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stderr, fmt, args);
va_end(args);
return 0;
}
int
note (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stdout, fmt, args);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 255;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
if (expected_tests == NO_PLAN)
retval = failed_tests;
else
retval = expected_tests - current_test + failed_tests;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
tap_skip (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
note("skip %s\n", why);
}
free(why);
}
void
tap_todo (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
tap_end_todo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
#if defined __APPLE__ || defined BSD
#define MAP_ANONYMOUS MAP_ANON
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros. */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
|
zorgnax/libtap
|
18f1ec08977eb0b1355c33a909efe9ac1dd74a01
|
cmp_mem() improvements
|
diff --git a/README.md b/README.md
index 449388c..eaaa2ba 100644
--- a/README.md
+++ b/README.md
@@ -1,264 +1,264 @@
NAME
====
libtap - Write tests in C
SYNOPSIS
========
#include <tap.h>
int main () {
plan(5);
ok(3 == 3);
is("fnord", "eek", "two different strings not that way?");
ok(3 <= 8732, "%d <= %d", 3, 8732);
like("fnord", "f(yes|no)r*[a-f]$");
cmp_ok(3, ">=", 10);
done_testing();
}
results in:
1..5
ok 1
not ok 2 - two different strings not that way?
# Failed test 'two different strings not that way?'
# at t/synopsis.c line 7.
# got: 'fnord'
# expected: 'eek'
ok 3 - 3 <= 8732
ok 4
not ok 5
# Failed test at t/synopsis.c line 10.
# 3
# >=
# 10
# Looks like you failed 2 tests of 5 run.
DESCRIPTION
===========
tap is an easy to read and easy to write way of creating tests for your
software. This library creates functions that can be used to generate it for
your C programs. It is mostly based on the Test::More Perl module.
FUNCTIONS
=========
- plan(tests)
- plan(NO_PLAN)
- plan(SKIP_ALL);
- plan(SKIP_ALL, fmt, ...)
Use this to start a series of tests. When you know how many tests there
will be, you can put a number as a number of tests you expect to run. If
you do not know how many tests there will be, you can use plan(NO_PLAN)
or not call this function. When you pass it a number of tests to run, a
message similar to the following will appear in the output:
1..5
If you pass it SKIP_ALL, the whole test will be skipped.
- ok(test)
- ok(test, fmt, ...)
Specify a test. the test can be any statement returning a true or false
value. You may optionally pass a format string describing the test.
ok(r = reader_new("Of Mice and Men"), "create a new reader");
ok(reader_go_to_page(r, 55), "can turn the page");
ok(r->page == 55, "page turned to the right one");
Should print out:
ok 1 - create a new reader
ok 2 - can turn the page
ok 3 - page turned to the right one
On failure, a diagnostic message will be printed out.
not ok 3 - page turned to the right one
# Failed test 'page turned to the right one'
# at reader.c line 13.
- is(got, expected)
- is(got, expected, fmt, ...)
- isnt(got, unexpected)
- isnt(got, unexpected, fmt, ...)
Tests that the string you got is what you expected. with isnt, it is the
reverse.
is("this", "that", "this is that");
prints:
not ok 1 - this is that
# Failed test 'this is that'
# at is.c line 6.
# got: 'this'
# expected: 'that'
- cmp_ok(a, op, b)
- cmp_ok(a, op, b, fmt, ...)
Compares two ints with any binary operator that doesn't require an lvalue.
This is nice to use since it provides a better error message than an
equivalent ok.
cmp_ok(420, ">", 666);
prints:
not ok 1
# Failed test at cmpok.c line 5.
# 420
# >
# 666
- cmp_mem(got, expected, n)
- cmp_mem(got, expected, n, fmt, ...)
Tests that the first n bytes of the memory you got is what you expected.
- You have to take care that the pointers are valid and n is not greater than
- the the amount of memory allocated for either got or expected.
+ NULL pointers for got and expected are handled (if either or both are NULL,
+ the test fails), but you need to ensure n is not too large.
char *a = "foo";
char *b = "bar";
cmp_mem(a, b, 3)
prints
not ok 1
# Failed test at t/cmp_mem.c line 9.
# Difference starts at offset 0
- # got: '0x66'
- # expected: '0x62'
+ # got: 0x66
+ # expected: 0x62
- like(got, expected)
- like(got, expected, fmt, ...)
- unlike(got, unexpected)
- unlike(got, unexpected, fmt, ...)
Tests that the string you got matches the expected extended POSIX regex.
unlike is the reverse. These macros are the equivalent of a skip on
Windows.
like("stranger", "^s.(r).*\\1$", "matches the regex");
prints:
ok 1 - matches the regex
- pass()
- pass(fmt, ...)
- fail()
- fail(fmt, ...)
Speciy that a test succeeded or failed. Use these when the statement is
longer than you can fit into the argument given to an ok() test.
- dies_ok(code)
- dies_ok(code, fmt, ...)
- lives_ok(code)
- lives_ok(code, fmt, ...)
Tests whether the given code causes your program to exit. The code gets
passed to a macro that will test it in a forked process. If the code
succeeds it will be executed in the parent process. You can test things
like passing a function a null pointer and make sure it doesnt
dereference it and crash.
dies_ok({abort();}, "abort does close your program");
dies_ok({int x = 0/0;}, "divide by zero crash");
lives_ok({pow(3.0, 5.0);}, "nothing wrong with taking 3**5");
On Windows, these macros are the equivalent of a skip.
- done_testing()
Summarizes the tests that occurred and exits the main function. If
there was no plan, it will print out the number of tests as.
1..5
It will also print a diagnostic message about how many
failures there were.
# Looks like you failed 2 tests of 3 run.
If all planned tests were successful, it will return 0. If any test fails,
it will return the number of failed tests (including ones that were
missing). If they all passed, but there were missing tests, it will return
255.
- note(fmt, ...)
- diag(fmt, ...)
print out a message to the tap output. note prints to stdout and diag
prints to stderr. Each line is preceeded by a "# " so that you know its a
diagnostic message.
note("This is\na note\nto describe\nsomething.");
prints:
# This is
# a note
# to describe
# something
ok() and these functions return ints so you can use them like:
ok(1) && note("yo!");
ok(0) || diag("I have no idea what just happened");
- skip(test, n)
- skip(test, n, fmt, ...)
- end_skip
Skip a series of n tests if test is true. You may give a reason why you are
skipping them or not. The (possibly) skipped tests must occur between the
skip and end_skip macros.
skip(TRUE, 2);
ok(1);
ok(0);
end_skip;
prints:
ok 1 # skip
ok 2 # skip
- todo()
- todo(fmt, ...)
- end_todo
Specifies a series of tests that you expect to fail because they are not
yet implemented.
todo()
ok(0);
end_todo;
prints:
not ok 1 # TODO
# Failed (TODO) test at todo.c line 7
- BAIL_OUT()
- BAIL_OUT(fmt, ...)
Immediately stops all testing.
BAIL_OUT("Can't go no further");
prints
Bail out! Can't go no further
and exits with 255.
diff --git a/t/cmp_mem.c b/t/cmp_mem.c
index 2bb40e9..2d7d160 100644
--- a/t/cmp_mem.c
+++ b/t/cmp_mem.c
@@ -1,16 +1,19 @@
#include "tap.h"
int main () {
setvbuf(stdout, NULL, _IONBF, 0);
unsigned char all_0[] = { 0, 0, 0, 0 };
unsigned char all_255[] = { 255, 255, 255, 255 };
unsigned char half[] = { 0, 0, 255, 255 };
- plan(4);
+ plan(7);
cmp_mem(all_0, all_0, 4, "Array must be equal to itself");
cmp_mem(all_0, all_255, 4, "Arrays with different contents");
cmp_mem(all_0, half, 4, "Arrays differ, but start the same");
cmp_mem(all_0, all_255, 0, "Comparing 0 bytes of different arrays");
+ cmp_mem(NULL, all_0, 4, "got == NULL");
+ cmp_mem(all_0, NULL, 4, "expected == NULL");
+ cmp_mem(NULL, NULL, 4, "got == expected == NULL");
done_testing();
}
diff --git a/t/test.t b/t/test.t
index 90d74e8..726e67f 100755
--- a/t/test.t
+++ b/t/test.t
@@ -1,236 +1,254 @@
#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 10;
use Test::Differences;
my $x = $^O eq 'MSWin32' ? ".exe" : "";
sub cmd_eq_or_diff {
my ($command, $expected) = @_;
my $output = `$command$x 2>&1`;
eq_or_diff($output, $expected, $command);
}
cmd_eq_or_diff "t/cmpok", <<END;
1..9
not ok 1
# Failed test at t/cmpok.c line 6.
# 420
# >
# 666
not ok 2 - the number 23 is definitely 55
# Failed test 'the number 23 is definitely 55'
# at t/cmpok.c line 7.
# 23
# ==
# 55
not ok 3
# Failed test at t/cmpok.c line 8.
# 23
# ==
# 55
ok 4
# unrecognized operator 'frob'
not ok 5
# Failed test at t/cmpok.c line 10.
# 23
# frob
# 55
ok 6
not ok 7
# Failed test at t/cmpok.c line 12.
# 55
# +
# -55
ok 8
not ok 9
# Failed test at t/cmpok.c line 14.
# 55
# %
# 5
# Looks like you failed 6 tests of 9 run.
END
cmd_eq_or_diff "t/cmp_mem", <<END;
-1..4
+1..7
ok 1 - Array must be equal to itself
not ok 2 - Arrays with different contents
# Failed test 'Arrays with different contents'
# at t/cmp_mem.c line 11.
# Difference starts at offset 0
-# got: '0x0'
-# expected: '0xff'
+# got: 0x00
+# expected: 0xff
not ok 3 - Arrays differ, but start the same
# Failed test 'Arrays differ, but start the same'
# at t/cmp_mem.c line 12.
# Difference starts at offset 2
-# got: '0x0'
-# expected: '0xff'
+# got: 0x00
+# expected: 0xff
ok 4 - Comparing 0 bytes of different arrays
-# Looks like you failed 2 tests of 4 run.
+not ok 5 - got == NULL
+# Failed test 'got == NULL'
+# at t/cmp_mem.c line 14.
+# got and/or expected are NULL
+# got: NULL
+# expected: not NULL
+not ok 6 - expected == NULL
+# Failed test 'expected == NULL'
+# at t/cmp_mem.c line 15.
+# got and/or expected are NULL
+# got: not NULL
+# expected: NULL
+not ok 7 - got == expected == NULL
+# Failed test 'got == expected == NULL'
+# at t/cmp_mem.c line 16.
+# got and/or expected are NULL
+# got: NULL
+# expected: NULL
+# Looks like you failed 5 tests of 7 run.
END
cmd_eq_or_diff "t/diesok", <<END;
1..5
ok 1 - sanity
ok 2 - can't divide by zero
ok 3 - this is a perfectly fine statement
ok 4 - abort kills the program
ok 5 - supress output
END
cmd_eq_or_diff "t/is", <<END;
1..18
not ok 1 - this is that
# Failed test 'this is that'
# at t/is.c line 6.
# got: 'this'
# expected: 'that'
ok 2 - this is this
not ok 3
# Failed test at t/is.c line 8.
# got: 'this'
# expected: 'that'
ok 4
ok 5 - null is null
not ok 6 - null is this
# Failed test 'null is this'
# at t/is.c line 11.
# got: '(null)'
# expected: 'this'
not ok 7 - this is null
# Failed test 'this is null'
# at t/is.c line 12.
# got: 'this'
# expected: '(null)'
not ok 8
# Failed test at t/is.c line 13.
# got: 'foo
# foo
# foo'
# expected: 'bar
# bar
# bar'
ok 9
ok 10 - this isnt that
not ok 11 - this isnt this
# Failed test 'this isnt this'
# at t/is.c line 16.
# got: 'this'
# expected: anything else
ok 12
not ok 13
# Failed test at t/is.c line 18.
# got: 'this'
# expected: anything else
not ok 14 - null isnt null
# Failed test 'null isnt null'
# at t/is.c line 19.
# got: '(null)'
# expected: anything else
ok 15 - null isnt this
ok 16 - this isnt null
ok 17
not ok 18
# Failed test at t/is.c line 23.
# got: 'foo
# foo
# foo'
# expected: anything else
# Looks like you failed 9 tests of 18 run.
END
cmd_eq_or_diff "t/like", <<END;
1..3
ok 1 - strange ~~ /range/
ok 2 - strange !~~ /anger/
ok 3 - matches the regex
END
cmd_eq_or_diff "t/notediag", <<END;
# note no new line
# note new line
# diag no new line
# diag new line
END
cmd_eq_or_diff "t/simple", <<END;
1..24
ok 1
ok 2
ok 3
not ok 4
# Failed test at t/simple.c line 9.
ok 5 - foo
ok 6 - bar
ok 7 - baz
ok 8 - quux
ok 9 - thud
ok 10 - wombat
ok 11 - blurgle
ok 12 - frob
not ok 13 - frobnicate
# Failed test 'frobnicate'
# at t/simple.c line 18.
ok 14 - eek
ok 15 - ook
ok 16 - frodo
ok 17 - bilbo
ok 18 - wubble
ok 19 - flarp
ok 20 - fnord
ok 21
not ok 22
# Failed test at t/simple.c line 27.
ok 23 - good
not ok 24 - bad
# Failed test 'bad'
# at t/simple.c line 29.
# Looks like you failed 4 tests of 24 run.
END
cmd_eq_or_diff "t/skip", <<END;
1..8
ok 1 - quux
ok 2 - thud
ok 3 - wombat
ok 4 # skip need to be on windows
ok 5 - quux
ok 6 - thud
ok 7 - wombat
ok 8 # skip
END
cmd_eq_or_diff "t/synopsis", <<END;
1..5
ok 1
not ok 2 - two different strings not that way?
# Failed test 'two different strings not that way?'
# at t/synopsis.c line 7.
# got: 'fnord'
# expected: 'eek'
ok 3 - 3 <= 8732
ok 4
not ok 5
# Failed test at t/synopsis.c line 10.
# 3
# >=
# 10
# Looks like you failed 2 tests of 5 run.
END
cmd_eq_or_diff "t/todo", <<END;
1..6
not ok 1 - foo # TODO
# Failed (TODO) test 'foo'
# at t/todo.c line 7.
ok 2 - bar # TODO
ok 3 - baz # TODO
not ok 4 - quux # TODO im not ready
# Failed (TODO) test 'quux'
# at t/todo.c line 12.
ok 5 - thud # TODO im not ready
ok 6 - wombat # TODO im not ready
END
diff --git a/tap.c b/tap.c
index 46eeaa6..ae23a24 100644
--- a/tap.c
+++ b/tap.c
@@ -1,359 +1,374 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the GPLv2 or any later version
*/
#define _BSD_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
if (!str) {
perror("malloc error");
exit(1);
}
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
tap_plan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
note("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
if (!test)
printf("not ");
printf("ok %d", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
fprintf(stderr, "# Failed ");
if (todo_mesg)
fprintf(stderr, "(TODO) ");
fprintf(stderr, "test ");
if (*name)
fprintf(stderr, "'%s'\n# ", name);
fprintf(stderr, "at %s line %d.\n", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
int
cmp_mem_at_loc (const char *file, int line, const void *got,
const void *expected, size_t n, const char *fmt, ...)
{
- int test = !memcmp(got, expected, n);
+ int i = 0;
+ int test = 1; /* assume success */
+
+ if ((got == NULL) || (expected == NULL)) {
+ test = 0;
+ }
+ else if (got != expected) {
+ /* got and expected point to different memory: compare byte per byte */
+ for (i = 0; i < n; ++i) {
+ if (((char *)got)[i] != ((char *)expected)[i]) {
+ test = 0;
+ break;
+ }
+ }
+ }
+
va_list args;
va_start(args, fmt);
vok_at_loc(file, line, test, fmt, args);
va_end(args);
if (!test) {
- const unsigned char *a = got;
- const unsigned char *b = expected;
- int i = 0;
-
- while (*(a++) == *(b++))
- ++i;
- /* a and b point to 1 position after first different value */
- diag(" Difference starts at offset %d", i);
- diag(" got: '0x%x'", *(--a));
- diag(" expected: '0x%x'", *(--b));
+ if ((got == NULL) || (expected == NULL)) {
+ diag(" got and/or expected are NULL");
+ diag(" got: %s", got ? "not NULL" : "NULL");
+ diag(" expected: %s", expected ? "not NULL" : "NULL");
+ }
+ else {
+ diag(" Difference starts at offset %d", i);
+ diag(" got: 0x%02x", ((unsigned char *)got)[i]);
+ diag(" expected: 0x%02x", ((unsigned char *)expected)[i]);
+ }
}
return test;
}
static void
vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
char *mesg, *line;
int i;
if (!fmt)
return;
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
fprintf(fh, "# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
return;
}
int
diag (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stderr, fmt, args);
va_end(args);
return 0;
}
int
note (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stdout, fmt, args);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 255;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
if (expected_tests == NO_PLAN)
retval = failed_tests;
else
retval = expected_tests - current_test + failed_tests;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
tap_skip (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
note("skip %s\n", why);
}
free(why);
}
void
tap_todo (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
tap_end_todo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
#if defined __APPLE__ || defined BSD
#define MAP_ANONYMOUS MAP_ANON
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros. */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
|
zorgnax/libtap
|
1796a0d15d69d817cd3f72672337a5ec9353f291
|
Fix whitespace
|
diff --git a/tap.c b/tap.c
index 27ebec8..46eeaa6 100644
--- a/tap.c
+++ b/tap.c
@@ -1,359 +1,359 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the GPLv2 or any later version
*/
#define _BSD_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
if (!str) {
perror("malloc error");
exit(1);
}
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
tap_plan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
note("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
if (!test)
printf("not ");
printf("ok %d", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
fprintf(stderr, "# Failed ");
if (todo_mesg)
fprintf(stderr, "(TODO) ");
fprintf(stderr, "test ");
if (*name)
fprintf(stderr, "'%s'\n# ", name);
fprintf(stderr, "at %s line %d.\n", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
int
-cmp_mem_at_loc(const char *file, int line, const void *got,
- const void *expected, size_t n, const char *fmt, ...)
+cmp_mem_at_loc (const char *file, int line, const void *got,
+ const void *expected, size_t n, const char *fmt, ...)
{
int test = !memcmp(got, expected, n);
va_list args;
va_start(args, fmt);
vok_at_loc(file, line, test, fmt, args);
va_end(args);
if (!test) {
const unsigned char *a = got;
const unsigned char *b = expected;
int i = 0;
while (*(a++) == *(b++))
++i;
/* a and b point to 1 position after first different value */
diag(" Difference starts at offset %d", i);
diag(" got: '0x%x'", *(--a));
diag(" expected: '0x%x'", *(--b));
}
return test;
}
static void
vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
char *mesg, *line;
int i;
if (!fmt)
return;
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
fprintf(fh, "# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
return;
}
int
diag (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stderr, fmt, args);
va_end(args);
return 0;
}
int
note (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stdout, fmt, args);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 255;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
if (expected_tests == NO_PLAN)
retval = failed_tests;
else
retval = expected_tests - current_test + failed_tests;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
tap_skip (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
note("skip %s\n", why);
}
free(why);
}
void
tap_todo (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
tap_end_todo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
#if defined __APPLE__ || defined BSD
#define MAP_ANONYMOUS MAP_ANON
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros. */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
|
zorgnax/libtap
|
433c24900fd19bb68e49de74e7d6972ed09da92d
|
Add cmp_mem test
|
diff --git a/README.md b/README.md
index b241e5d..449388c 100644
--- a/README.md
+++ b/README.md
@@ -1,245 +1,264 @@
NAME
====
libtap - Write tests in C
SYNOPSIS
========
#include <tap.h>
int main () {
plan(5);
ok(3 == 3);
is("fnord", "eek", "two different strings not that way?");
ok(3 <= 8732, "%d <= %d", 3, 8732);
like("fnord", "f(yes|no)r*[a-f]$");
cmp_ok(3, ">=", 10);
done_testing();
}
results in:
1..5
ok 1
not ok 2 - two different strings not that way?
# Failed test 'two different strings not that way?'
# at t/synopsis.c line 7.
# got: 'fnord'
# expected: 'eek'
ok 3 - 3 <= 8732
ok 4
not ok 5
# Failed test at t/synopsis.c line 10.
# 3
# >=
# 10
# Looks like you failed 2 tests of 5 run.
DESCRIPTION
===========
tap is an easy to read and easy to write way of creating tests for your
software. This library creates functions that can be used to generate it for
your C programs. It is mostly based on the Test::More Perl module.
FUNCTIONS
=========
- plan(tests)
- plan(NO_PLAN)
- plan(SKIP_ALL);
- plan(SKIP_ALL, fmt, ...)
Use this to start a series of tests. When you know how many tests there
will be, you can put a number as a number of tests you expect to run. If
you do not know how many tests there will be, you can use plan(NO_PLAN)
or not call this function. When you pass it a number of tests to run, a
message similar to the following will appear in the output:
1..5
If you pass it SKIP_ALL, the whole test will be skipped.
- ok(test)
- ok(test, fmt, ...)
Specify a test. the test can be any statement returning a true or false
value. You may optionally pass a format string describing the test.
ok(r = reader_new("Of Mice and Men"), "create a new reader");
ok(reader_go_to_page(r, 55), "can turn the page");
ok(r->page == 55, "page turned to the right one");
Should print out:
ok 1 - create a new reader
ok 2 - can turn the page
ok 3 - page turned to the right one
On failure, a diagnostic message will be printed out.
not ok 3 - page turned to the right one
# Failed test 'page turned to the right one'
# at reader.c line 13.
- is(got, expected)
- is(got, expected, fmt, ...)
- isnt(got, unexpected)
- isnt(got, unexpected, fmt, ...)
Tests that the string you got is what you expected. with isnt, it is the
reverse.
is("this", "that", "this is that");
prints:
not ok 1 - this is that
# Failed test 'this is that'
# at is.c line 6.
# got: 'this'
# expected: 'that'
- cmp_ok(a, op, b)
- cmp_ok(a, op, b, fmt, ...)
Compares two ints with any binary operator that doesn't require an lvalue.
This is nice to use since it provides a better error message than an
equivalent ok.
cmp_ok(420, ">", 666);
prints:
not ok 1
# Failed test at cmpok.c line 5.
# 420
# >
# 666
+- cmp_mem(got, expected, n)
+- cmp_mem(got, expected, n, fmt, ...)
+
+ Tests that the first n bytes of the memory you got is what you expected.
+ You have to take care that the pointers are valid and n is not greater than
+ the the amount of memory allocated for either got or expected.
+
+ char *a = "foo";
+ char *b = "bar";
+ cmp_mem(a, b, 3)
+
+ prints
+
+ not ok 1
+ # Failed test at t/cmp_mem.c line 9.
+ # Difference starts at offset 0
+ # got: '0x66'
+ # expected: '0x62'
+
- like(got, expected)
- like(got, expected, fmt, ...)
- unlike(got, unexpected)
- unlike(got, unexpected, fmt, ...)
Tests that the string you got matches the expected extended POSIX regex.
unlike is the reverse. These macros are the equivalent of a skip on
Windows.
like("stranger", "^s.(r).*\\1$", "matches the regex");
prints:
ok 1 - matches the regex
- pass()
- pass(fmt, ...)
- fail()
- fail(fmt, ...)
Speciy that a test succeeded or failed. Use these when the statement is
longer than you can fit into the argument given to an ok() test.
- dies_ok(code)
- dies_ok(code, fmt, ...)
- lives_ok(code)
- lives_ok(code, fmt, ...)
Tests whether the given code causes your program to exit. The code gets
passed to a macro that will test it in a forked process. If the code
succeeds it will be executed in the parent process. You can test things
like passing a function a null pointer and make sure it doesnt
dereference it and crash.
dies_ok({abort();}, "abort does close your program");
dies_ok({int x = 0/0;}, "divide by zero crash");
lives_ok({pow(3.0, 5.0);}, "nothing wrong with taking 3**5");
On Windows, these macros are the equivalent of a skip.
- done_testing()
Summarizes the tests that occurred and exits the main function. If
there was no plan, it will print out the number of tests as.
1..5
It will also print a diagnostic message about how many
failures there were.
# Looks like you failed 2 tests of 3 run.
If all planned tests were successful, it will return 0. If any test fails,
it will return the number of failed tests (including ones that were
missing). If they all passed, but there were missing tests, it will return
255.
- note(fmt, ...)
- diag(fmt, ...)
print out a message to the tap output. note prints to stdout and diag
prints to stderr. Each line is preceeded by a "# " so that you know its a
diagnostic message.
note("This is\na note\nto describe\nsomething.");
prints:
# This is
# a note
# to describe
# something
ok() and these functions return ints so you can use them like:
ok(1) && note("yo!");
ok(0) || diag("I have no idea what just happened");
- skip(test, n)
- skip(test, n, fmt, ...)
- end_skip
Skip a series of n tests if test is true. You may give a reason why you are
skipping them or not. The (possibly) skipped tests must occur between the
skip and end_skip macros.
skip(TRUE, 2);
ok(1);
ok(0);
end_skip;
prints:
ok 1 # skip
ok 2 # skip
- todo()
- todo(fmt, ...)
- end_todo
Specifies a series of tests that you expect to fail because they are not
yet implemented.
todo()
ok(0);
end_todo;
prints:
not ok 1 # TODO
# Failed (TODO) test at todo.c line 7
- BAIL_OUT()
- BAIL_OUT(fmt, ...)
Immediately stops all testing.
BAIL_OUT("Can't go no further");
prints
Bail out! Can't go no further
and exits with 255.
diff --git a/t/cmp_mem.c b/t/cmp_mem.c
new file mode 100644
index 0000000..2bb40e9
--- /dev/null
+++ b/t/cmp_mem.c
@@ -0,0 +1,16 @@
+#include "tap.h"
+
+int main () {
+ setvbuf(stdout, NULL, _IONBF, 0);
+ unsigned char all_0[] = { 0, 0, 0, 0 };
+ unsigned char all_255[] = { 255, 255, 255, 255 };
+ unsigned char half[] = { 0, 0, 255, 255 };
+
+ plan(4);
+ cmp_mem(all_0, all_0, 4, "Array must be equal to itself");
+ cmp_mem(all_0, all_255, 4, "Arrays with different contents");
+ cmp_mem(all_0, half, 4, "Arrays differ, but start the same");
+ cmp_mem(all_0, all_255, 0, "Comparing 0 bytes of different arrays");
+ done_testing();
+}
+
diff --git a/t/test.t b/t/test.t
index 6dbafdf..90d74e8 100755
--- a/t/test.t
+++ b/t/test.t
@@ -1,217 +1,236 @@
#!/usr/bin/perl
use strict;
use warnings;
-use Test::More tests => 9;
+use Test::More tests => 10;
use Test::Differences;
my $x = $^O eq 'MSWin32' ? ".exe" : "";
sub cmd_eq_or_diff {
my ($command, $expected) = @_;
my $output = `$command$x 2>&1`;
eq_or_diff($output, $expected, $command);
}
cmd_eq_or_diff "t/cmpok", <<END;
1..9
not ok 1
# Failed test at t/cmpok.c line 6.
# 420
# >
# 666
not ok 2 - the number 23 is definitely 55
# Failed test 'the number 23 is definitely 55'
# at t/cmpok.c line 7.
# 23
# ==
# 55
not ok 3
# Failed test at t/cmpok.c line 8.
# 23
# ==
# 55
ok 4
# unrecognized operator 'frob'
not ok 5
# Failed test at t/cmpok.c line 10.
# 23
# frob
# 55
ok 6
not ok 7
# Failed test at t/cmpok.c line 12.
# 55
# +
# -55
ok 8
not ok 9
# Failed test at t/cmpok.c line 14.
# 55
# %
# 5
# Looks like you failed 6 tests of 9 run.
END
+cmd_eq_or_diff "t/cmp_mem", <<END;
+1..4
+ok 1 - Array must be equal to itself
+not ok 2 - Arrays with different contents
+# Failed test 'Arrays with different contents'
+# at t/cmp_mem.c line 11.
+# Difference starts at offset 0
+# got: '0x0'
+# expected: '0xff'
+not ok 3 - Arrays differ, but start the same
+# Failed test 'Arrays differ, but start the same'
+# at t/cmp_mem.c line 12.
+# Difference starts at offset 2
+# got: '0x0'
+# expected: '0xff'
+ok 4 - Comparing 0 bytes of different arrays
+# Looks like you failed 2 tests of 4 run.
+END
+
cmd_eq_or_diff "t/diesok", <<END;
1..5
ok 1 - sanity
ok 2 - can't divide by zero
ok 3 - this is a perfectly fine statement
ok 4 - abort kills the program
ok 5 - supress output
END
cmd_eq_or_diff "t/is", <<END;
1..18
not ok 1 - this is that
# Failed test 'this is that'
# at t/is.c line 6.
# got: 'this'
# expected: 'that'
ok 2 - this is this
not ok 3
# Failed test at t/is.c line 8.
# got: 'this'
# expected: 'that'
ok 4
ok 5 - null is null
not ok 6 - null is this
# Failed test 'null is this'
# at t/is.c line 11.
# got: '(null)'
# expected: 'this'
not ok 7 - this is null
# Failed test 'this is null'
# at t/is.c line 12.
# got: 'this'
# expected: '(null)'
not ok 8
# Failed test at t/is.c line 13.
# got: 'foo
# foo
# foo'
# expected: 'bar
# bar
# bar'
ok 9
ok 10 - this isnt that
not ok 11 - this isnt this
# Failed test 'this isnt this'
# at t/is.c line 16.
# got: 'this'
# expected: anything else
ok 12
not ok 13
# Failed test at t/is.c line 18.
# got: 'this'
# expected: anything else
not ok 14 - null isnt null
# Failed test 'null isnt null'
# at t/is.c line 19.
# got: '(null)'
# expected: anything else
ok 15 - null isnt this
ok 16 - this isnt null
ok 17
not ok 18
# Failed test at t/is.c line 23.
# got: 'foo
# foo
# foo'
# expected: anything else
# Looks like you failed 9 tests of 18 run.
END
cmd_eq_or_diff "t/like", <<END;
1..3
ok 1 - strange ~~ /range/
ok 2 - strange !~~ /anger/
ok 3 - matches the regex
END
cmd_eq_or_diff "t/notediag", <<END;
# note no new line
# note new line
# diag no new line
# diag new line
END
cmd_eq_or_diff "t/simple", <<END;
1..24
ok 1
ok 2
ok 3
not ok 4
# Failed test at t/simple.c line 9.
ok 5 - foo
ok 6 - bar
ok 7 - baz
ok 8 - quux
ok 9 - thud
ok 10 - wombat
ok 11 - blurgle
ok 12 - frob
not ok 13 - frobnicate
# Failed test 'frobnicate'
# at t/simple.c line 18.
ok 14 - eek
ok 15 - ook
ok 16 - frodo
ok 17 - bilbo
ok 18 - wubble
ok 19 - flarp
ok 20 - fnord
ok 21
not ok 22
# Failed test at t/simple.c line 27.
ok 23 - good
not ok 24 - bad
# Failed test 'bad'
# at t/simple.c line 29.
# Looks like you failed 4 tests of 24 run.
END
cmd_eq_or_diff "t/skip", <<END;
1..8
ok 1 - quux
ok 2 - thud
ok 3 - wombat
ok 4 # skip need to be on windows
ok 5 - quux
ok 6 - thud
ok 7 - wombat
ok 8 # skip
END
cmd_eq_or_diff "t/synopsis", <<END;
1..5
ok 1
not ok 2 - two different strings not that way?
# Failed test 'two different strings not that way?'
# at t/synopsis.c line 7.
# got: 'fnord'
# expected: 'eek'
ok 3 - 3 <= 8732
ok 4
not ok 5
# Failed test at t/synopsis.c line 10.
# 3
# >=
# 10
# Looks like you failed 2 tests of 5 run.
END
cmd_eq_or_diff "t/todo", <<END;
1..6
not ok 1 - foo # TODO
# Failed (TODO) test 'foo'
# at t/todo.c line 7.
ok 2 - bar # TODO
ok 3 - baz # TODO
not ok 4 - quux # TODO im not ready
# Failed (TODO) test 'quux'
# at t/todo.c line 12.
ok 5 - thud # TODO im not ready
ok 6 - wombat # TODO im not ready
END
diff --git a/tap.c b/tap.c
index 560b97c..27ebec8 100644
--- a/tap.c
+++ b/tap.c
@@ -1,334 +1,359 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the GPLv2 or any later version
*/
#define _BSD_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
if (!str) {
perror("malloc error");
exit(1);
}
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
tap_plan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
note("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
if (!test)
printf("not ");
printf("ok %d", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
fprintf(stderr, "# Failed ");
if (todo_mesg)
fprintf(stderr, "(TODO) ");
fprintf(stderr, "test ");
if (*name)
fprintf(stderr, "'%s'\n# ", name);
fprintf(stderr, "at %s line %d.\n", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
+int
+cmp_mem_at_loc(const char *file, int line, const void *got,
+ const void *expected, size_t n, const char *fmt, ...)
+{
+ int test = !memcmp(got, expected, n);
+ va_list args;
+ va_start(args, fmt);
+ vok_at_loc(file, line, test, fmt, args);
+ va_end(args);
+ if (!test) {
+ const unsigned char *a = got;
+ const unsigned char *b = expected;
+ int i = 0;
+
+ while (*(a++) == *(b++))
+ ++i;
+
+ /* a and b point to 1 position after first different value */
+ diag(" Difference starts at offset %d", i);
+ diag(" got: '0x%x'", *(--a));
+ diag(" expected: '0x%x'", *(--b));
+ }
+ return test;
+}
+
static void
vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
char *mesg, *line;
int i;
if (!fmt)
return;
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
fprintf(fh, "# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
return;
}
int
diag (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stderr, fmt, args);
va_end(args);
return 0;
}
int
note (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stdout, fmt, args);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 255;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
if (expected_tests == NO_PLAN)
retval = failed_tests;
else
retval = expected_tests - current_test + failed_tests;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
tap_skip (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
note("skip %s\n", why);
}
free(why);
}
void
tap_todo (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
tap_end_todo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
#if defined __APPLE__ || defined BSD
#define MAP_ANONYMOUS MAP_ANON
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros. */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
diff --git a/tap.h b/tap.h
index c7af8b5..302e6d8 100644
--- a/tap.h
+++ b/tap.h
@@ -1,114 +1,117 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the GPLv2 or any later version
*/
#ifndef __TAP_H__
#define __TAP_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifndef va_copy
#ifdef __va_copy
#define va_copy __va_copy
#else
#define va_copy(d, s) ((d) = (s))
#endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args);
int ok_at_loc (const char *file, int line, int test, const char *fmt,
...);
int is_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int isnt_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int cmp_ok_at_loc (const char *file, int line, int a, const char *op,
int b, const char *fmt, ...);
+int cmp_mem_at_loc (const char *file, int line, const void *got,
+ const void *expected, size_t n, const char *fmt, ...);
int bail_out (int ignore, const char *fmt, ...);
void tap_plan (int tests, const char *fmt, ...);
int diag (const char *fmt, ...);
int note (const char *fmt, ...);
int exit_status (void);
void tap_skip (int n, const char *fmt, ...);
void tap_todo (int ignore, const char *fmt, ...);
void tap_end_todo (void);
#define NO_PLAN -1
#define SKIP_ALL -2
#define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
+#define cmp_mem(...) cmp_mem_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL);
#define plan(...) tap_plan(__VA_ARGS__, NULL)
#define done_testing() return exit_status()
#define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
#define pass(...) ok(1, "" __VA_ARGS__)
#define fail(...) ok(0, "" __VA_ARGS__)
#define skip(test, ...) do {if (test) {tap_skip(__VA_ARGS__, NULL); break;}
#define end_skip } while (0)
#define todo(...) tap_todo(0, "" __VA_ARGS__, NULL)
#define end_todo tap_end_todo()
#define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
#define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
#ifdef _WIN32
#define like(...) tap_skip(1, "like is not implemented on Windows")
#define unlike tap_skip(1, "unlike is not implemented on Windows")
#define dies_ok_common(...) \
tap_skip(1, "Death detection is not supported on Windows")
#else
#define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
#define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
int like_at_loc (int for_match, const char *file, int line,
const char *got, const char *expected,
const char *fmt, ...);
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int tap_test_died (int status);
#define dies_ok_common(for_death, code, ...) \
do { \
int cpid; \
int it_died; \
tap_test_died(1); \
cpid = fork(); \
switch (cpid) { \
case -1: \
perror("fork error"); \
exit(1); \
case 0: \
close(1); \
close(2); \
code \
tap_test_died(0); \
exit(0); \
} \
if (waitpid(cpid, NULL, 0) < 0) { \
perror("waitpid error"); \
exit(1); \
} \
it_died = tap_test_died(0); \
if (!it_died) \
{code} \
ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \
} while (0)
#endif
#ifdef __cplusplus
}
#endif
#endif
|
zorgnax/libtap
|
959a1126967da00f672a7bc71e6f11f6d07f81f5
|
Replace ternary operations with if statements
|
diff --git a/tap.c b/tap.c
index 904c4c1..560b97c 100644
--- a/tap.c
+++ b/tap.c
@@ -1,331 +1,334 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the GPLv2 or any later version
*/
#define _BSD_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
if (!str) {
perror("malloc error");
exit(1);
}
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
tap_plan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
note("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
- printf("%sok %d", test ? "" : "not ", ++current_test);
+ if (!test)
+ printf("not ");
+ printf("ok %d", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
+ fprintf(stderr, "# Failed ");
+ if (todo_mesg)
+ fprintf(stderr, "(TODO) ");
+ fprintf(stderr, "test ");
if (*name)
- diag(" Failed%s test '%s'\n at %s line %d.",
- todo_mesg ? " (TODO)" : "", name, file, line);
- else
- diag(" Failed%s test at %s line %d.",
- todo_mesg ? " (TODO)" : "", file, line);
+ fprintf(stderr, "'%s'\n# ", name);
+ fprintf(stderr, "at %s line %d.\n", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static void
vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
char *mesg, *line;
int i;
if (!fmt)
return;
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
fprintf(fh, "# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
return;
}
int
diag (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stderr, fmt, args);
va_end(args);
return 0;
}
int
note (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stdout, fmt, args);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 255;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
if (expected_tests == NO_PLAN)
retval = failed_tests;
else
retval = expected_tests - current_test + failed_tests;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
tap_skip (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
note("skip %s\n", why);
}
free(why);
}
void
tap_todo (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
tap_end_todo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
#if defined __APPLE__ || defined BSD
#define MAP_ANONYMOUS MAP_ANON
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros. */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
|
zorgnax/libtap
|
74494abafb18bd5e2d690bbb0416ff05d0ece903
|
Ignore all compiled tests no matter their names
|
diff --git a/.gitignore b/.gitignore
index 64a4dfc..2e45fcb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,14 +1,5 @@
+/t/*
+!/t/*.*
*.a
*.o
*.sw?
-
-# compiled tests
-/t/cmpok
-/t/diesok
-/t/is
-/t/like
-/t/notediag
-/t/simple
-/t/skip
-/t/synopsis
-/t/todo
|
zorgnax/libtap
|
0b06bea3a3e16651c0bbd7b3174752c2145535c4
|
Define _BSD_SOURCE to 1
|
diff --git a/tap.c b/tap.c
index d731f6c..51e2e8d 100644
--- a/tap.c
+++ b/tap.c
@@ -1,329 +1,331 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the GPLv2
*/
+#define _BSD_SOURCE 1
+
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
if (!str) {
perror("malloc error");
exit(1);
}
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
tap_plan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
note("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
printf("%sok %d", test ? "" : "not ", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
if (*name)
diag(" Failed%s test '%s'\n at %s line %d.",
todo_mesg ? " (TODO)" : "", name, file, line);
else
diag(" Failed%s test at %s line %d.",
todo_mesg ? " (TODO)" : "", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static void
vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
char *mesg, *line;
int i;
if (!fmt)
return;
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
fprintf(fh, "# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
return;
}
int
diag (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stderr, fmt, args);
va_end(args);
return 0;
}
int
note (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stdout, fmt, args);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 255;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
if (expected_tests == NO_PLAN)
retval = failed_tests;
else
retval = expected_tests - current_test + failed_tests;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
tap_skip (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
note("skip %s\n", why);
}
free(why);
}
void
tap_todo (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
tap_end_todo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
#if defined __APPLE__ || defined BSD
#define MAP_ANONYMOUS MAP_ANON
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros. */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
|
zorgnax/libtap
|
4d5a11a1c29b3fb5f23b5174e9df47da373248b6
|
Make better naming choices: planf -> tap_plan, skippy -> tap_skip, todof -> tap_todo
|
diff --git a/tap.c b/tap.c
index b28debd..d731f6c 100644
--- a/tap.c
+++ b/tap.c
@@ -1,329 +1,329 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the GPLv2
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
if (!str) {
perror("malloc error");
exit(1);
}
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
-planf (int tests, const char *fmt, ...) {
+tap_plan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
note("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
printf("%sok %d", test ? "" : "not ", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
if (*name)
diag(" Failed%s test '%s'\n at %s line %d.",
todo_mesg ? " (TODO)" : "", name, file, line);
else
diag(" Failed%s test at %s line %d.",
todo_mesg ? " (TODO)" : "", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static void
vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
char *mesg, *line;
int i;
if (!fmt)
return;
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
fprintf(fh, "# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
return;
}
int
diag (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stderr, fmt, args);
va_end(args);
return 0;
}
int
note (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stdout, fmt, args);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 255;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
if (expected_tests == NO_PLAN)
retval = failed_tests;
else
retval = expected_tests - current_test + failed_tests;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
-skippy (int n, const char *fmt, ...) {
+tap_skip (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
note("skip %s\n", why);
}
free(why);
}
void
-todof (int ignore, const char *fmt, ...) {
+tap_todo (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
-end_todof () {
+tap_end_todo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
#if defined __APPLE__ || defined BSD
#define MAP_ANONYMOUS MAP_ANON
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros. */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
diff --git a/tap.h b/tap.h
index 4642345..3586dc3 100644
--- a/tap.h
+++ b/tap.h
@@ -1,114 +1,114 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the GPLv2
*/
#ifndef __TAP_H__
#define __TAP_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifndef va_copy
#ifdef __va_copy
#define va_copy __va_copy
#else
#define va_copy(d, s) ((d) = (s))
#endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args);
int ok_at_loc (const char *file, int line, int test, const char *fmt,
...);
int is_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int isnt_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int cmp_ok_at_loc (const char *file, int line, int a, const char *op,
int b, const char *fmt, ...);
int bail_out (int ignore, const char *fmt, ...);
-void planf (int tests, const char *fmt, ...);
+void tap_plan (int tests, const char *fmt, ...);
int diag (const char *fmt, ...);
int note (const char *fmt, ...);
int exit_status (void);
-void skippy (int n, const char *fmt, ...);
-void todof (int ignore, const char *fmt, ...);
-void end_todof (void);
+void tap_skip (int n, const char *fmt, ...);
+void tap_todo (int ignore, const char *fmt, ...);
+void tap_end_todo (void);
#define NO_PLAN -1
#define SKIP_ALL -2
#define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
-#define plan(...) planf(__VA_ARGS__, NULL)
+#define plan(...) tap_plan(__VA_ARGS__, NULL)
#define done_testing() return exit_status()
#define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
#define pass(...) ok(1, "" __VA_ARGS__)
#define fail(...) ok(0, "" __VA_ARGS__)
-#define skip(test, ...) do {if (test) {skippy(__VA_ARGS__, NULL); break;}
+#define skip(test, ...) do {if (test) {tap_skip(__VA_ARGS__, NULL); break;}
#define end_skip } while (0)
-#define todo(...) todof(0, "" __VA_ARGS__, NULL)
-#define end_todo end_todof()
+#define todo(...) tap_todo(0, "" __VA_ARGS__, NULL)
+#define end_todo tap_end_todo()
#define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
#define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
#ifdef _WIN32
-#define like(...) skippy(1, "like is not implemented on Windows")
-#define unlike like
+#define like(...) tap_skip(1, "like is not implemented on Windows")
+#define unlike tap_skip(1, "unlike is not implemented on Windows")
#define dies_ok_common(...) \
- skippy(1, "Death detection is not supported on Windows")
+ tap_skip(1, "Death detection is not supported on Windows")
#else
#define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
#define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
int like_at_loc (int for_match, const char *file, int line,
const char *got, const char *expected,
const char *fmt, ...);
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int tap_test_died (int status);
#define dies_ok_common(for_death, code, ...) \
do { \
int cpid; \
int it_died; \
tap_test_died(1); \
cpid = fork(); \
switch (cpid) { \
case -1: \
perror("fork error"); \
exit(1); \
case 0: \
close(1); \
close(2); \
code \
tap_test_died(0); \
exit(0); \
} \
if (waitpid(cpid, NULL, 0) < 0) { \
perror("waitpid error"); \
exit(1); \
} \
it_died = tap_test_died(0); \
if (!it_died) \
{code} \
ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \
} while (0)
#endif
#ifdef __cplusplus
}
#endif
#endif
|
zorgnax/libtap
|
3fdd33db63d54e1df75c09aa6d10e0e74743102a
|
Remove autotools support
|
diff --git a/.gitignore b/.gitignore
index 3eb6036..64a4dfc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,33 +1,14 @@
*.a
*.o
*.sw?
# compiled tests
/t/cmpok
/t/diesok
/t/is
/t/like
/t/notediag
/t/simple
/t/skip
/t/synopsis
/t/todo
-
-# autotools
-autom4te.cache/
-configure
-Makefile
-Makefile.in
-aclocal.m4
-config.h*
-config.log
-config.status
-.auto/
-ltmain.sh
-.deps/
-.libs/
-*.la
-*.lo
-libtool
-stamp-h1
-tap.pc
diff --git a/AUTHORS b/AUTHORS
deleted file mode 100644
index 7f1da7c..0000000
--- a/AUTHORS
+++ /dev/null
@@ -1 +0,0 @@
-Jake Gelbman <[email protected]>
diff --git a/ChangeLog b/ChangeLog
deleted file mode 100644
index e69de29..0000000
diff --git a/INSTALL b/INSTALL
index df1f3f2..2ed4543 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,51 +1,42 @@
-To install libtap on a unix-like system you have two ways:
+To install libtap on a unix-like system:
-Use Makefile:
-
- $ make -fMakefile.simple
- $ make -fMakefile.simple check
- $ make -fMakefile.siple install
+ $ make
+ $ make check
+ $ make install
To compile with gcc -ansi, run
- $ make ANSI=1 -fMakefile.simple
-
-Use autotools:
-
- $ autoreconf -i
- $ ./configure
- $ make
- $ make install
+ $ make ANSI=1
On Windows, the library can be created by first setting up
the correct development environment variables. Usually this
is done by running vcvars32.bat included in the visual studio
distribution. You should also install gnu make which can be
found at http://gnuwin32.sourceforge.net/packages/make.htm.
And you should have perl to run the tests although this isnt
absolutely necessary. Once this is done, you should be able to
run the following:
> make -f Makefile.win
> make check
Alternatively, you might want to use the visual studio project file
included by Alexander Kahl (e-user).
If you want to use it directly in another project, you can copy tap.c
and tap.h there and it shouldn't have a problem compiling.
$ ls
tap.c tap.h test.c
$ cat test.c
#include "tap.h"
int main () {
plan(1);
ok(50 + 5, "foo %s", "bar");
done_testing();
}
$ gcc test.c tap.c
$ a.out
1..1
ok 1 - foo bar
diff --git a/Makefile.simple b/Makefile
similarity index 100%
rename from Makefile.simple
rename to Makefile
diff --git a/Makefile.am b/Makefile.am
deleted file mode 100644
index 8a54540..0000000
--- a/Makefile.am
+++ /dev/null
@@ -1,8 +0,0 @@
-SUBDIRS = . t
-
-lib_LTLIBRARIES = libtap.la
-pkgconfig_DATA = tap.pc
-pkgconfigdir = $(libdir)/pkgconfig
-include_HEADERS = tap.h
-libtap_la_SOURCES = tap.c
-
diff --git a/NEWS b/NEWS
deleted file mode 100644
index e69de29..0000000
diff --git a/README b/README.md
similarity index 100%
rename from README
rename to README.md
diff --git a/configure.ac b/configure.ac
deleted file mode 100644
index 39718a4..0000000
--- a/configure.ac
+++ /dev/null
@@ -1,30 +0,0 @@
-# -*- Autoconf -*-
-# Process this file with autoconf to produce a configure script.
-
-AC_PREREQ([2.69])
-AC_INIT([libtap], [0.1.0], [[email protected]])
-AC_CONFIG_SRCDIR([tap.c])
-AC_CONFIG_HEADERS([config.h])
-AC_CONFIG_AUX_DIR([.auto])
-AM_INIT_AUTOMAKE
-
-# Checks for programs.
-AC_PROG_CC
-AC_PROG_INSTALL
-LT_INIT
-
-# Checks for libraries.
-
-# Checks for header files.
-AC_CHECK_HEADERS([stdlib.h string.h sys/param.h unistd.h])
-
-# Checks for typedefs, structures, and compiler characteristics.
-
-# Checks for library functions.
-AC_FUNC_FORK
-AC_FUNC_MALLOC
-AC_FUNC_MMAP
-AC_CHECK_FUNCS([regcomp])
-
-AC_CONFIG_FILES([Makefile t/Makefile tap.pc])
-AC_OUTPUT
diff --git a/t/Makefile.am b/t/Makefile.am
deleted file mode 100644
index d580728..0000000
--- a/t/Makefile.am
+++ /dev/null
@@ -1,12 +0,0 @@
-AM_LDFLAGS = $(top_srcdir)/.libs/libtap.la -static
-
-noinst_PROGRAMS = cmpok diesok is like notediag simple skip synopsis todo
-
-cmpok_SOURCES = cmpok.c
-diesok_SOURCES = diesok.c
-is_SOURCES = is.c
-like_SOURCES = like.c
-notediag_SOURCES = notediag.c
-simple_SOURCES = simple.c
-skip_SOURCES = skip.c
-todo_SOURCES = todo.c
diff --git a/tap.pc.in b/tap.pc.in
deleted file mode 100644
index c42055a..0000000
--- a/tap.pc.in
+++ /dev/null
@@ -1,9 +0,0 @@
-prefix=@prefix@
-libdir=@libdir@
-includedir=@includedir@
-
-Name: tap
-Description: easy to read and write way of creating tests for your software
-Version: @VERSION@
-Libs: -L${libdir} -ltap
-Cflags: -I${includedir}
|
zorgnax/libtap
|
23dec52cee1b083e1cd2c7afa2534c5796c2c364
|
Add autotools support
|
diff --git a/.gitignore b/.gitignore
index 64a4dfc..3eb6036 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,14 +1,33 @@
*.a
*.o
*.sw?
# compiled tests
/t/cmpok
/t/diesok
/t/is
/t/like
/t/notediag
/t/simple
/t/skip
/t/synopsis
/t/todo
+
+# autotools
+autom4te.cache/
+configure
+Makefile
+Makefile.in
+aclocal.m4
+config.h*
+config.log
+config.status
+.auto/
+ltmain.sh
+.deps/
+.libs/
+*.la
+*.lo
+libtool
+stamp-h1
+tap.pc
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..7f1da7c
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
+Jake Gelbman <[email protected]>
diff --git a/ChangeLog b/ChangeLog
new file mode 100644
index 0000000..e69de29
diff --git a/INSTALL b/INSTALL
index 2ed4543..df1f3f2 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,42 +1,51 @@
-To install libtap on a unix-like system:
+To install libtap on a unix-like system you have two ways:
- $ make
- $ make check
- $ make install
+Use Makefile:
+
+ $ make -fMakefile.simple
+ $ make -fMakefile.simple check
+ $ make -fMakefile.siple install
To compile with gcc -ansi, run
- $ make ANSI=1
+ $ make ANSI=1 -fMakefile.simple
+
+Use autotools:
+
+ $ autoreconf -i
+ $ ./configure
+ $ make
+ $ make install
On Windows, the library can be created by first setting up
the correct development environment variables. Usually this
is done by running vcvars32.bat included in the visual studio
distribution. You should also install gnu make which can be
found at http://gnuwin32.sourceforge.net/packages/make.htm.
And you should have perl to run the tests although this isnt
absolutely necessary. Once this is done, you should be able to
run the following:
> make -f Makefile.win
> make check
Alternatively, you might want to use the visual studio project file
included by Alexander Kahl (e-user).
If you want to use it directly in another project, you can copy tap.c
and tap.h there and it shouldn't have a problem compiling.
$ ls
tap.c tap.h test.c
$ cat test.c
#include "tap.h"
int main () {
plan(1);
ok(50 + 5, "foo %s", "bar");
done_testing();
}
$ gcc test.c tap.c
$ a.out
1..1
ok 1 - foo bar
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..8a54540
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,8 @@
+SUBDIRS = . t
+
+lib_LTLIBRARIES = libtap.la
+pkgconfig_DATA = tap.pc
+pkgconfigdir = $(libdir)/pkgconfig
+include_HEADERS = tap.h
+libtap_la_SOURCES = tap.c
+
diff --git a/Makefile b/Makefile.simple
similarity index 100%
rename from Makefile
rename to Makefile.simple
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..e69de29
diff --git a/README.md b/README
similarity index 100%
rename from README.md
rename to README
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..39718a4
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,30 @@
+# -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+
+AC_PREREQ([2.69])
+AC_INIT([libtap], [0.1.0], [[email protected]])
+AC_CONFIG_SRCDIR([tap.c])
+AC_CONFIG_HEADERS([config.h])
+AC_CONFIG_AUX_DIR([.auto])
+AM_INIT_AUTOMAKE
+
+# Checks for programs.
+AC_PROG_CC
+AC_PROG_INSTALL
+LT_INIT
+
+# Checks for libraries.
+
+# Checks for header files.
+AC_CHECK_HEADERS([stdlib.h string.h sys/param.h unistd.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+
+# Checks for library functions.
+AC_FUNC_FORK
+AC_FUNC_MALLOC
+AC_FUNC_MMAP
+AC_CHECK_FUNCS([regcomp])
+
+AC_CONFIG_FILES([Makefile t/Makefile tap.pc])
+AC_OUTPUT
diff --git a/t/Makefile.am b/t/Makefile.am
new file mode 100644
index 0000000..d580728
--- /dev/null
+++ b/t/Makefile.am
@@ -0,0 +1,12 @@
+AM_LDFLAGS = $(top_srcdir)/.libs/libtap.la -static
+
+noinst_PROGRAMS = cmpok diesok is like notediag simple skip synopsis todo
+
+cmpok_SOURCES = cmpok.c
+diesok_SOURCES = diesok.c
+is_SOURCES = is.c
+like_SOURCES = like.c
+notediag_SOURCES = notediag.c
+simple_SOURCES = simple.c
+skip_SOURCES = skip.c
+todo_SOURCES = todo.c
diff --git a/tap.pc.in b/tap.pc.in
new file mode 100644
index 0000000..c42055a
--- /dev/null
+++ b/tap.pc.in
@@ -0,0 +1,9 @@
+prefix=@prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: tap
+Description: easy to read and write way of creating tests for your software
+Version: @VERSION@
+Libs: -L${libdir} -ltap
+Cflags: -I${includedir}
|
zorgnax/libtap
|
c3c3d0aa447611c779ee117f3bde0ec58798760d
|
Travis now supports C
|
diff --git a/.travis.yml b/.travis.yml
index 5920737..6f9809e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,9 +1,13 @@
-language: erlang # no C/shell language support; use least-loaded worker(s)
+language: c
+
+compiler:
+ - gcc
+ - clang
before_install: sudo apt-get install -y libtest-differences-perl
-install: make install
+install: make CC=$CC install
-script: make test
+script: make CC=$CC test
after_script: make uninstall
|
zorgnax/libtap
|
baf4d46e8b9df591ec40f963cb7a9e0b47b626d9
|
Generate testing command in subroutine
|
diff --git a/t/tap.t b/t/tap.t
index e0f726a..6dbafdf 100755
--- a/t/tap.t
+++ b/t/tap.t
@@ -1,211 +1,217 @@
#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 9;
use Test::Differences;
my $x = $^O eq 'MSWin32' ? ".exe" : "";
-eq_or_diff ~~`t/cmpok$x 2>&1`, <<'END', "cmp_ok";
+sub cmd_eq_or_diff {
+ my ($command, $expected) = @_;
+ my $output = `$command$x 2>&1`;
+ eq_or_diff($output, $expected, $command);
+}
+
+cmd_eq_or_diff "t/cmpok", <<END;
1..9
not ok 1
# Failed test at t/cmpok.c line 6.
# 420
# >
# 666
not ok 2 - the number 23 is definitely 55
# Failed test 'the number 23 is definitely 55'
# at t/cmpok.c line 7.
# 23
# ==
# 55
not ok 3
# Failed test at t/cmpok.c line 8.
# 23
# ==
# 55
ok 4
# unrecognized operator 'frob'
not ok 5
# Failed test at t/cmpok.c line 10.
# 23
# frob
# 55
ok 6
not ok 7
# Failed test at t/cmpok.c line 12.
# 55
# +
# -55
ok 8
not ok 9
# Failed test at t/cmpok.c line 14.
# 55
# %
# 5
# Looks like you failed 6 tests of 9 run.
END
-eq_or_diff ~~`t/diesok$x 2>&1`, <<'END', "dies_ok";
+cmd_eq_or_diff "t/diesok", <<END;
1..5
ok 1 - sanity
ok 2 - can't divide by zero
ok 3 - this is a perfectly fine statement
ok 4 - abort kills the program
ok 5 - supress output
END
-eq_or_diff ~~`t/is$x 2>&1`, <<'END', "is";
+cmd_eq_or_diff "t/is", <<END;
1..18
not ok 1 - this is that
# Failed test 'this is that'
# at t/is.c line 6.
# got: 'this'
# expected: 'that'
ok 2 - this is this
not ok 3
# Failed test at t/is.c line 8.
# got: 'this'
# expected: 'that'
ok 4
ok 5 - null is null
not ok 6 - null is this
# Failed test 'null is this'
# at t/is.c line 11.
# got: '(null)'
# expected: 'this'
not ok 7 - this is null
# Failed test 'this is null'
# at t/is.c line 12.
# got: 'this'
# expected: '(null)'
not ok 8
# Failed test at t/is.c line 13.
# got: 'foo
# foo
# foo'
# expected: 'bar
# bar
# bar'
ok 9
ok 10 - this isnt that
not ok 11 - this isnt this
# Failed test 'this isnt this'
# at t/is.c line 16.
# got: 'this'
# expected: anything else
ok 12
not ok 13
# Failed test at t/is.c line 18.
# got: 'this'
# expected: anything else
not ok 14 - null isnt null
# Failed test 'null isnt null'
# at t/is.c line 19.
# got: '(null)'
# expected: anything else
ok 15 - null isnt this
ok 16 - this isnt null
ok 17
not ok 18
# Failed test at t/is.c line 23.
# got: 'foo
# foo
# foo'
# expected: anything else
# Looks like you failed 9 tests of 18 run.
END
-eq_or_diff ~~`t/like$x 2>&1`, <<'END', "like";
+cmd_eq_or_diff "t/like", <<END;
1..3
ok 1 - strange ~~ /range/
ok 2 - strange !~~ /anger/
ok 3 - matches the regex
END
-eq_or_diff ~~`t/notediag$x 2>&1`, <<'END', "note and diag";
+cmd_eq_or_diff "t/notediag", <<END;
# note no new line
# note new line
# diag no new line
# diag new line
END
-eq_or_diff ~~`t/simple$x 2>&1`, <<'END', "simple";
+cmd_eq_or_diff "t/simple", <<END;
1..24
ok 1
ok 2
ok 3
not ok 4
# Failed test at t/simple.c line 9.
ok 5 - foo
ok 6 - bar
ok 7 - baz
ok 8 - quux
ok 9 - thud
ok 10 - wombat
ok 11 - blurgle
ok 12 - frob
not ok 13 - frobnicate
# Failed test 'frobnicate'
# at t/simple.c line 18.
ok 14 - eek
ok 15 - ook
ok 16 - frodo
ok 17 - bilbo
ok 18 - wubble
ok 19 - flarp
ok 20 - fnord
ok 21
not ok 22
# Failed test at t/simple.c line 27.
ok 23 - good
not ok 24 - bad
# Failed test 'bad'
# at t/simple.c line 29.
# Looks like you failed 4 tests of 24 run.
END
-eq_or_diff ~~`t/skip$x 2>&1`, <<'END', "skip";
+cmd_eq_or_diff "t/skip", <<END;
1..8
ok 1 - quux
ok 2 - thud
ok 3 - wombat
ok 4 # skip need to be on windows
ok 5 - quux
ok 6 - thud
ok 7 - wombat
ok 8 # skip
END
-eq_or_diff ~~`t/synopsis$x 2>&1`, <<'END', "synopsis";
+cmd_eq_or_diff "t/synopsis", <<END;
1..5
ok 1
not ok 2 - two different strings not that way?
# Failed test 'two different strings not that way?'
# at t/synopsis.c line 7.
# got: 'fnord'
# expected: 'eek'
ok 3 - 3 <= 8732
ok 4
not ok 5
# Failed test at t/synopsis.c line 10.
# 3
# >=
# 10
# Looks like you failed 2 tests of 5 run.
END
-eq_or_diff ~~`t/todo$x 2>&1`, <<'END', "todo";
+cmd_eq_or_diff "t/todo", <<END;
1..6
not ok 1 - foo # TODO
# Failed (TODO) test 'foo'
# at t/todo.c line 7.
ok 2 - bar # TODO
ok 3 - baz # TODO
not ok 4 - quux # TODO im not ready
# Failed (TODO) test 'quux'
# at t/todo.c line 12.
ok 5 - thud # TODO im not ready
ok 6 - wombat # TODO im not ready
END
|
zorgnax/libtap
|
0e45669c781edad2062a60e689adda447c0a380b
|
Rename endskip and endtodo to end_skip and end_todo
|
diff --git a/README.md b/README.md
index c51384c..b241e5d 100644
--- a/README.md
+++ b/README.md
@@ -1,245 +1,245 @@
NAME
====
libtap - Write tests in C
SYNOPSIS
========
#include <tap.h>
int main () {
plan(5);
ok(3 == 3);
is("fnord", "eek", "two different strings not that way?");
ok(3 <= 8732, "%d <= %d", 3, 8732);
like("fnord", "f(yes|no)r*[a-f]$");
cmp_ok(3, ">=", 10);
done_testing();
}
results in:
1..5
ok 1
not ok 2 - two different strings not that way?
# Failed test 'two different strings not that way?'
# at t/synopsis.c line 7.
# got: 'fnord'
# expected: 'eek'
ok 3 - 3 <= 8732
ok 4
not ok 5
# Failed test at t/synopsis.c line 10.
# 3
# >=
# 10
# Looks like you failed 2 tests of 5 run.
DESCRIPTION
===========
tap is an easy to read and easy to write way of creating tests for your
software. This library creates functions that can be used to generate it for
your C programs. It is mostly based on the Test::More Perl module.
FUNCTIONS
=========
- plan(tests)
- plan(NO_PLAN)
- plan(SKIP_ALL);
- plan(SKIP_ALL, fmt, ...)
Use this to start a series of tests. When you know how many tests there
will be, you can put a number as a number of tests you expect to run. If
you do not know how many tests there will be, you can use plan(NO_PLAN)
or not call this function. When you pass it a number of tests to run, a
message similar to the following will appear in the output:
1..5
If you pass it SKIP_ALL, the whole test will be skipped.
- ok(test)
- ok(test, fmt, ...)
Specify a test. the test can be any statement returning a true or false
value. You may optionally pass a format string describing the test.
ok(r = reader_new("Of Mice and Men"), "create a new reader");
ok(reader_go_to_page(r, 55), "can turn the page");
ok(r->page == 55, "page turned to the right one");
Should print out:
ok 1 - create a new reader
ok 2 - can turn the page
ok 3 - page turned to the right one
On failure, a diagnostic message will be printed out.
not ok 3 - page turned to the right one
# Failed test 'page turned to the right one'
# at reader.c line 13.
- is(got, expected)
- is(got, expected, fmt, ...)
- isnt(got, unexpected)
- isnt(got, unexpected, fmt, ...)
Tests that the string you got is what you expected. with isnt, it is the
reverse.
is("this", "that", "this is that");
prints:
not ok 1 - this is that
# Failed test 'this is that'
# at is.c line 6.
# got: 'this'
# expected: 'that'
- cmp_ok(a, op, b)
- cmp_ok(a, op, b, fmt, ...)
Compares two ints with any binary operator that doesn't require an lvalue.
This is nice to use since it provides a better error message than an
equivalent ok.
cmp_ok(420, ">", 666);
prints:
not ok 1
# Failed test at cmpok.c line 5.
# 420
# >
# 666
- like(got, expected)
- like(got, expected, fmt, ...)
- unlike(got, unexpected)
- unlike(got, unexpected, fmt, ...)
Tests that the string you got matches the expected extended POSIX regex.
unlike is the reverse. These macros are the equivalent of a skip on
Windows.
like("stranger", "^s.(r).*\\1$", "matches the regex");
prints:
ok 1 - matches the regex
- pass()
- pass(fmt, ...)
- fail()
- fail(fmt, ...)
Speciy that a test succeeded or failed. Use these when the statement is
longer than you can fit into the argument given to an ok() test.
- dies_ok(code)
- dies_ok(code, fmt, ...)
- lives_ok(code)
- lives_ok(code, fmt, ...)
Tests whether the given code causes your program to exit. The code gets
passed to a macro that will test it in a forked process. If the code
succeeds it will be executed in the parent process. You can test things
like passing a function a null pointer and make sure it doesnt
dereference it and crash.
dies_ok({abort();}, "abort does close your program");
dies_ok({int x = 0/0;}, "divide by zero crash");
lives_ok({pow(3.0, 5.0);}, "nothing wrong with taking 3**5");
On Windows, these macros are the equivalent of a skip.
- done_testing()
Summarizes the tests that occurred and exits the main function. If
there was no plan, it will print out the number of tests as.
1..5
It will also print a diagnostic message about how many
failures there were.
# Looks like you failed 2 tests of 3 run.
If all planned tests were successful, it will return 0. If any test fails,
it will return the number of failed tests (including ones that were
missing). If they all passed, but there were missing tests, it will return
255.
- note(fmt, ...)
- diag(fmt, ...)
print out a message to the tap output. note prints to stdout and diag
prints to stderr. Each line is preceeded by a "# " so that you know its a
diagnostic message.
note("This is\na note\nto describe\nsomething.");
prints:
# This is
# a note
# to describe
# something
ok() and these functions return ints so you can use them like:
ok(1) && note("yo!");
ok(0) || diag("I have no idea what just happened");
- skip(test, n)
- skip(test, n, fmt, ...)
-- endskip
+- end_skip
Skip a series of n tests if test is true. You may give a reason why you are
skipping them or not. The (possibly) skipped tests must occur between the
- skip and endskip macros.
+ skip and end_skip macros.
skip(TRUE, 2);
ok(1);
ok(0);
- endskip;
+ end_skip;
prints:
ok 1 # skip
ok 2 # skip
- todo()
- todo(fmt, ...)
-- endtodo
+- end_todo
Specifies a series of tests that you expect to fail because they are not
yet implemented.
todo()
ok(0);
- endtodo;
+ end_todo;
prints:
not ok 1 # TODO
# Failed (TODO) test at todo.c line 7
- BAIL_OUT()
- BAIL_OUT(fmt, ...)
Immediately stops all testing.
BAIL_OUT("Can't go no further");
prints
Bail out! Can't go no further
and exits with 255.
diff --git a/t/skip.c b/t/skip.c
index 149ef53..92faca8 100644
--- a/t/skip.c
+++ b/t/skip.c
@@ -1,24 +1,24 @@
#include "tap.h"
int main () {
setvbuf(stdout, NULL, _IONBF, 0);
plan(8);
skip(0, 3, "%s cannot fork", "windows");
ok(1, "quux");
ok(1, "thud");
ok(1, "wombat");
- endskip;
+ end_skip;
skip(1, 1, "need to be on windows");
ok(0, "blurgle");
- endskip;
+ end_skip;
skip(0, 3);
ok(1, "quux");
ok(1, "thud");
ok(1, "wombat");
- endskip;
+ end_skip;
skip(1, 1);
ok(0, "blurgle");
- endskip;
+ end_skip;
done_testing();
}
diff --git a/t/todo.c b/t/todo.c
index af15f11..2493667 100644
--- a/t/todo.c
+++ b/t/todo.c
@@ -1,18 +1,18 @@
#include "tap.h"
int main () {
setvbuf(stdout, NULL, _IONBF, 0);
plan(6);
todo();
ok(0, "foo");
ok(1, "bar");
ok(1, "baz");
- endtodo;
+ end_todo;
todo("im not ready");
ok(0, "quux");
ok(1, "thud");
ok(1, "wombat");
- endtodo;
+ end_todo;
done_testing();
}
diff --git a/tap.c b/tap.c
index a923bb0..b28debd 100644
--- a/tap.c
+++ b/tap.c
@@ -1,329 +1,329 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the GPLv2
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
if (!str) {
perror("malloc error");
exit(1);
}
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
planf (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
note("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
printf("%sok %d", test ? "" : "not ", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
if (*name)
diag(" Failed%s test '%s'\n at %s line %d.",
todo_mesg ? " (TODO)" : "", name, file, line);
else
diag(" Failed%s test at %s line %d.",
todo_mesg ? " (TODO)" : "", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static void
vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
char *mesg, *line;
int i;
if (!fmt)
return;
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
fprintf(fh, "# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
return;
}
int
diag (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stderr, fmt, args);
va_end(args);
return 0;
}
int
note (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stdout, fmt, args);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 255;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
if (expected_tests == NO_PLAN)
retval = failed_tests;
else
retval = expected_tests - current_test + failed_tests;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
skippy (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
note("skip %s\n", why);
}
free(why);
}
void
todof (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
-endtodof () {
+end_todof () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
#if defined __APPLE__ || defined BSD
#define MAP_ANONYMOUS MAP_ANON
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros. */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
diff --git a/tap.h b/tap.h
index ea4af00..4642345 100644
--- a/tap.h
+++ b/tap.h
@@ -1,114 +1,114 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the GPLv2
*/
#ifndef __TAP_H__
#define __TAP_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifndef va_copy
#ifdef __va_copy
#define va_copy __va_copy
#else
#define va_copy(d, s) ((d) = (s))
#endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args);
int ok_at_loc (const char *file, int line, int test, const char *fmt,
...);
int is_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int isnt_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int cmp_ok_at_loc (const char *file, int line, int a, const char *op,
int b, const char *fmt, ...);
int bail_out (int ignore, const char *fmt, ...);
void planf (int tests, const char *fmt, ...);
int diag (const char *fmt, ...);
int note (const char *fmt, ...);
int exit_status (void);
void skippy (int n, const char *fmt, ...);
void todof (int ignore, const char *fmt, ...);
-void endtodof (void);
+void end_todof (void);
#define NO_PLAN -1
#define SKIP_ALL -2
#define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define plan(...) planf(__VA_ARGS__, NULL)
#define done_testing() return exit_status()
#define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
#define pass(...) ok(1, "" __VA_ARGS__)
#define fail(...) ok(0, "" __VA_ARGS__)
#define skip(test, ...) do {if (test) {skippy(__VA_ARGS__, NULL); break;}
-#define endskip } while (0)
+#define end_skip } while (0)
#define todo(...) todof(0, "" __VA_ARGS__, NULL)
-#define endtodo endtodof()
+#define end_todo end_todof()
#define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
#define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
#ifdef _WIN32
#define like(...) skippy(1, "like is not implemented on Windows")
#define unlike like
#define dies_ok_common(...) \
skippy(1, "Death detection is not supported on Windows")
#else
#define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
#define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
int like_at_loc (int for_match, const char *file, int line,
const char *got, const char *expected,
const char *fmt, ...);
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int tap_test_died (int status);
#define dies_ok_common(for_death, code, ...) \
do { \
int cpid; \
int it_died; \
tap_test_died(1); \
cpid = fork(); \
switch (cpid) { \
case -1: \
perror("fork error"); \
exit(1); \
case 0: \
close(1); \
close(2); \
code \
tap_test_died(0); \
exit(0); \
} \
if (waitpid(cpid, NULL, 0) < 0) { \
perror("waitpid error"); \
exit(1); \
} \
it_died = tap_test_died(0); \
if (!it_died) \
{code} \
ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \
} while (0)
#endif
#ifdef __cplusplus
}
#endif
#endif
|
zorgnax/libtap
|
e1329bfc033d8bb7eaac89fb3e9b58dd362dc180
|
Use the name Windows instead of MSWin32
|
diff --git a/tap.h b/tap.h
index 04eeb86..ea4af00 100644
--- a/tap.h
+++ b/tap.h
@@ -1,114 +1,114 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the GPLv2
*/
#ifndef __TAP_H__
#define __TAP_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifndef va_copy
#ifdef __va_copy
#define va_copy __va_copy
#else
#define va_copy(d, s) ((d) = (s))
#endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args);
int ok_at_loc (const char *file, int line, int test, const char *fmt,
...);
int is_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int isnt_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int cmp_ok_at_loc (const char *file, int line, int a, const char *op,
int b, const char *fmt, ...);
int bail_out (int ignore, const char *fmt, ...);
void planf (int tests, const char *fmt, ...);
int diag (const char *fmt, ...);
int note (const char *fmt, ...);
int exit_status (void);
void skippy (int n, const char *fmt, ...);
void todof (int ignore, const char *fmt, ...);
void endtodof (void);
#define NO_PLAN -1
#define SKIP_ALL -2
#define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define plan(...) planf(__VA_ARGS__, NULL)
#define done_testing() return exit_status()
#define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
#define pass(...) ok(1, "" __VA_ARGS__)
#define fail(...) ok(0, "" __VA_ARGS__)
#define skip(test, ...) do {if (test) {skippy(__VA_ARGS__, NULL); break;}
#define endskip } while (0)
#define todo(...) todof(0, "" __VA_ARGS__, NULL)
#define endtodo endtodof()
#define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
#define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
#ifdef _WIN32
-#define like(...) skippy(1, "like is not implemented on MSWin32")
+#define like(...) skippy(1, "like is not implemented on Windows")
#define unlike like
#define dies_ok_common(...) \
- skippy(1, "Death detection is not supported on MSWin32")
+ skippy(1, "Death detection is not supported on Windows")
#else
#define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
#define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
int like_at_loc (int for_match, const char *file, int line,
const char *got, const char *expected,
const char *fmt, ...);
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int tap_test_died (int status);
#define dies_ok_common(for_death, code, ...) \
do { \
int cpid; \
int it_died; \
tap_test_died(1); \
cpid = fork(); \
switch (cpid) { \
case -1: \
perror("fork error"); \
exit(1); \
case 0: \
close(1); \
close(2); \
code \
tap_test_died(0); \
exit(0); \
} \
if (waitpid(cpid, NULL, 0) < 0) { \
perror("waitpid error"); \
exit(1); \
} \
it_died = tap_test_died(0); \
if (!it_died) \
{code} \
ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \
} while (0)
#endif
#ifdef __cplusplus
}
#endif
#endif
|
zorgnax/libtap
|
efcecfe3dcc66fdd9eb1427bf090283754342e80
|
Rename cplan, ctodo, and cendtodo to planf, todof, endtodof
|
diff --git a/tap.c b/tap.c
index 35694ea..a923bb0 100644
--- a/tap.c
+++ b/tap.c
@@ -1,329 +1,329 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the GPLv2
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
if (!str) {
perror("malloc error");
exit(1);
}
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
-cplan (int tests, const char *fmt, ...) {
+planf (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
note("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
printf("%sok %d", test ? "" : "not ", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
if (*name)
diag(" Failed%s test '%s'\n at %s line %d.",
todo_mesg ? " (TODO)" : "", name, file, line);
else
diag(" Failed%s test at %s line %d.",
todo_mesg ? " (TODO)" : "", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static void
vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
char *mesg, *line;
int i;
if (!fmt)
return;
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
fprintf(fh, "# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
return;
}
int
diag (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stderr, fmt, args);
va_end(args);
return 0;
}
int
note (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stdout, fmt, args);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 255;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
if (expected_tests == NO_PLAN)
retval = failed_tests;
else
retval = expected_tests - current_test + failed_tests;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
skippy (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
note("skip %s\n", why);
}
free(why);
}
void
-ctodo (int ignore, const char *fmt, ...) {
+todof (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
-cendtodo () {
+endtodof () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
#if defined __APPLE__ || defined BSD
#define MAP_ANONYMOUS MAP_ANON
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
-dies. to be used in the dies_ok and lives_ok macros */
+dies. to be used in the dies_ok and lives_ok macros. */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
diff --git a/tap.h b/tap.h
index 503ab23..04eeb86 100644
--- a/tap.h
+++ b/tap.h
@@ -1,114 +1,114 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the GPLv2
*/
#ifndef __TAP_H__
#define __TAP_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifndef va_copy
#ifdef __va_copy
#define va_copy __va_copy
#else
#define va_copy(d, s) ((d) = (s))
#endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args);
int ok_at_loc (const char *file, int line, int test, const char *fmt,
...);
int is_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int isnt_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int cmp_ok_at_loc (const char *file, int line, int a, const char *op,
int b, const char *fmt, ...);
int bail_out (int ignore, const char *fmt, ...);
-void cplan (int tests, const char *fmt, ...);
+void planf (int tests, const char *fmt, ...);
int diag (const char *fmt, ...);
int note (const char *fmt, ...);
int exit_status (void);
void skippy (int n, const char *fmt, ...);
-void ctodo (int ignore, const char *fmt, ...);
-void cendtodo (void);
+void todof (int ignore, const char *fmt, ...);
+void endtodof (void);
#define NO_PLAN -1
#define SKIP_ALL -2
#define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
-#define plan(...) cplan(__VA_ARGS__, NULL)
+#define plan(...) planf(__VA_ARGS__, NULL)
#define done_testing() return exit_status()
#define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
#define pass(...) ok(1, "" __VA_ARGS__)
#define fail(...) ok(0, "" __VA_ARGS__)
#define skip(test, ...) do {if (test) {skippy(__VA_ARGS__, NULL); break;}
#define endskip } while (0)
-#define todo(...) ctodo(0, "" __VA_ARGS__, NULL)
-#define endtodo cendtodo()
+#define todo(...) todof(0, "" __VA_ARGS__, NULL)
+#define endtodo endtodof()
#define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
#define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
#ifdef _WIN32
#define like(...) skippy(1, "like is not implemented on MSWin32")
#define unlike like
#define dies_ok_common(...) \
skippy(1, "Death detection is not supported on MSWin32")
#else
#define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
#define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
int like_at_loc (int for_match, const char *file, int line,
const char *got, const char *expected,
const char *fmt, ...);
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int tap_test_died (int status);
#define dies_ok_common(for_death, code, ...) \
do { \
int cpid; \
int it_died; \
tap_test_died(1); \
cpid = fork(); \
switch (cpid) { \
case -1: \
perror("fork error"); \
exit(1); \
case 0: \
close(1); \
close(2); \
code \
tap_test_died(0); \
exit(0); \
} \
if (waitpid(cpid, NULL, 0) < 0) { \
perror("waitpid error"); \
exit(1); \
} \
it_died = tap_test_died(0); \
if (!it_died) \
{code} \
ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \
} while (0)
#endif
#ifdef __cplusplus
}
#endif
#endif
|
zorgnax/libtap
|
b2b8e01d6d40a1a34e726847e4c1c57b0819725f
|
Check for malloc errors
|
diff --git a/tap.c b/tap.c
index 517d5c6..35694ea 100644
--- a/tap.c
+++ b/tap.c
@@ -1,325 +1,329 @@
/*
libtap - Write tests in C
Copyright 2012 Jake Gelbman <[email protected]>
This file is licensed under the GPLv2
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
+ if (!str) {
+ perror("malloc error");
+ exit(1);
+ }
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
cplan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
note("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
printf("%sok %d", test ? "" : "not ", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
if (*name)
diag(" Failed%s test '%s'\n at %s line %d.",
todo_mesg ? " (TODO)" : "", name, file, line);
else
diag(" Failed%s test at %s line %d.",
todo_mesg ? " (TODO)" : "", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static void
vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
char *mesg, *line;
int i;
if (!fmt)
return;
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
fprintf(fh, "# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
return;
}
int
diag (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stderr, fmt, args);
va_end(args);
return 0;
}
int
note (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stdout, fmt, args);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 255;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
if (expected_tests == NO_PLAN)
retval = failed_tests;
else
retval = expected_tests - current_test + failed_tests;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
skippy (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
note("skip %s\n", why);
}
free(why);
}
void
ctodo (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
cendtodo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
#if defined __APPLE__ || defined BSD
#define MAP_ANONYMOUS MAP_ANON
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
|
zorgnax/libtap
|
52a6219d6121a13d30192d6c187a9f0f1d08fff4
|
Simplify synopsis
|
diff --git a/README.md b/README.md
index a77d22a..c51384c 100644
--- a/README.md
+++ b/README.md
@@ -1,248 +1,245 @@
NAME
====
libtap - Write tests in C
SYNOPSIS
========
#include <tap.h>
- int foo () {return 3;}
- char *bar () {return "fnord";}
-
int main () {
plan(5);
- ok(foo() == 3);
- is(bar(), "eek");
- ok(foo() <= 8732, "foo <= %d", 8732);
- like(bar(), "f(yes|no)r*[a-f]$", "is like");
- cmp_ok(foo(), ">=", 10, "foo is greater than ten");
+ ok(3 == 3);
+ is("fnord", "eek", "two different strings not that way?");
+ ok(3 <= 8732, "%d <= %d", 3, 8732);
+ like("fnord", "f(yes|no)r*[a-f]$");
+ cmp_ok(3, ">=", 10);
done_testing();
}
results in:
1..5
ok 1
- not ok 2
- # Failed test at synopsis.c line 9.
+ not ok 2 - two different strings not that way?
+ # Failed test 'two different strings not that way?'
+ # at t/synopsis.c line 7.
# got: 'fnord'
# expected: 'eek'
- ok 3 - foo <= 8732
- ok 4 - is like
- not ok 5 - foo is greater than ten
- # Failed test 'foo is greater than ten'
- # at synopsis.c line 12.
+ ok 3 - 3 <= 8732
+ ok 4
+ not ok 5
+ # Failed test at t/synopsis.c line 10.
# 3
# >=
# 10
# Looks like you failed 2 tests of 5 run.
DESCRIPTION
===========
tap is an easy to read and easy to write way of creating tests for your
software. This library creates functions that can be used to generate it for
your C programs. It is mostly based on the Test::More Perl module.
FUNCTIONS
=========
- plan(tests)
- plan(NO_PLAN)
- plan(SKIP_ALL);
- plan(SKIP_ALL, fmt, ...)
Use this to start a series of tests. When you know how many tests there
will be, you can put a number as a number of tests you expect to run. If
you do not know how many tests there will be, you can use plan(NO_PLAN)
or not call this function. When you pass it a number of tests to run, a
message similar to the following will appear in the output:
1..5
If you pass it SKIP_ALL, the whole test will be skipped.
- ok(test)
- ok(test, fmt, ...)
Specify a test. the test can be any statement returning a true or false
value. You may optionally pass a format string describing the test.
ok(r = reader_new("Of Mice and Men"), "create a new reader");
ok(reader_go_to_page(r, 55), "can turn the page");
ok(r->page == 55, "page turned to the right one");
Should print out:
ok 1 - create a new reader
ok 2 - can turn the page
ok 3 - page turned to the right one
On failure, a diagnostic message will be printed out.
not ok 3 - page turned to the right one
# Failed test 'page turned to the right one'
# at reader.c line 13.
- is(got, expected)
- is(got, expected, fmt, ...)
- isnt(got, unexpected)
- isnt(got, unexpected, fmt, ...)
Tests that the string you got is what you expected. with isnt, it is the
reverse.
is("this", "that", "this is that");
prints:
not ok 1 - this is that
# Failed test 'this is that'
# at is.c line 6.
# got: 'this'
# expected: 'that'
- cmp_ok(a, op, b)
- cmp_ok(a, op, b, fmt, ...)
Compares two ints with any binary operator that doesn't require an lvalue.
This is nice to use since it provides a better error message than an
equivalent ok.
cmp_ok(420, ">", 666);
prints:
not ok 1
# Failed test at cmpok.c line 5.
# 420
# >
# 666
- like(got, expected)
- like(got, expected, fmt, ...)
- unlike(got, unexpected)
- unlike(got, unexpected, fmt, ...)
Tests that the string you got matches the expected extended POSIX regex.
unlike is the reverse. These macros are the equivalent of a skip on
Windows.
like("stranger", "^s.(r).*\\1$", "matches the regex");
prints:
ok 1 - matches the regex
- pass()
- pass(fmt, ...)
- fail()
- fail(fmt, ...)
Speciy that a test succeeded or failed. Use these when the statement is
longer than you can fit into the argument given to an ok() test.
- dies_ok(code)
- dies_ok(code, fmt, ...)
- lives_ok(code)
- lives_ok(code, fmt, ...)
Tests whether the given code causes your program to exit. The code gets
passed to a macro that will test it in a forked process. If the code
succeeds it will be executed in the parent process. You can test things
like passing a function a null pointer and make sure it doesnt
dereference it and crash.
dies_ok({abort();}, "abort does close your program");
dies_ok({int x = 0/0;}, "divide by zero crash");
lives_ok({pow(3.0, 5.0);}, "nothing wrong with taking 3**5");
On Windows, these macros are the equivalent of a skip.
- done_testing()
Summarizes the tests that occurred and exits the main function. If
there was no plan, it will print out the number of tests as.
1..5
It will also print a diagnostic message about how many
failures there were.
# Looks like you failed 2 tests of 3 run.
If all planned tests were successful, it will return 0. If any test fails,
it will return the number of failed tests (including ones that were
missing). If they all passed, but there were missing tests, it will return
255.
- note(fmt, ...)
- diag(fmt, ...)
print out a message to the tap output. note prints to stdout and diag
prints to stderr. Each line is preceeded by a "# " so that you know its a
diagnostic message.
note("This is\na note\nto describe\nsomething.");
prints:
# This is
# a note
# to describe
# something
ok() and these functions return ints so you can use them like:
ok(1) && note("yo!");
ok(0) || diag("I have no idea what just happened");
- skip(test, n)
- skip(test, n, fmt, ...)
- endskip
Skip a series of n tests if test is true. You may give a reason why you are
skipping them or not. The (possibly) skipped tests must occur between the
skip and endskip macros.
skip(TRUE, 2);
ok(1);
ok(0);
endskip;
prints:
ok 1 # skip
ok 2 # skip
- todo()
- todo(fmt, ...)
- endtodo
Specifies a series of tests that you expect to fail because they are not
yet implemented.
todo()
ok(0);
endtodo;
prints:
not ok 1 # TODO
# Failed (TODO) test at todo.c line 7
- BAIL_OUT()
- BAIL_OUT(fmt, ...)
Immediately stops all testing.
BAIL_OUT("Can't go no further");
prints
Bail out! Can't go no further
and exits with 255.
diff --git a/t/synopsis.c b/t/synopsis.c
index c7b3041..b83b11c 100644
--- a/t/synopsis.c
+++ b/t/synopsis.c
@@ -1,16 +1,13 @@
#include "tap.h"
-int foo () {return 3;}
-char *bar () {return "fnord";}
-
int main () {
setvbuf(stdout, NULL, _IONBF, 0);
plan(5);
- ok(foo() == 3);
- is(bar(), "eek");
- ok(foo() <= 8732, "foo <= %d", 8732);
- like(bar(), "f(yes|no)r*[a-f]$", "is like");
- cmp_ok(foo(), ">=", 10, "foo is greater than ten");
+ ok(3 == 3);
+ is("fnord", "eek", "two different strings not that way?");
+ ok(3 <= 8732, "%d <= %d", 3, 8732);
+ like("fnord", "f(yes|no)r*[a-f]$");
+ cmp_ok(3, ">=", 10);
done_testing();
}
diff --git a/t/tap.t b/t/tap.t
index 8a8e54d..e0f726a 100755
--- a/t/tap.t
+++ b/t/tap.t
@@ -1,211 +1,211 @@
#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 9;
use Test::Differences;
my $x = $^O eq 'MSWin32' ? ".exe" : "";
eq_or_diff ~~`t/cmpok$x 2>&1`, <<'END', "cmp_ok";
1..9
not ok 1
# Failed test at t/cmpok.c line 6.
# 420
# >
# 666
not ok 2 - the number 23 is definitely 55
# Failed test 'the number 23 is definitely 55'
# at t/cmpok.c line 7.
# 23
# ==
# 55
not ok 3
# Failed test at t/cmpok.c line 8.
# 23
# ==
# 55
ok 4
# unrecognized operator 'frob'
not ok 5
# Failed test at t/cmpok.c line 10.
# 23
# frob
# 55
ok 6
not ok 7
# Failed test at t/cmpok.c line 12.
# 55
# +
# -55
ok 8
not ok 9
# Failed test at t/cmpok.c line 14.
# 55
# %
# 5
# Looks like you failed 6 tests of 9 run.
END
eq_or_diff ~~`t/diesok$x 2>&1`, <<'END', "dies_ok";
1..5
ok 1 - sanity
ok 2 - can't divide by zero
ok 3 - this is a perfectly fine statement
ok 4 - abort kills the program
ok 5 - supress output
END
eq_or_diff ~~`t/is$x 2>&1`, <<'END', "is";
1..18
not ok 1 - this is that
# Failed test 'this is that'
# at t/is.c line 6.
# got: 'this'
# expected: 'that'
ok 2 - this is this
not ok 3
# Failed test at t/is.c line 8.
# got: 'this'
# expected: 'that'
ok 4
ok 5 - null is null
not ok 6 - null is this
# Failed test 'null is this'
# at t/is.c line 11.
# got: '(null)'
# expected: 'this'
not ok 7 - this is null
# Failed test 'this is null'
# at t/is.c line 12.
# got: 'this'
# expected: '(null)'
not ok 8
# Failed test at t/is.c line 13.
# got: 'foo
# foo
# foo'
# expected: 'bar
# bar
# bar'
ok 9
ok 10 - this isnt that
not ok 11 - this isnt this
# Failed test 'this isnt this'
# at t/is.c line 16.
# got: 'this'
# expected: anything else
ok 12
not ok 13
# Failed test at t/is.c line 18.
# got: 'this'
# expected: anything else
not ok 14 - null isnt null
# Failed test 'null isnt null'
# at t/is.c line 19.
# got: '(null)'
# expected: anything else
ok 15 - null isnt this
ok 16 - this isnt null
ok 17
not ok 18
# Failed test at t/is.c line 23.
# got: 'foo
# foo
# foo'
# expected: anything else
# Looks like you failed 9 tests of 18 run.
END
eq_or_diff ~~`t/like$x 2>&1`, <<'END', "like";
1..3
ok 1 - strange ~~ /range/
ok 2 - strange !~~ /anger/
ok 3 - matches the regex
END
eq_or_diff ~~`t/notediag$x 2>&1`, <<'END', "note and diag";
# note no new line
# note new line
# diag no new line
# diag new line
END
eq_or_diff ~~`t/simple$x 2>&1`, <<'END', "simple";
1..24
ok 1
ok 2
ok 3
not ok 4
# Failed test at t/simple.c line 9.
ok 5 - foo
ok 6 - bar
ok 7 - baz
ok 8 - quux
ok 9 - thud
ok 10 - wombat
ok 11 - blurgle
ok 12 - frob
not ok 13 - frobnicate
# Failed test 'frobnicate'
# at t/simple.c line 18.
ok 14 - eek
ok 15 - ook
ok 16 - frodo
ok 17 - bilbo
ok 18 - wubble
ok 19 - flarp
ok 20 - fnord
ok 21
not ok 22
# Failed test at t/simple.c line 27.
ok 23 - good
not ok 24 - bad
# Failed test 'bad'
# at t/simple.c line 29.
# Looks like you failed 4 tests of 24 run.
END
eq_or_diff ~~`t/skip$x 2>&1`, <<'END', "skip";
1..8
ok 1 - quux
ok 2 - thud
ok 3 - wombat
ok 4 # skip need to be on windows
ok 5 - quux
ok 6 - thud
ok 7 - wombat
ok 8 # skip
END
eq_or_diff ~~`t/synopsis$x 2>&1`, <<'END', "synopsis";
1..5
ok 1
-not ok 2
-# Failed test at t/synopsis.c line 10.
+not ok 2 - two different strings not that way?
+# Failed test 'two different strings not that way?'
+# at t/synopsis.c line 7.
# got: 'fnord'
# expected: 'eek'
-ok 3 - foo <= 8732
-ok 4 - is like
-not ok 5 - foo is greater than ten
-# Failed test 'foo is greater than ten'
-# at t/synopsis.c line 13.
+ok 3 - 3 <= 8732
+ok 4
+not ok 5
+# Failed test at t/synopsis.c line 10.
# 3
# >=
# 10
# Looks like you failed 2 tests of 5 run.
END
eq_or_diff ~~`t/todo$x 2>&1`, <<'END', "todo";
1..6
not ok 1 - foo # TODO
# Failed (TODO) test 'foo'
# at t/todo.c line 7.
ok 2 - bar # TODO
ok 3 - baz # TODO
not ok 4 - quux # TODO im not ready
# Failed (TODO) test 'quux'
# at t/todo.c line 12.
ok 5 - thud # TODO im not ready
ok 6 - wombat # TODO im not ready
END
|
zorgnax/libtap
|
1af28ae72e34ba8c42b62d25acafed05456fddba
|
Give the isnt and unlike arguments better names
|
diff --git a/README.md b/README.md
index 7384e86..a77d22a 100644
--- a/README.md
+++ b/README.md
@@ -1,248 +1,248 @@
NAME
====
libtap - Write tests in C
SYNOPSIS
========
#include <tap.h>
int foo () {return 3;}
char *bar () {return "fnord";}
int main () {
plan(5);
ok(foo() == 3);
is(bar(), "eek");
ok(foo() <= 8732, "foo <= %d", 8732);
like(bar(), "f(yes|no)r*[a-f]$", "is like");
cmp_ok(foo(), ">=", 10, "foo is greater than ten");
done_testing();
}
results in:
1..5
ok 1
not ok 2
# Failed test at synopsis.c line 9.
# got: 'fnord'
# expected: 'eek'
ok 3 - foo <= 8732
ok 4 - is like
not ok 5 - foo is greater than ten
# Failed test 'foo is greater than ten'
# at synopsis.c line 12.
# 3
# >=
# 10
# Looks like you failed 2 tests of 5 run.
DESCRIPTION
===========
tap is an easy to read and easy to write way of creating tests for your
software. This library creates functions that can be used to generate it for
your C programs. It is mostly based on the Test::More Perl module.
FUNCTIONS
=========
- plan(tests)
- plan(NO_PLAN)
- plan(SKIP_ALL);
- plan(SKIP_ALL, fmt, ...)
Use this to start a series of tests. When you know how many tests there
will be, you can put a number as a number of tests you expect to run. If
you do not know how many tests there will be, you can use plan(NO_PLAN)
or not call this function. When you pass it a number of tests to run, a
message similar to the following will appear in the output:
1..5
If you pass it SKIP_ALL, the whole test will be skipped.
- ok(test)
- ok(test, fmt, ...)
Specify a test. the test can be any statement returning a true or false
value. You may optionally pass a format string describing the test.
ok(r = reader_new("Of Mice and Men"), "create a new reader");
ok(reader_go_to_page(r, 55), "can turn the page");
ok(r->page == 55, "page turned to the right one");
Should print out:
ok 1 - create a new reader
ok 2 - can turn the page
ok 3 - page turned to the right one
On failure, a diagnostic message will be printed out.
not ok 3 - page turned to the right one
# Failed test 'page turned to the right one'
# at reader.c line 13.
- is(got, expected)
- is(got, expected, fmt, ...)
-- isnt(got, expected)
-- isnt(got, expected, fmt, ...)
+- isnt(got, unexpected)
+- isnt(got, unexpected, fmt, ...)
Tests that the string you got is what you expected. with isnt, it is the
reverse.
is("this", "that", "this is that");
prints:
not ok 1 - this is that
# Failed test 'this is that'
# at is.c line 6.
# got: 'this'
# expected: 'that'
- cmp_ok(a, op, b)
- cmp_ok(a, op, b, fmt, ...)
Compares two ints with any binary operator that doesn't require an lvalue.
This is nice to use since it provides a better error message than an
equivalent ok.
cmp_ok(420, ">", 666);
prints:
not ok 1
# Failed test at cmpok.c line 5.
# 420
# >
# 666
- like(got, expected)
- like(got, expected, fmt, ...)
-- unlike(got, expected)
-- unlike(got, expected, fmt, ...)
+- unlike(got, unexpected)
+- unlike(got, unexpected, fmt, ...)
Tests that the string you got matches the expected extended POSIX regex.
unlike is the reverse. These macros are the equivalent of a skip on
Windows.
like("stranger", "^s.(r).*\\1$", "matches the regex");
prints:
ok 1 - matches the regex
- pass()
- pass(fmt, ...)
- fail()
- fail(fmt, ...)
Speciy that a test succeeded or failed. Use these when the statement is
longer than you can fit into the argument given to an ok() test.
- dies_ok(code)
- dies_ok(code, fmt, ...)
- lives_ok(code)
- lives_ok(code, fmt, ...)
Tests whether the given code causes your program to exit. The code gets
passed to a macro that will test it in a forked process. If the code
succeeds it will be executed in the parent process. You can test things
like passing a function a null pointer and make sure it doesnt
dereference it and crash.
dies_ok({abort();}, "abort does close your program");
dies_ok({int x = 0/0;}, "divide by zero crash");
lives_ok({pow(3.0, 5.0);}, "nothing wrong with taking 3**5");
On Windows, these macros are the equivalent of a skip.
- done_testing()
Summarizes the tests that occurred and exits the main function. If
there was no plan, it will print out the number of tests as.
1..5
It will also print a diagnostic message about how many
failures there were.
# Looks like you failed 2 tests of 3 run.
If all planned tests were successful, it will return 0. If any test fails,
it will return the number of failed tests (including ones that were
missing). If they all passed, but there were missing tests, it will return
255.
- note(fmt, ...)
- diag(fmt, ...)
print out a message to the tap output. note prints to stdout and diag
prints to stderr. Each line is preceeded by a "# " so that you know its a
diagnostic message.
note("This is\na note\nto describe\nsomething.");
prints:
# This is
# a note
# to describe
# something
ok() and these functions return ints so you can use them like:
ok(1) && note("yo!");
ok(0) || diag("I have no idea what just happened");
- skip(test, n)
- skip(test, n, fmt, ...)
- endskip
Skip a series of n tests if test is true. You may give a reason why you are
skipping them or not. The (possibly) skipped tests must occur between the
skip and endskip macros.
skip(TRUE, 2);
ok(1);
ok(0);
endskip;
prints:
ok 1 # skip
ok 2 # skip
- todo()
- todo(fmt, ...)
- endtodo
Specifies a series of tests that you expect to fail because they are not
yet implemented.
todo()
ok(0);
endtodo;
prints:
not ok 1 # TODO
# Failed (TODO) test at todo.c line 7
- BAIL_OUT()
- BAIL_OUT(fmt, ...)
Immediately stops all testing.
BAIL_OUT("Can't go no further");
prints
Bail out! Can't go no further
and exits with 255.
|
zorgnax/libtap
|
fbfeb81248cea090328fe1dd78f96a51e9b4bc9f
|
License with GPLv2
|
diff --git a/COPYING b/COPYING
index 94a9ed0..d159169 100644
--- a/COPYING
+++ b/COPYING
@@ -1,674 +1,339 @@
GNU GENERAL PUBLIC LICENSE
- Version 3, 29 June 2007
+ Version 2, June 1991
- Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
- The GNU General Public License is a free, copyleft license for
-software and other kinds of works.
-
- The licenses for most software and other practical works are designed
-to take away your freedom to share and change the works. By contrast,
-the GNU General Public License is intended to guarantee your freedom to
-share and change all versions of a program--to make sure it remains free
-software for all its users. We, the Free Software Foundation, use the
-GNU General Public License for most of our software; it applies also to
-any other work released this way by its authors. You can apply it to
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
-them if you wish), that you receive source code or can get it if you
-want it, that you can change the software or use pieces of it in new
-free programs, and that you know you can do these things.
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
- To protect your rights, we need to prevent others from denying you
-these rights or asking you to surrender the rights. Therefore, you have
-certain responsibilities if you distribute copies of the software, or if
-you modify it: responsibilities to respect the freedom of others.
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must pass on to the recipients the same
-freedoms that you received. You must make sure that they, too, receive
-or can get the source code. And you must show them these terms so they
-know their rights.
-
- Developers that use the GNU GPL protect your rights with two steps:
-(1) assert copyright on the software, and (2) offer you this License
-giving you legal permission to copy, distribute and/or modify it.
-
- For the developers' and authors' protection, the GPL clearly explains
-that there is no warranty for this free software. For both users' and
-authors' sake, the GPL requires that modified versions be marked as
-changed, so that their problems will not be attributed erroneously to
-authors of previous versions.
-
- Some devices are designed to deny users access to install or run
-modified versions of the software inside them, although the manufacturer
-can do so. This is fundamentally incompatible with the aim of
-protecting users' freedom to change the software. The systematic
-pattern of such abuse occurs in the area of products for individuals to
-use, which is precisely where it is most unacceptable. Therefore, we
-have designed this version of the GPL to prohibit the practice for those
-products. If such problems arise substantially in other domains, we
-stand ready to extend this provision to those domains in future versions
-of the GPL, as needed to protect the freedom of users.
-
- Finally, every program is threatened constantly by software patents.
-States should not allow patents to restrict development and use of
-software on general-purpose computers, but in those that do, we wish to
-avoid the special danger that patents applied to a free program could
-make it effectively proprietary. To prevent this, the GPL assures that
-patents cannot be used to render the program non-free.
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
- TERMS AND CONDITIONS
-
- 0. Definitions.
-
- "This License" refers to version 3 of the GNU General Public License.
-
- "Copyright" also means copyright-like laws that apply to other kinds of
-works, such as semiconductor masks.
-
- "The Program" refers to any copyrightable work licensed under this
-License. Each licensee is addressed as "you". "Licensees" and
-"recipients" may be individuals or organizations.
-
- To "modify" a work means to copy from or adapt all or part of the work
-in a fashion requiring copyright permission, other than the making of an
-exact copy. The resulting work is called a "modified version" of the
-earlier work or a work "based on" the earlier work.
-
- A "covered work" means either the unmodified Program or a work based
-on the Program.
-
- To "propagate" a work means to do anything with it that, without
-permission, would make you directly or secondarily liable for
-infringement under applicable copyright law, except executing it on a
-computer or modifying a private copy. Propagation includes copying,
-distribution (with or without modification), making available to the
-public, and in some countries other activities as well.
-
- To "convey" a work means any kind of propagation that enables other
-parties to make or receive copies. Mere interaction with a user through
-a computer network, with no transfer of a copy, is not conveying.
-
- An interactive user interface displays "Appropriate Legal Notices"
-to the extent that it includes a convenient and prominently visible
-feature that (1) displays an appropriate copyright notice, and (2)
-tells the user that there is no warranty for the work (except to the
-extent that warranties are provided), that licensees may convey the
-work under this License, and how to view a copy of this License. If
-the interface presents a list of user commands or options, such as a
-menu, a prominent item in the list meets this criterion.
-
- 1. Source Code.
-
- The "source code" for a work means the preferred form of the work
-for making modifications to it. "Object code" means any non-source
-form of a work.
-
- A "Standard Interface" means an interface that either is an official
-standard defined by a recognized standards body, or, in the case of
-interfaces specified for a particular programming language, one that
-is widely used among developers working in that language.
-
- The "System Libraries" of an executable work include anything, other
-than the work as a whole, that (a) is included in the normal form of
-packaging a Major Component, but which is not part of that Major
-Component, and (b) serves only to enable use of the work with that
-Major Component, or to implement a Standard Interface for which an
-implementation is available to the public in source code form. A
-"Major Component", in this context, means a major essential component
-(kernel, window system, and so on) of the specific operating system
-(if any) on which the executable work runs, or a compiler used to
-produce the work, or an object code interpreter used to run it.
-
- The "Corresponding Source" for a work in object code form means all
-the source code needed to generate, install, and (for an executable
-work) run the object code and to modify the work, including scripts to
-control those activities. However, it does not include the work's
-System Libraries, or general-purpose tools or generally available free
-programs which are used unmodified in performing those activities but
-which are not part of the work. For example, Corresponding Source
-includes interface definition files associated with source files for
-the work, and the source code for shared libraries and dynamically
-linked subprograms that the work is specifically designed to require,
-such as by intimate data communication or control flow between those
-subprograms and other parts of the work.
-
- The Corresponding Source need not include anything that users
-can regenerate automatically from other parts of the Corresponding
-Source.
-
- The Corresponding Source for a work in source code form is that
-same work.
-
- 2. Basic Permissions.
-
- All rights granted under this License are granted for the term of
-copyright on the Program, and are irrevocable provided the stated
-conditions are met. This License explicitly affirms your unlimited
-permission to run the unmodified Program. The output from running a
-covered work is covered by this License only if the output, given its
-content, constitutes a covered work. This License acknowledges your
-rights of fair use or other equivalent, as provided by copyright law.
-
- You may make, run and propagate covered works that you do not
-convey, without conditions so long as your license otherwise remains
-in force. You may convey covered works to others for the sole purpose
-of having them make modifications exclusively for you, or provide you
-with facilities for running those works, provided that you comply with
-the terms of this License in conveying all material for which you do
-not control copyright. Those thus making or running the covered works
-for you must do so exclusively on your behalf, under your direction
-and control, on terms that prohibit them from making any copies of
-your copyrighted material outside their relationship with you.
-
- Conveying under any other circumstances is permitted solely under
-the conditions stated below. Sublicensing is not allowed; section 10
-makes it unnecessary.
-
- 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
-
- No covered work shall be deemed part of an effective technological
-measure under any applicable law fulfilling obligations under article
-11 of the WIPO copyright treaty adopted on 20 December 1996, or
-similar laws prohibiting or restricting circumvention of such
-measures.
-
- When you convey a covered work, you waive any legal power to forbid
-circumvention of technological measures to the extent such circumvention
-is effected by exercising rights under this License with respect to
-the covered work, and you disclaim any intention to limit operation or
-modification of the work as a means of enforcing, against the work's
-users, your or third parties' legal rights to forbid circumvention of
-technological measures.
-
- 4. Conveying Verbatim Copies.
-
- You may convey verbatim copies of the Program's source code as you
-receive it, in any medium, provided that you conspicuously and
-appropriately publish on each copy an appropriate copyright notice;
-keep intact all notices stating that this License and any
-non-permissive terms added in accord with section 7 apply to the code;
-keep intact all notices of the absence of any warranty; and give all
-recipients a copy of this License along with the Program.
-
- You may charge any price or no price for each copy that you convey,
-and you may offer support or warranty protection for a fee.
-
- 5. Conveying Modified Source Versions.
-
- You may convey a work based on the Program, or the modifications to
-produce it from the Program, in the form of source code under the
-terms of section 4, provided that you also meet all of these conditions:
-
- a) The work must carry prominent notices stating that you modified
- it, and giving a relevant date.
-
- b) The work must carry prominent notices stating that it is
- released under this License and any conditions added under section
- 7. This requirement modifies the requirement in section 4 to
- "keep intact all notices".
-
- c) You must license the entire work, as a whole, under this
- License to anyone who comes into possession of a copy. This
- License will therefore apply, along with any applicable section 7
- additional terms, to the whole of the work, and all its parts,
- regardless of how they are packaged. This License gives no
- permission to license the work in any other way, but it does not
- invalidate such permission if you have separately received it.
-
- d) If the work has interactive user interfaces, each must display
- Appropriate Legal Notices; however, if the Program has interactive
- interfaces that do not display Appropriate Legal Notices, your
- work need not make them do so.
-
- A compilation of a covered work with other separate and independent
-works, which are not by their nature extensions of the covered work,
-and which are not combined with it such as to form a larger program,
-in or on a volume of a storage or distribution medium, is called an
-"aggregate" if the compilation and its resulting copyright are not
-used to limit the access or legal rights of the compilation's users
-beyond what the individual works permit. Inclusion of a covered work
-in an aggregate does not cause this License to apply to the other
-parts of the aggregate.
-
- 6. Conveying Non-Source Forms.
-
- You may convey a covered work in object code form under the terms
-of sections 4 and 5, provided that you also convey the
-machine-readable Corresponding Source under the terms of this License,
-in one of these ways:
-
- a) Convey the object code in, or embodied in, a physical product
- (including a physical distribution medium), accompanied by the
- Corresponding Source fixed on a durable physical medium
- customarily used for software interchange.
-
- b) Convey the object code in, or embodied in, a physical product
- (including a physical distribution medium), accompanied by a
- written offer, valid for at least three years and valid for as
- long as you offer spare parts or customer support for that product
- model, to give anyone who possesses the object code either (1) a
- copy of the Corresponding Source for all the software in the
- product that is covered by this License, on a durable physical
- medium customarily used for software interchange, for a price no
- more than your reasonable cost of physically performing this
- conveying of source, or (2) access to copy the
- Corresponding Source from a network server at no charge.
-
- c) Convey individual copies of the object code with a copy of the
- written offer to provide the Corresponding Source. This
- alternative is allowed only occasionally and noncommercially, and
- only if you received the object code with such an offer, in accord
- with subsection 6b.
-
- d) Convey the object code by offering access from a designated
- place (gratis or for a charge), and offer equivalent access to the
- Corresponding Source in the same way through the same place at no
- further charge. You need not require recipients to copy the
- Corresponding Source along with the object code. If the place to
- copy the object code is a network server, the Corresponding Source
- may be on a different server (operated by you or a third party)
- that supports equivalent copying facilities, provided you maintain
- clear directions next to the object code saying where to find the
- Corresponding Source. Regardless of what server hosts the
- Corresponding Source, you remain obligated to ensure that it is
- available for as long as needed to satisfy these requirements.
-
- e) Convey the object code using peer-to-peer transmission, provided
- you inform other peers where the object code and Corresponding
- Source of the work are being offered to the general public at no
- charge under subsection 6d.
-
- A separable portion of the object code, whose source code is excluded
-from the Corresponding Source as a System Library, need not be
-included in conveying the object code work.
-
- A "User Product" is either (1) a "consumer product", which means any
-tangible personal property which is normally used for personal, family,
-or household purposes, or (2) anything designed or sold for incorporation
-into a dwelling. In determining whether a product is a consumer product,
-doubtful cases shall be resolved in favor of coverage. For a particular
-product received by a particular user, "normally used" refers to a
-typical or common use of that class of product, regardless of the status
-of the particular user or of the way in which the particular user
-actually uses, or expects or is expected to use, the product. A product
-is a consumer product regardless of whether the product has substantial
-commercial, industrial or non-consumer uses, unless such uses represent
-the only significant mode of use of the product.
-
- "Installation Information" for a User Product means any methods,
-procedures, authorization keys, or other information required to install
-and execute modified versions of a covered work in that User Product from
-a modified version of its Corresponding Source. The information must
-suffice to ensure that the continued functioning of the modified object
-code is in no case prevented or interfered with solely because
-modification has been made.
-
- If you convey an object code work under this section in, or with, or
-specifically for use in, a User Product, and the conveying occurs as
-part of a transaction in which the right of possession and use of the
-User Product is transferred to the recipient in perpetuity or for a
-fixed term (regardless of how the transaction is characterized), the
-Corresponding Source conveyed under this section must be accompanied
-by the Installation Information. But this requirement does not apply
-if neither you nor any third party retains the ability to install
-modified object code on the User Product (for example, the work has
-been installed in ROM).
-
- The requirement to provide Installation Information does not include a
-requirement to continue to provide support service, warranty, or updates
-for a work that has been modified or installed by the recipient, or for
-the User Product in which it has been modified or installed. Access to a
-network may be denied when the modification itself materially and
-adversely affects the operation of the network or violates the rules and
-protocols for communication across the network.
-
- Corresponding Source conveyed, and Installation Information provided,
-in accord with this section must be in a format that is publicly
-documented (and with an implementation available to the public in
-source code form), and must require no special password or key for
-unpacking, reading or copying.
-
- 7. Additional Terms.
-
- "Additional permissions" are terms that supplement the terms of this
-License by making exceptions from one or more of its conditions.
-Additional permissions that are applicable to the entire Program shall
-be treated as though they were included in this License, to the extent
-that they are valid under applicable law. If additional permissions
-apply only to part of the Program, that part may be used separately
-under those permissions, but the entire Program remains governed by
-this License without regard to the additional permissions.
-
- When you convey a copy of a covered work, you may at your option
-remove any additional permissions from that copy, or from any part of
-it. (Additional permissions may be written to require their own
-removal in certain cases when you modify the work.) You may place
-additional permissions on material, added by you to a covered work,
-for which you have or can give appropriate copyright permission.
-
- Notwithstanding any other provision of this License, for material you
-add to a covered work, you may (if authorized by the copyright holders of
-that material) supplement the terms of this License with terms:
-
- a) Disclaiming warranty or limiting liability differently from the
- terms of sections 15 and 16 of this License; or
-
- b) Requiring preservation of specified reasonable legal notices or
- author attributions in that material or in the Appropriate Legal
- Notices displayed by works containing it; or
-
- c) Prohibiting misrepresentation of the origin of that material, or
- requiring that modified versions of such material be marked in
- reasonable ways as different from the original version; or
-
- d) Limiting the use for publicity purposes of names of licensors or
- authors of the material; or
-
- e) Declining to grant rights under trademark law for use of some
- trade names, trademarks, or service marks; or
-
- f) Requiring indemnification of licensors and authors of that
- material by anyone who conveys the material (or modified versions of
- it) with contractual assumptions of liability to the recipient, for
- any liability that these contractual assumptions directly impose on
- those licensors and authors.
-
- All other non-permissive additional terms are considered "further
-restrictions" within the meaning of section 10. If the Program as you
-received it, or any part of it, contains a notice stating that it is
-governed by this License along with a term that is a further
-restriction, you may remove that term. If a license document contains
-a further restriction but permits relicensing or conveying under this
-License, you may add to a covered work material governed by the terms
-of that license document, provided that the further restriction does
-not survive such relicensing or conveying.
-
- If you add terms to a covered work in accord with this section, you
-must place, in the relevant source files, a statement of the
-additional terms that apply to those files, or a notice indicating
-where to find the applicable terms.
-
- Additional terms, permissive or non-permissive, may be stated in the
-form of a separately written license, or stated as exceptions;
-the above requirements apply either way.
-
- 8. Termination.
-
- You may not propagate or modify a covered work except as expressly
-provided under this License. Any attempt otherwise to propagate or
-modify it is void, and will automatically terminate your rights under
-this License (including any patent licenses granted under the third
-paragraph of section 11).
-
- However, if you cease all violation of this License, then your
-license from a particular copyright holder is reinstated (a)
-provisionally, unless and until the copyright holder explicitly and
-finally terminates your license, and (b) permanently, if the copyright
-holder fails to notify you of the violation by some reasonable means
-prior to 60 days after the cessation.
-
- Moreover, your license from a particular copyright holder is
-reinstated permanently if the copyright holder notifies you of the
-violation by some reasonable means, this is the first time you have
-received notice of violation of this License (for any work) from that
-copyright holder, and you cure the violation prior to 30 days after
-your receipt of the notice.
-
- Termination of your rights under this section does not terminate the
-licenses of parties who have received copies or rights from you under
-this License. If your rights have been terminated and not permanently
-reinstated, you do not qualify to receive new licenses for the same
-material under section 10.
-
- 9. Acceptance Not Required for Having Copies.
-
- You are not required to accept this License in order to receive or
-run a copy of the Program. Ancillary propagation of a covered work
-occurring solely as a consequence of using peer-to-peer transmission
-to receive a copy likewise does not require acceptance. However,
-nothing other than this License grants you permission to propagate or
-modify any covered work. These actions infringe copyright if you do
-not accept this License. Therefore, by modifying or propagating a
-covered work, you indicate your acceptance of this License to do so.
-
- 10. Automatic Licensing of Downstream Recipients.
-
- Each time you convey a covered work, the recipient automatically
-receives a license from the original licensors, to run, modify and
-propagate that work, subject to this License. You are not responsible
-for enforcing compliance by third parties with this License.
-
- An "entity transaction" is a transaction transferring control of an
-organization, or substantially all assets of one, or subdividing an
-organization, or merging organizations. If propagation of a covered
-work results from an entity transaction, each party to that
-transaction who receives a copy of the work also receives whatever
-licenses to the work the party's predecessor in interest had or could
-give under the previous paragraph, plus a right to possession of the
-Corresponding Source of the work from the predecessor in interest, if
-the predecessor has it or can get it with reasonable efforts.
-
- You may not impose any further restrictions on the exercise of the
-rights granted or affirmed under this License. For example, you may
-not impose a license fee, royalty, or other charge for exercise of
-rights granted under this License, and you may not initiate litigation
-(including a cross-claim or counterclaim in a lawsuit) alleging that
-any patent claim is infringed by making, using, selling, offering for
-sale, or importing the Program or any portion of it.
-
- 11. Patents.
-
- A "contributor" is a copyright holder who authorizes use under this
-License of the Program or a work on which the Program is based. The
-work thus licensed is called the contributor's "contributor version".
-
- A contributor's "essential patent claims" are all patent claims
-owned or controlled by the contributor, whether already acquired or
-hereafter acquired, that would be infringed by some manner, permitted
-by this License, of making, using, or selling its contributor version,
-but do not include claims that would be infringed only as a
-consequence of further modification of the contributor version. For
-purposes of this definition, "control" includes the right to grant
-patent sublicenses in a manner consistent with the requirements of
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
this License.
- Each contributor grants you a non-exclusive, worldwide, royalty-free
-patent license under the contributor's essential patent claims, to
-make, use, sell, offer for sale, import and otherwise run, modify and
-propagate the contents of its contributor version.
-
- In the following three paragraphs, a "patent license" is any express
-agreement or commitment, however denominated, not to enforce a patent
-(such as an express permission to practice a patent or covenant not to
-sue for patent infringement). To "grant" such a patent license to a
-party means to make such an agreement or commitment not to enforce a
-patent against the party.
-
- If you convey a covered work, knowingly relying on a patent license,
-and the Corresponding Source of the work is not available for anyone
-to copy, free of charge and under the terms of this License, through a
-publicly available network server or other readily accessible means,
-then you must either (1) cause the Corresponding Source to be so
-available, or (2) arrange to deprive yourself of the benefit of the
-patent license for this particular work, or (3) arrange, in a manner
-consistent with the requirements of this License, to extend the patent
-license to downstream recipients. "Knowingly relying" means you have
-actual knowledge that, but for the patent license, your conveying the
-covered work in a country, or your recipient's use of the covered work
-in a country, would infringe one or more identifiable patents in that
-country that you have reason to believe are valid.
-
- If, pursuant to or in connection with a single transaction or
-arrangement, you convey, or propagate by procuring conveyance of, a
-covered work, and grant a patent license to some of the parties
-receiving the covered work authorizing them to use, propagate, modify
-or convey a specific copy of the covered work, then the patent license
-you grant is automatically extended to all recipients of the covered
-work and works based on it.
-
- A patent license is "discriminatory" if it does not include within
-the scope of its coverage, prohibits the exercise of, or is
-conditioned on the non-exercise of one or more of the rights that are
-specifically granted under this License. You may not convey a covered
-work if you are a party to an arrangement with a third party that is
-in the business of distributing software, under which you make payment
-to the third party based on the extent of your activity of conveying
-the work, and under which the third party grants, to any of the
-parties who would receive the covered work from you, a discriminatory
-patent license (a) in connection with copies of the covered work
-conveyed by you (or copies made from those copies), or (b) primarily
-for and in connection with specific products or compilations that
-contain the covered work, unless you entered into that arrangement,
-or that patent license was granted, prior to 28 March 2007.
-
- Nothing in this License shall be construed as excluding or limiting
-any implied license or other defenses to infringement that may
-otherwise be available to you under applicable patent law.
-
- 12. No Surrender of Others' Freedom.
-
- If conditions are imposed on you (whether by court order, agreement or
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot convey a
-covered work so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you may
-not convey it at all. For example, if you agree to terms that obligate you
-to collect a royalty for further conveying from those to whom you convey
-the Program, the only way you could satisfy both those terms and this
-License would be to refrain entirely from conveying the Program.
-
- 13. Use with the GNU Affero General Public License.
-
- Notwithstanding any other provision of this License, you have
-permission to link or combine any covered work with a work licensed
-under version 3 of the GNU Affero General Public License into a single
-combined work, and to convey the resulting work. The terms of this
-License will continue to apply to the part which is the covered work,
-but the special requirements of the GNU Affero General Public License,
-section 13, concerning interaction through a network will apply to the
-combination as such.
-
- 14. Revised Versions of this License.
-
- The Free Software Foundation may publish revised and/or new versions of
-the GNU General Public License from time to time. Such new versions will
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
- Each version is given a distinguishing version number. If the
-Program specifies that a certain numbered version of the GNU General
-Public License "or any later version" applies to it, you have the
-option of following the terms and conditions either of that numbered
-version or of any later version published by the Free Software
-Foundation. If the Program does not specify a version number of the
-GNU General Public License, you may choose any version ever published
-by the Free Software Foundation.
-
- If the Program specifies that a proxy can decide which future
-versions of the GNU General Public License can be used, that proxy's
-public statement of acceptance of a version permanently authorizes you
-to choose that version for the Program.
-
- Later license versions may give you additional or different
-permissions. However, no additional obligations are imposed on any
-author or copyright holder as a result of your choosing to follow a
-later version.
-
- 15. Disclaimer of Warranty.
-
- THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
-APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
-HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
-OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
-IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
-ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
- 16. Limitation of Liability.
-
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
-THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
-GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
-USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
-DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
-PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
-EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGES.
-
- 17. Interpretation of Sections 15 and 16.
-
- If the disclaimer of warranty and limitation of liability provided
-above cannot be given local legal effect according to their terms,
-reviewing courts shall apply local law that most closely approximates
-an absolute waiver of all civil liability in connection with the
-Program, unless a warranty or assumption of liability accompanies a
-copy of the Program in return for a fee.
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
-state the exclusion of warranty; and each file should have at least
+convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
- This program is free software: you can redistribute it and/or modify
+ This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
+ the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
- If the program does terminal interaction, make it output a short
-notice like this when it starts in an interactive mode:
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
- <program> Copyright (C) <year> <name of author>
- This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, your program's commands
-might be different; for a GUI interface, you would use an "about box".
-
- You should also get your employer (if you work as a programmer) or school,
-if any, to sign a "copyright disclaimer" for the program, if necessary.
-For more information on this, and how to apply and follow the GNU GPL, see
-<http://www.gnu.org/licenses/>.
-
- The GNU General Public License does not permit incorporating your program
-into proprietary programs. If your program is a subroutine library, you
-may consider it more useful to permit linking proprietary applications with
-the library. If this is what you want to do, use the GNU Lesser General
-Public License instead of this License. But first, please read
-<http://www.gnu.org/philosophy/why-not-lgpl.html>.
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.
diff --git a/tap.c b/tap.c
index f666b64..517d5c6 100644
--- a/tap.c
+++ b/tap.c
@@ -1,325 +1,325 @@
/*
libtap - Write tests in C
-Copyright (C) 2011 Jake Gelbman <[email protected]>
-This file is licensed under the GPL v3
+Copyright 2012 Jake Gelbman <[email protected]>
+This file is licensed under the GPLv2
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
cplan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
note("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
printf("%sok %d", test ? "" : "not ", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
if (*name)
diag(" Failed%s test '%s'\n at %s line %d.",
todo_mesg ? " (TODO)" : "", name, file, line);
else
diag(" Failed%s test at %s line %d.",
todo_mesg ? " (TODO)" : "", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static void
vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
char *mesg, *line;
int i;
if (!fmt)
return;
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
fprintf(fh, "# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
return;
}
int
diag (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stderr, fmt, args);
va_end(args);
return 0;
}
int
note (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stdout, fmt, args);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 255;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
if (expected_tests == NO_PLAN)
retval = failed_tests;
else
retval = expected_tests - current_test + failed_tests;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
skippy (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
note("skip %s\n", why);
}
free(why);
}
void
ctodo (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
cendtodo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <sys/param.h>
#include <regex.h>
#if defined __APPLE__ || defined BSD
#define MAP_ANONYMOUS MAP_ANON
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
diff --git a/tap.h b/tap.h
index 89484f4..503ab23 100644
--- a/tap.h
+++ b/tap.h
@@ -1,114 +1,114 @@
/*
libtap - Write tests in C
-Copyright (C) 2011 Jake Gelbman <[email protected]>
-This file is licensed under the GPL v3
+Copyright 2012 Jake Gelbman <[email protected]>
+This file is licensed under the GPLv2
*/
#ifndef __TAP_H__
#define __TAP_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifndef va_copy
#ifdef __va_copy
#define va_copy __va_copy
#else
#define va_copy(d, s) ((d) = (s))
#endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args);
int ok_at_loc (const char *file, int line, int test, const char *fmt,
...);
int is_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int isnt_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int cmp_ok_at_loc (const char *file, int line, int a, const char *op,
int b, const char *fmt, ...);
int bail_out (int ignore, const char *fmt, ...);
void cplan (int tests, const char *fmt, ...);
int diag (const char *fmt, ...);
int note (const char *fmt, ...);
int exit_status (void);
void skippy (int n, const char *fmt, ...);
void ctodo (int ignore, const char *fmt, ...);
void cendtodo (void);
#define NO_PLAN -1
#define SKIP_ALL -2
#define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define plan(...) cplan(__VA_ARGS__, NULL)
#define done_testing() return exit_status()
#define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
#define pass(...) ok(1, "" __VA_ARGS__)
#define fail(...) ok(0, "" __VA_ARGS__)
#define skip(test, ...) do {if (test) {skippy(__VA_ARGS__, NULL); break;}
#define endskip } while (0)
#define todo(...) ctodo(0, "" __VA_ARGS__, NULL)
#define endtodo cendtodo()
#define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
#define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
#ifdef _WIN32
#define like(...) skippy(1, "like is not implemented on MSWin32")
#define unlike like
#define dies_ok_common(...) \
skippy(1, "Death detection is not supported on MSWin32")
#else
#define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
#define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
int like_at_loc (int for_match, const char *file, int line,
const char *got, const char *expected,
const char *fmt, ...);
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int tap_test_died (int status);
#define dies_ok_common(for_death, code, ...) \
do { \
int cpid; \
int it_died; \
tap_test_died(1); \
cpid = fork(); \
switch (cpid) { \
case -1: \
perror("fork error"); \
exit(1); \
case 0: \
close(1); \
close(2); \
code \
tap_test_died(0); \
exit(0); \
} \
if (waitpid(cpid, NULL, 0) < 0) { \
perror("waitpid error"); \
exit(1); \
} \
it_died = tap_test_died(0); \
if (!it_died) \
{code} \
ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \
} while (0)
#endif
#ifdef __cplusplus
}
#endif
#endif
|
zorgnax/libtap
|
e0faf0a0a317f0b1515a65d2912f13a8941c5f0e
|
Add Travis CI config
|
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..5920737
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,9 @@
+language: erlang # no C/shell language support; use least-loaded worker(s)
+
+before_install: sudo apt-get install -y libtest-differences-perl
+
+install: make install
+
+script: make test
+
+after_script: make uninstall
|
zorgnax/libtap
|
5cf810f0832ddbaed1f3769296e4cd532f7c3a33
|
Ignore build products for Unix-like systems
|
diff --git a/.gitignore b/.gitignore
index b8cd647..64a4dfc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,14 @@
+*.a
+*.o
*.sw?
+# compiled tests
+/t/cmpok
+/t/diesok
+/t/is
+/t/like
+/t/notediag
+/t/simple
+/t/skip
+/t/synopsis
+/t/todo
|
zorgnax/libtap
|
3e7643f76a013feb84e2449406a693f262814b21
|
Indent with spaces
|
diff --git a/INSTALL b/INSTALL
index 1e378ca..2ed4543 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,42 +1,42 @@
To install libtap on a unix-like system:
$ make
$ make check
$ make install
To compile with gcc -ansi, run
- $ make ANSI=1
+ $ make ANSI=1
On Windows, the library can be created by first setting up
the correct development environment variables. Usually this
is done by running vcvars32.bat included in the visual studio
distribution. You should also install gnu make which can be
found at http://gnuwin32.sourceforge.net/packages/make.htm.
And you should have perl to run the tests although this isnt
absolutely necessary. Once this is done, you should be able to
run the following:
> make -f Makefile.win
> make check
Alternatively, you might want to use the visual studio project file
included by Alexander Kahl (e-user).
If you want to use it directly in another project, you can copy tap.c
and tap.h there and it shouldn't have a problem compiling.
$ ls
tap.c tap.h test.c
$ cat test.c
#include "tap.h"
int main () {
plan(1);
ok(50 + 5, "foo %s", "bar");
done_testing();
}
$ gcc test.c tap.c
$ a.out
1..1
ok 1 - foo bar
|
zorgnax/libtap
|
c588c134dcadd96aca093b1156387638c5f6aae0
|
Combine #ifdef statements for MAP_ANONYMOUS macro
|
diff --git a/tap.c b/tap.c
index e5a5171..f666b64 100644
--- a/tap.c
+++ b/tap.c
@@ -1,330 +1,325 @@
/*
libtap - Write tests in C
Copyright (C) 2011 Jake Gelbman <[email protected]>
This file is licensed under the GPL v3
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
cplan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
note("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
printf("%sok %d", test ? "" : "not ", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
if (*name)
diag(" Failed%s test '%s'\n at %s line %d.",
todo_mesg ? " (TODO)" : "", name, file, line);
else
diag(" Failed%s test at %s line %d.",
todo_mesg ? " (TODO)" : "", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static void
vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
char *mesg, *line;
int i;
if (!fmt)
return;
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
fprintf(fh, "# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
return;
}
int
diag (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stderr, fmt, args);
va_end(args);
return 0;
}
int
note (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stdout, fmt, args);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 255;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
if (expected_tests == NO_PLAN)
retval = failed_tests;
else
retval = expected_tests - current_test + failed_tests;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
skippy (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
note("skip %s\n", why);
}
free(why);
}
void
ctodo (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
cendtodo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
+#include <sys/param.h>
#include <regex.h>
-#ifdef __APPLE__
-#define MAP_ANONYMOUS MAP_ANON
-#endif
-
-#include <sys/param.h>
-#ifdef BSD
-#include <sys/mman.h>
+#if defined __APPLE__ || defined BSD
#define MAP_ANONYMOUS MAP_ANON
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
|
zorgnax/libtap
|
3985ee37ddc36b9641088617e1f9a03d7752b1fe
|
make tap work on freebsd
|
diff --git a/tap.c b/tap.c
index 77aaee0..e5a5171 100644
--- a/tap.c
+++ b/tap.c
@@ -1,324 +1,330 @@
/*
libtap - Write tests in C
Copyright (C) 2011 Jake Gelbman <[email protected]>
This file is licensed under the GPL v3
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
cplan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
note("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
printf("%sok %d", test ? "" : "not ", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
if (*name)
diag(" Failed%s test '%s'\n at %s line %d.",
todo_mesg ? " (TODO)" : "", name, file, line);
else
diag(" Failed%s test at %s line %d.",
todo_mesg ? " (TODO)" : "", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static void
vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
char *mesg, *line;
int i;
if (!fmt)
return;
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
fprintf(fh, "# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
return;
}
int
diag (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stderr, fmt, args);
va_end(args);
return 0;
}
int
note (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stdout, fmt, args);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 255;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
if (expected_tests == NO_PLAN)
retval = failed_tests;
else
retval = expected_tests - current_test + failed_tests;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
skippy (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
note("skip %s\n", why);
}
free(why);
}
void
ctodo (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
cendtodo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <regex.h>
#ifdef __APPLE__
#define MAP_ANONYMOUS MAP_ANON
#endif
+#include <sys/param.h>
+#ifdef BSD
+#include <sys/mman.h>
+#define MAP_ANONYMOUS MAP_ANON
+#endif
+
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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;
}
#endif
|
zorgnax/libtap
|
b7d9e585098d940a24afb0651c29f80f7251a6e2
|
Declaration moved out of statement for C90 compliance.
|
diff --git a/tap.c b/tap.c
index 7dcd0e9..77aaee0 100644
--- a/tap.c
+++ b/tap.c
@@ -1,324 +1,324 @@
/*
libtap - Write tests in C
Copyright (C) 2011 Jake Gelbman <[email protected]>
This file is licensed under the GPL v3
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "tap.h"
static int expected_tests = NO_PLAN;
static int failed_tests;
static int current_test;
static char *todo_mesg;
static char *
vstrdupf (const char *fmt, va_list args) {
char *str;
int size;
va_list args2;
va_copy(args2, args);
if (!fmt)
fmt = "";
size = vsnprintf(NULL, 0, fmt, args2) + 2;
str = malloc(size);
vsprintf(str, fmt, args);
va_end(args2);
return str;
}
void
cplan (int tests, const char *fmt, ...) {
expected_tests = tests;
if (tests == SKIP_ALL) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
printf("1..0 ");
note("SKIP %s\n", why);
exit(0);
}
if (tests != NO_PLAN) {
printf("1..%d\n", tests);
}
}
int
vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args)
{
char *name = vstrdupf(fmt, args);
printf("%sok %d", test ? "" : "not ", ++current_test);
if (*name)
printf(" - %s", name);
if (todo_mesg) {
printf(" # TODO");
if (*todo_mesg)
printf(" %s", todo_mesg);
}
printf("\n");
if (!test) {
if (*name)
diag(" Failed%s test '%s'\n at %s line %d.",
todo_mesg ? " (TODO)" : "", name, file, line);
else
diag(" Failed%s test at %s line %d.",
todo_mesg ? " (TODO)" : "", file, line);
if (!todo_mesg)
failed_tests++;
}
free(name);
return test;
}
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;
}
static int
mystrcmp (const char *a, const char *b) {
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
}
#define eq(a, b) (!mystrcmp(a, b))
#define ne(a, b) (mystrcmp(a, b))
int
is_at_loc (const char *file, int line, const char *got, const char *expected,
const char *fmt, ...)
{
int test = eq(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: '%s'", expected);
}
return test;
}
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;
}
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;
}
static void
vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
char *mesg, *line;
int i;
if (!fmt)
return;
mesg = vstrdupf(fmt, args);
line = mesg;
for (i = 0; *line; i++) {
char c = mesg[i];
if (!c || c == '\n') {
mesg[i] = '\0';
fprintf(fh, "# %s\n", line);
if (!c)
break;
mesg[i] = c;
line = mesg + i + 1;
}
}
free(mesg);
return;
}
int
diag (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stderr, fmt, args);
va_end(args);
return 0;
}
int
note (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vdiag_to_fh(stdout, fmt, args);
va_end(args);
return 0;
}
int
exit_status () {
int retval = 0;
if (expected_tests == NO_PLAN) {
printf("1..%d\n", current_test);
}
else if (current_test != expected_tests) {
diag("Looks like you planned %d test%s but ran %d.",
expected_tests, expected_tests > 1 ? "s" : "", current_test);
retval = 255;
}
if (failed_tests) {
diag("Looks like you failed %d test%s of %d run.",
failed_tests, failed_tests > 1 ? "s" : "", current_test);
if (expected_tests == NO_PLAN)
retval = failed_tests;
else
retval = expected_tests - current_test + failed_tests;
}
return retval;
}
int
bail_out (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf("Bail out! ");
vprintf(fmt, args);
printf("\n");
va_end(args);
exit(255);
return 0;
}
void
skippy (int n, const char *fmt, ...) {
char *why;
va_list args;
va_start(args, fmt);
why = vstrdupf(fmt, args);
va_end(args);
while (n --> 0) {
printf("ok %d ", ++current_test);
note("skip %s\n", why);
}
free(why);
}
void
ctodo (int ignore, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
todo_mesg = vstrdupf(fmt, args);
va_end(args);
}
void
cendtodo () {
free(todo_mesg);
todo_mesg = NULL;
}
#ifndef _WIN32
#include <sys/mman.h>
#include <regex.h>
#ifdef __APPLE__
#define MAP_ANONYMOUS MAP_ANON
#endif
/* Create a shared memory int to keep track of whether a piece of code executed
dies. to be used in the dies_ok and lives_ok macros */
int
tap_test_died (int status) {
static int *test_died = NULL;
int prev;
if (!test_died) {
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*test_died = 0;
}
prev = *test_died;
*test_died = status;
return prev;
}
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_list args;
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;
}
#endif
|
zorgnax/libtap
|
94859c6f5f84a615c6370d0dd45db28662ab3c5c
|
Removes declaration in statements. (When using older compilers, declarations in statements are not allowed - C90 style)
|
diff --git a/tap.h b/tap.h
index 09935e8..89484f4 100644
--- a/tap.h
+++ b/tap.h
@@ -1,112 +1,114 @@
/*
libtap - Write tests in C
Copyright (C) 2011 Jake Gelbman <[email protected]>
This file is licensed under the GPL v3
*/
#ifndef __TAP_H__
#define __TAP_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifndef va_copy
#ifdef __va_copy
#define va_copy __va_copy
#else
#define va_copy(d, s) ((d) = (s))
#endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int vok_at_loc (const char *file, int line, int test, const char *fmt,
va_list args);
int ok_at_loc (const char *file, int line, int test, const char *fmt,
...);
int is_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int isnt_at_loc (const char *file, int line, const char *got,
const char *expected, const char *fmt, ...);
int cmp_ok_at_loc (const char *file, int line, int a, const char *op,
int b, const char *fmt, ...);
int bail_out (int ignore, const char *fmt, ...);
void cplan (int tests, const char *fmt, ...);
int diag (const char *fmt, ...);
int note (const char *fmt, ...);
int exit_status (void);
void skippy (int n, const char *fmt, ...);
void ctodo (int ignore, const char *fmt, ...);
void cendtodo (void);
#define NO_PLAN -1
#define SKIP_ALL -2
#define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
#define plan(...) cplan(__VA_ARGS__, NULL)
#define done_testing() return exit_status()
#define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
#define pass(...) ok(1, "" __VA_ARGS__)
#define fail(...) ok(0, "" __VA_ARGS__)
#define skip(test, ...) do {if (test) {skippy(__VA_ARGS__, NULL); break;}
#define endskip } while (0)
#define todo(...) ctodo(0, "" __VA_ARGS__, NULL)
#define endtodo cendtodo()
#define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
#define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
#ifdef _WIN32
#define like(...) skippy(1, "like is not implemented on MSWin32")
#define unlike like
#define dies_ok_common(...) \
skippy(1, "Death detection is not supported on MSWin32")
#else
#define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
#define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
int like_at_loc (int for_match, const char *file, int line,
const char *got, const char *expected,
const char *fmt, ...);
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int tap_test_died (int status);
#define dies_ok_common(for_death, code, ...) \
do { \
+ int cpid; \
+ int it_died; \
tap_test_died(1); \
- int cpid = fork(); \
+ cpid = fork(); \
switch (cpid) { \
case -1: \
perror("fork error"); \
exit(1); \
case 0: \
close(1); \
close(2); \
code \
tap_test_died(0); \
exit(0); \
} \
if (waitpid(cpid, NULL, 0) < 0) { \
perror("waitpid error"); \
exit(1); \
} \
- int it_died = tap_test_died(0); \
+ it_died = tap_test_died(0); \
if (!it_died) \
{code} \
ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \
} while (0)
#endif
#ifdef __cplusplus
}
#endif
#endif
|
zorgnax/libtap
|
b993a60c5bc3451ca824e293668440d5d4490646
|
Combine config.mk and t/Makefile into Makefile. Separate windows related stuff to its own Makefile.
|
diff --git a/INSTALL b/INSTALL
index 6db3249..1e378ca 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,42 +1,42 @@
To install libtap on a unix-like system:
$ make
$ make check
$ make install
To compile with gcc -ansi, run
$ make ANSI=1
On Windows, the library can be created by first setting up
the correct development environment variables. Usually this
is done by running vcvars32.bat included in the visual studio
distribution. You should also install gnu make which can be
found at http://gnuwin32.sourceforge.net/packages/make.htm.
And you should have perl to run the tests although this isnt
absolutely necessary. Once this is done, you should be able to
run the following:
- > make GNU=
+ > make -f Makefile.win
> make check
Alternatively, you might want to use the visual studio project file
included by Alexander Kahl (e-user).
If you want to use it directly in another project, you can copy tap.c
and tap.h there and it shouldn't have a problem compiling.
$ ls
tap.c tap.h test.c
$ cat test.c
#include "tap.h"
int main () {
plan(1);
ok(50 + 5, "foo %s", "bar");
done_testing();
}
$ gcc test.c tap.c
$ a.out
1..1
ok 1 - foo bar
diff --git a/Makefile b/Makefile
index 55bed02..750ae44 100644
--- a/Makefile
+++ b/Makefile
@@ -1,30 +1,53 @@
-include config.mk
+CFLAGS = -g -Wall -I.
+CC = gcc
+TESTS = $(patsubst %.c, %, $(wildcard t/*.c))
+
+ifdef ANSI
+ # -D_BSD_SOURCE for MAP_ANONYMOUS
+ CFLAGS += -ansi -D_BSD_SOURCE
+ LDLIBS += -lbsd-compat
+endif
+
+%:
+ $(CC) $(LDFLAGS) $(TARGET_ARCH) $(filter %.o %.a %.so, $^) $(LDLIBS) -o $@
+
+%.o:
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $(filter %.c, $^) $(LDLIBS) -o $@
+
+%.a:
+ $(AR) rcs $@ $(filter %.o, $^)
+
+%.so:
+ $(CC) -shared $(LDFLAGS) $(TARGET_ARCH) $(filter %.o, $^) $(LDLIBS) -o $@
-all: $(TAPLIB)
- $(MAKE) -C t/ all
+all: libtap.a tests
-$(TAPLIB): tap$(_O)
-tap$(_O): tap.c tap.h
+libtap.a: tap.o
+
+tap.o: tap.c tap.h
+
+tests: $(TESTS)
+
+$(TESTS): %: %.o libtap.a
+
+$(patsubst %, %.o, $(TESTS)): %.o: %.c tap.h
clean:
- $(RM) -rv $(TAPLIB) *.o *.obj *.lib *.pdb *.ilk _C
- $(MAKE) -C t/ clean
+ rm -rf *.o t/*.o libtap.a $(TESTS)
-ifdef GNU
-install: $(TAPLIB) tap.h
- sudo cp $(TAPLIB) /usr/lib
+install: libtap.a tap.h
+ sudo cp libtap.a /usr/lib
sudo cp tap.h /usr/include
uninstall:
- sudo $(RM) /usr/lib/$(TAPLIB) /usr/include/tap.h
-endif
+ sudo rm /usr/lib/libtap.a /usr/include/tap.h
dist:
- $(RM) -v libtap.zip
+ rm libtap.zip
zip -r libtap *
-check: all
+check test: all
prove
-.PHONY: all clean install uninstall dist check
+.PHONY: all clean install uninstall dist check test tests
diff --git a/Makefile.win b/Makefile.win
new file mode 100644
index 0000000..694d679
--- /dev/null
+++ b/Makefile.win
@@ -0,0 +1,37 @@
+CFLAGS = /Zi /Wall /wd4255 /wd4996 /wd4127 /wd4820 /wd4100 /wd4619 \
+ /wd4514 /wd4668 /I.
+CC = cl /nologo
+TESTS = $(patsubst %.c, %.exe, $(wildcard t/*.c))
+
+%.exe:
+ $(CC) $(LDFLAGS) $(filter %.obj %.lib %.dll, $^) $(LDLIBS) /Fe $@
+
+%.o:
+ $(CC) $(CFLAGS) $(CPPFLAGS) /c $(filter %.c, $^) $(LDLIBS) /Fo $@
+
+%.lib:
+ lib /nologo /out:$@ $(filter %.obj, $^)
+
+%.dll:
+ lib /nologo /out:$@ $(filter %.obj, $^)
+
+all: tap.lib tests
+
+tap.lib: tap.obj
+
+tap.obj: tap.c tap.h
+
+tests: $(TESTS)
+
+$(TESTS): %.exe: %.obj tap.lib
+
+$(patsubst %.exe, %.obj, $(TESTS)): %.obj: %.c tap.h
+
+clean:
+ rm -rf *.obj t/*.obj tap.lib $(TESTS)
+
+check test: all
+ prove
+
+.PHONY: all clean check test tests
+
diff --git a/config.mk b/config.mk
deleted file mode 100644
index 6987901..0000000
--- a/config.mk
+++ /dev/null
@@ -1,47 +0,0 @@
-GNU = 1
-MAKE = make
-CFLAGS = $(DEBUG)
-ifdef GNU
- ALLCFLAGS = -Wall $(CFLAGS)
- ifdef ANSI
- # -D_BSD_SOURCE for MAP_ANONYMOUS
- ALLCFLAGS += -ansi -D_BSD_SOURCE
- LDLIBS += -lbsd-compat
- endif
- DEBUG = -g
- CCFLAGS = -c
- CCOUT = -o
- CLOUT = -o
- PIC = -fPIC
- _O = .o
- _X =
- _A = .a
- _SO = .so
- TAPLIB = libtap.a
- STATICLIB.o = $(AR) rcs $@ $(filter %$(_O), $^)
- DYNAMICLIB.o = $(CC) -shared -o $@ $(filter %$(_O), $^)
-else
- CC = cl /nologo
- ALLCFLAGS = /Wall /wd4255 /wd4996 /wd4127 /wd4820 \
- /wd4100 /wd4619 /wd4514 /wd4668 $(CFLAGS)
- DEBUG = /Zi
- CCFLAGS = /c
- CCOUT = /Fo
- CLOUT = /Fe
- PIC =
- _O = .obj
- _X = .exe
- _A = .lib
- _SO = .dll
- TAPLIB = tap.lib
- STATICLIB.o = lib /nologo /out:$@ $(filter %$(_O), $^)
- DYNAMICLIB.o = lib /nologo /out:$@ $(filter %$(_O), $^)
-endif
-COMPILE.c = $(CC) $(CCFLAGS) $(CPPFLAGS) $(ALLCFLAGS) $(CCOUT)$@ $(filter %.c, $^)
-LINK.o = $(CC) $(ALLCFLAGS) $(CLOUT)$@ $(filter %$(_O) %.a %.so %.lib %.dll, $^) $(LDFLAGS) $(LDLIBS)
-
-%$(_X):; $(LINK.o)
-%$(_A):; $(STATICLIB.o)
-%$(_SO):; $(DYNAMICLIB.o)
-%$(_O):; $(COMPILE.c)
-
diff --git a/t/Makefile b/t/Makefile
deleted file mode 100644
index d46fc78..0000000
--- a/t/Makefile
+++ /dev/null
@@ -1,21 +0,0 @@
-include ../config.mk
-
-CFLAGS += -I..
-
-X := simple diesok notediag skip todo is like cmpok synopsis
-X := $(patsubst %, %$(_X), $(X))
-O = $(patsubst %$(_X), %$(_O), $(X))
-
-all: $(X) ../$(TAPLIB)
-
-../$(TAPLIB):
- $(error error $(TAPLIB) needs to be built)
-
-$(O): %$(_O): %.c ../tap.h
-$(X): %$(_X): %$(_O) ../$(TAPLIB)
-
-clean:
- $(RM) -rv $(X) *.o *.obj *.lib *.pdb *.ilk _C
-
-.PHONY: all clean
-
diff --git a/t/tap.t b/t/tap.t
index d6ef667..8a8e54d 100755
--- a/t/tap.t
+++ b/t/tap.t
@@ -1,211 +1,211 @@
#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 9;
use Test::Differences;
my $x = $^O eq 'MSWin32' ? ".exe" : "";
eq_or_diff ~~`t/cmpok$x 2>&1`, <<'END', "cmp_ok";
1..9
not ok 1
-# Failed test at cmpok.c line 6.
+# Failed test at t/cmpok.c line 6.
# 420
# >
# 666
not ok 2 - the number 23 is definitely 55
# Failed test 'the number 23 is definitely 55'
-# at cmpok.c line 7.
+# at t/cmpok.c line 7.
# 23
# ==
# 55
not ok 3
-# Failed test at cmpok.c line 8.
+# Failed test at t/cmpok.c line 8.
# 23
# ==
# 55
ok 4
# unrecognized operator 'frob'
not ok 5
-# Failed test at cmpok.c line 10.
+# Failed test at t/cmpok.c line 10.
# 23
# frob
# 55
ok 6
not ok 7
-# Failed test at cmpok.c line 12.
+# Failed test at t/cmpok.c line 12.
# 55
# +
# -55
ok 8
not ok 9
-# Failed test at cmpok.c line 14.
+# Failed test at t/cmpok.c line 14.
# 55
# %
# 5
# Looks like you failed 6 tests of 9 run.
END
eq_or_diff ~~`t/diesok$x 2>&1`, <<'END', "dies_ok";
1..5
ok 1 - sanity
ok 2 - can't divide by zero
ok 3 - this is a perfectly fine statement
ok 4 - abort kills the program
ok 5 - supress output
END
eq_or_diff ~~`t/is$x 2>&1`, <<'END', "is";
1..18
not ok 1 - this is that
# Failed test 'this is that'
-# at is.c line 6.
+# at t/is.c line 6.
# got: 'this'
# expected: 'that'
ok 2 - this is this
not ok 3
-# Failed test at is.c line 8.
+# Failed test at t/is.c line 8.
# got: 'this'
# expected: 'that'
ok 4
ok 5 - null is null
not ok 6 - null is this
# Failed test 'null is this'
-# at is.c line 11.
+# at t/is.c line 11.
# got: '(null)'
# expected: 'this'
not ok 7 - this is null
# Failed test 'this is null'
-# at is.c line 12.
+# at t/is.c line 12.
# got: 'this'
# expected: '(null)'
not ok 8
-# Failed test at is.c line 13.
+# Failed test at t/is.c line 13.
# got: 'foo
# foo
# foo'
# expected: 'bar
# bar
# bar'
ok 9
ok 10 - this isnt that
not ok 11 - this isnt this
# Failed test 'this isnt this'
-# at is.c line 16.
+# at t/is.c line 16.
# got: 'this'
# expected: anything else
ok 12
not ok 13
-# Failed test at is.c line 18.
+# Failed test at t/is.c line 18.
# got: 'this'
# expected: anything else
not ok 14 - null isnt null
# Failed test 'null isnt null'
-# at is.c line 19.
+# at t/is.c line 19.
# got: '(null)'
# expected: anything else
ok 15 - null isnt this
ok 16 - this isnt null
ok 17
not ok 18
-# Failed test at is.c line 23.
+# Failed test at t/is.c line 23.
# got: 'foo
# foo
# foo'
# expected: anything else
# Looks like you failed 9 tests of 18 run.
END
eq_or_diff ~~`t/like$x 2>&1`, <<'END', "like";
1..3
ok 1 - strange ~~ /range/
ok 2 - strange !~~ /anger/
ok 3 - matches the regex
END
eq_or_diff ~~`t/notediag$x 2>&1`, <<'END', "note and diag";
# note no new line
# note new line
# diag no new line
# diag new line
END
eq_or_diff ~~`t/simple$x 2>&1`, <<'END', "simple";
1..24
ok 1
ok 2
ok 3
not ok 4
-# Failed test at simple.c line 9.
+# Failed test at t/simple.c line 9.
ok 5 - foo
ok 6 - bar
ok 7 - baz
ok 8 - quux
ok 9 - thud
ok 10 - wombat
ok 11 - blurgle
ok 12 - frob
not ok 13 - frobnicate
# Failed test 'frobnicate'
-# at simple.c line 18.
+# at t/simple.c line 18.
ok 14 - eek
ok 15 - ook
ok 16 - frodo
ok 17 - bilbo
ok 18 - wubble
ok 19 - flarp
ok 20 - fnord
ok 21
not ok 22
-# Failed test at simple.c line 27.
+# Failed test at t/simple.c line 27.
ok 23 - good
not ok 24 - bad
# Failed test 'bad'
-# at simple.c line 29.
+# at t/simple.c line 29.
# Looks like you failed 4 tests of 24 run.
END
eq_or_diff ~~`t/skip$x 2>&1`, <<'END', "skip";
1..8
ok 1 - quux
ok 2 - thud
ok 3 - wombat
ok 4 # skip need to be on windows
ok 5 - quux
ok 6 - thud
ok 7 - wombat
ok 8 # skip
END
eq_or_diff ~~`t/synopsis$x 2>&1`, <<'END', "synopsis";
1..5
ok 1
not ok 2
-# Failed test at synopsis.c line 10.
+# Failed test at t/synopsis.c line 10.
# got: 'fnord'
# expected: 'eek'
ok 3 - foo <= 8732
ok 4 - is like
not ok 5 - foo is greater than ten
# Failed test 'foo is greater than ten'
-# at synopsis.c line 13.
+# at t/synopsis.c line 13.
# 3
# >=
# 10
# Looks like you failed 2 tests of 5 run.
END
eq_or_diff ~~`t/todo$x 2>&1`, <<'END', "todo";
1..6
not ok 1 - foo # TODO
# Failed (TODO) test 'foo'
-# at todo.c line 7.
+# at t/todo.c line 7.
ok 2 - bar # TODO
ok 3 - baz # TODO
not ok 4 - quux # TODO im not ready
# Failed (TODO) test 'quux'
-# at todo.c line 12.
+# at t/todo.c line 12.
ok 5 - thud # TODO im not ready
ok 6 - wombat # TODO im not ready
END
|
zorgnax/libtap
|
7d699d37ce940b2b62f187cad6fa5c5ab33744f6
|
Ignore vim swap files.
|
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..b8cd647
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.sw?
+
|
zorgnax/libtap
|
f9ab55a5ab098f0a8877d93b82d9c087cf48c4ff
|
Compile everything before running the tests.
|
diff --git a/Makefile b/Makefile
index 88ef897..55bed02 100644
--- a/Makefile
+++ b/Makefile
@@ -1,30 +1,30 @@
include config.mk
all: $(TAPLIB)
$(MAKE) -C t/ all
$(TAPLIB): tap$(_O)
tap$(_O): tap.c tap.h
clean:
$(RM) -rv $(TAPLIB) *.o *.obj *.lib *.pdb *.ilk _C
$(MAKE) -C t/ clean
ifdef GNU
install: $(TAPLIB) tap.h
sudo cp $(TAPLIB) /usr/lib
sudo cp tap.h /usr/include
uninstall:
sudo $(RM) /usr/lib/$(TAPLIB) /usr/include/tap.h
endif
dist:
$(RM) -v libtap.zip
zip -r libtap *
-check:
+check: all
prove
.PHONY: all clean install uninstall dist check
|
zorgnax/libtap
|
cfd204593be1b5f50a3a876fa294eb5b141f8bd6
|
Make the library compatible with gcc -ansi.
|
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..94a9ed0
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ <program> Copyright (C) <year> <name of author>
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/INSTALL b/INSTALL
new file mode 100644
index 0000000..6db3249
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,42 @@
+To install libtap on a unix-like system:
+
+ $ make
+ $ make check
+ $ make install
+
+To compile with gcc -ansi, run
+
+ $ make ANSI=1
+
+On Windows, the library can be created by first setting up
+the correct development environment variables. Usually this
+is done by running vcvars32.bat included in the visual studio
+distribution. You should also install gnu make which can be
+found at http://gnuwin32.sourceforge.net/packages/make.htm.
+And you should have perl to run the tests although this isnt
+absolutely necessary. Once this is done, you should be able to
+run the following:
+
+ > make GNU=
+ > make check
+
+Alternatively, you might want to use the visual studio project file
+included by Alexander Kahl (e-user).
+
+If you want to use it directly in another project, you can copy tap.c
+and tap.h there and it shouldn't have a problem compiling.
+
+ $ ls
+ tap.c tap.h test.c
+ $ cat test.c
+ #include "tap.h"
+ int main () {
+ plan(1);
+ ok(50 + 5, "foo %s", "bar");
+ done_testing();
+ }
+ $ gcc test.c tap.c
+ $ a.out
+ 1..1
+ ok 1 - foo bar
+
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..88ef897
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,30 @@
+include config.mk
+
+all: $(TAPLIB)
+ $(MAKE) -C t/ all
+
+$(TAPLIB): tap$(_O)
+tap$(_O): tap.c tap.h
+
+clean:
+ $(RM) -rv $(TAPLIB) *.o *.obj *.lib *.pdb *.ilk _C
+ $(MAKE) -C t/ clean
+
+ifdef GNU
+install: $(TAPLIB) tap.h
+ sudo cp $(TAPLIB) /usr/lib
+ sudo cp tap.h /usr/include
+
+uninstall:
+ sudo $(RM) /usr/lib/$(TAPLIB) /usr/include/tap.h
+endif
+
+dist:
+ $(RM) -v libtap.zip
+ zip -r libtap *
+
+check:
+ prove
+
+.PHONY: all clean install uninstall dist check
+
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..7384e86
--- /dev/null
+++ b/README.md
@@ -0,0 +1,248 @@
+NAME
+====
+
+libtap - Write tests in C
+
+SYNOPSIS
+========
+
+ #include <tap.h>
+
+ int foo () {return 3;}
+ char *bar () {return "fnord";}
+
+ int main () {
+ plan(5);
+ ok(foo() == 3);
+ is(bar(), "eek");
+ ok(foo() <= 8732, "foo <= %d", 8732);
+ like(bar(), "f(yes|no)r*[a-f]$", "is like");
+ cmp_ok(foo(), ">=", 10, "foo is greater than ten");
+ done_testing();
+ }
+
+results in:
+
+ 1..5
+ ok 1
+ not ok 2
+ # Failed test at synopsis.c line 9.
+ # got: 'fnord'
+ # expected: 'eek'
+ ok 3 - foo <= 8732
+ ok 4 - is like
+ not ok 5 - foo is greater than ten
+ # Failed test 'foo is greater than ten'
+ # at synopsis.c line 12.
+ # 3
+ # >=
+ # 10
+ # Looks like you failed 2 tests of 5 run.
+
+DESCRIPTION
+===========
+
+tap is an easy to read and easy to write way of creating tests for your
+software. This library creates functions that can be used to generate it for
+your C programs. It is mostly based on the Test::More Perl module.
+
+FUNCTIONS
+=========
+
+- plan(tests)
+- plan(NO_PLAN)
+- plan(SKIP_ALL);
+- plan(SKIP_ALL, fmt, ...)
+
+ Use this to start a series of tests. When you know how many tests there
+ will be, you can put a number as a number of tests you expect to run. If
+ you do not know how many tests there will be, you can use plan(NO_PLAN)
+ or not call this function. When you pass it a number of tests to run, a
+ message similar to the following will appear in the output:
+
+ 1..5
+
+ If you pass it SKIP_ALL, the whole test will be skipped.
+
+- ok(test)
+- ok(test, fmt, ...)
+
+ Specify a test. the test can be any statement returning a true or false
+ value. You may optionally pass a format string describing the test.
+
+ ok(r = reader_new("Of Mice and Men"), "create a new reader");
+ ok(reader_go_to_page(r, 55), "can turn the page");
+ ok(r->page == 55, "page turned to the right one");
+
+ Should print out:
+
+ ok 1 - create a new reader
+ ok 2 - can turn the page
+ ok 3 - page turned to the right one
+
+ On failure, a diagnostic message will be printed out.
+
+ not ok 3 - page turned to the right one
+ # Failed test 'page turned to the right one'
+ # at reader.c line 13.
+
+- is(got, expected)
+- is(got, expected, fmt, ...)
+- isnt(got, expected)
+- isnt(got, expected, fmt, ...)
+
+ Tests that the string you got is what you expected. with isnt, it is the
+ reverse.
+
+ is("this", "that", "this is that");
+
+ prints:
+
+ not ok 1 - this is that
+ # Failed test 'this is that'
+ # at is.c line 6.
+ # got: 'this'
+ # expected: 'that'
+
+- cmp_ok(a, op, b)
+- cmp_ok(a, op, b, fmt, ...)
+
+ Compares two ints with any binary operator that doesn't require an lvalue.
+ This is nice to use since it provides a better error message than an
+ equivalent ok.
+
+ cmp_ok(420, ">", 666);
+
+ prints:
+
+ not ok 1
+ # Failed test at cmpok.c line 5.
+ # 420
+ # >
+ # 666
+
+- like(got, expected)
+- like(got, expected, fmt, ...)
+- unlike(got, expected)
+- unlike(got, expected, fmt, ...)
+
+ Tests that the string you got matches the expected extended POSIX regex.
+ unlike is the reverse. These macros are the equivalent of a skip on
+ Windows.
+
+ like("stranger", "^s.(r).*\\1$", "matches the regex");
+
+ prints:
+
+ ok 1 - matches the regex
+
+- pass()
+- pass(fmt, ...)
+- fail()
+- fail(fmt, ...)
+
+ Speciy that a test succeeded or failed. Use these when the statement is
+ longer than you can fit into the argument given to an ok() test.
+
+- dies_ok(code)
+- dies_ok(code, fmt, ...)
+- lives_ok(code)
+- lives_ok(code, fmt, ...)
+
+ Tests whether the given code causes your program to exit. The code gets
+ passed to a macro that will test it in a forked process. If the code
+ succeeds it will be executed in the parent process. You can test things
+ like passing a function a null pointer and make sure it doesnt
+ dereference it and crash.
+
+ dies_ok({abort();}, "abort does close your program");
+ dies_ok({int x = 0/0;}, "divide by zero crash");
+ lives_ok({pow(3.0, 5.0);}, "nothing wrong with taking 3**5");
+
+ On Windows, these macros are the equivalent of a skip.
+
+- done_testing()
+
+ Summarizes the tests that occurred and exits the main function. If
+ there was no plan, it will print out the number of tests as.
+
+ 1..5
+
+ It will also print a diagnostic message about how many
+ failures there were.
+
+ # Looks like you failed 2 tests of 3 run.
+
+ If all planned tests were successful, it will return 0. If any test fails,
+ it will return the number of failed tests (including ones that were
+ missing). If they all passed, but there were missing tests, it will return
+ 255.
+
+- note(fmt, ...)
+- diag(fmt, ...)
+
+ print out a message to the tap output. note prints to stdout and diag
+ prints to stderr. Each line is preceeded by a "# " so that you know its a
+ diagnostic message.
+
+ note("This is\na note\nto describe\nsomething.");
+
+ prints:
+
+ # This is
+ # a note
+ # to describe
+ # something
+
+ ok() and these functions return ints so you can use them like:
+
+ ok(1) && note("yo!");
+ ok(0) || diag("I have no idea what just happened");
+
+- skip(test, n)
+- skip(test, n, fmt, ...)
+- endskip
+
+ Skip a series of n tests if test is true. You may give a reason why you are
+ skipping them or not. The (possibly) skipped tests must occur between the
+ skip and endskip macros.
+
+ skip(TRUE, 2);
+ ok(1);
+ ok(0);
+ endskip;
+
+ prints:
+
+ ok 1 # skip
+ ok 2 # skip
+
+- todo()
+- todo(fmt, ...)
+- endtodo
+
+ Specifies a series of tests that you expect to fail because they are not
+ yet implemented.
+
+ todo()
+ ok(0);
+ endtodo;
+
+ prints:
+
+ not ok 1 # TODO
+ # Failed (TODO) test at todo.c line 7
+
+- BAIL_OUT()
+- BAIL_OUT(fmt, ...)
+
+ Immediately stops all testing.
+
+ BAIL_OUT("Can't go no further");
+
+ prints
+
+ Bail out! Can't go no further
+
+ and exits with 255.
+
diff --git a/config.mk b/config.mk
new file mode 100644
index 0000000..6987901
--- /dev/null
+++ b/config.mk
@@ -0,0 +1,47 @@
+GNU = 1
+MAKE = make
+CFLAGS = $(DEBUG)
+ifdef GNU
+ ALLCFLAGS = -Wall $(CFLAGS)
+ ifdef ANSI
+ # -D_BSD_SOURCE for MAP_ANONYMOUS
+ ALLCFLAGS += -ansi -D_BSD_SOURCE
+ LDLIBS += -lbsd-compat
+ endif
+ DEBUG = -g
+ CCFLAGS = -c
+ CCOUT = -o
+ CLOUT = -o
+ PIC = -fPIC
+ _O = .o
+ _X =
+ _A = .a
+ _SO = .so
+ TAPLIB = libtap.a
+ STATICLIB.o = $(AR) rcs $@ $(filter %$(_O), $^)
+ DYNAMICLIB.o = $(CC) -shared -o $@ $(filter %$(_O), $^)
+else
+ CC = cl /nologo
+ ALLCFLAGS = /Wall /wd4255 /wd4996 /wd4127 /wd4820 \
+ /wd4100 /wd4619 /wd4514 /wd4668 $(CFLAGS)
+ DEBUG = /Zi
+ CCFLAGS = /c
+ CCOUT = /Fo
+ CLOUT = /Fe
+ PIC =
+ _O = .obj
+ _X = .exe
+ _A = .lib
+ _SO = .dll
+ TAPLIB = tap.lib
+ STATICLIB.o = lib /nologo /out:$@ $(filter %$(_O), $^)
+ DYNAMICLIB.o = lib /nologo /out:$@ $(filter %$(_O), $^)
+endif
+COMPILE.c = $(CC) $(CCFLAGS) $(CPPFLAGS) $(ALLCFLAGS) $(CCOUT)$@ $(filter %.c, $^)
+LINK.o = $(CC) $(ALLCFLAGS) $(CLOUT)$@ $(filter %$(_O) %.a %.so %.lib %.dll, $^) $(LDFLAGS) $(LDLIBS)
+
+%$(_X):; $(LINK.o)
+%$(_A):; $(STATICLIB.o)
+%$(_SO):; $(DYNAMICLIB.o)
+%$(_O):; $(COMPILE.c)
+
diff --git a/libtap.vcxproj b/libtap.vcxproj
new file mode 100644
index 0000000..a790da4
--- /dev/null
+++ b/libtap.vcxproj
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{4DFC985A-83D7-4E61-85FE-C6EA6E43E3AA}</ProjectGuid>
+ <Keyword>Win32Proj</Keyword>
+ <RootNamespace>libtap</RootNamespace>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup />
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClInclude Include="tap.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="tap.c" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
diff --git a/t/Makefile b/t/Makefile
new file mode 100644
index 0000000..d46fc78
--- /dev/null
+++ b/t/Makefile
@@ -0,0 +1,21 @@
+include ../config.mk
+
+CFLAGS += -I..
+
+X := simple diesok notediag skip todo is like cmpok synopsis
+X := $(patsubst %, %$(_X), $(X))
+O = $(patsubst %$(_X), %$(_O), $(X))
+
+all: $(X) ../$(TAPLIB)
+
+../$(TAPLIB):
+ $(error error $(TAPLIB) needs to be built)
+
+$(O): %$(_O): %.c ../tap.h
+$(X): %$(_X): %$(_O) ../$(TAPLIB)
+
+clean:
+ $(RM) -rv $(X) *.o *.obj *.lib *.pdb *.ilk _C
+
+.PHONY: all clean
+
diff --git a/t/cmpok.c b/t/cmpok.c
new file mode 100644
index 0000000..72e8d16
--- /dev/null
+++ b/t/cmpok.c
@@ -0,0 +1,17 @@
+#include "tap.h"
+
+int main () {
+ setvbuf(stdout, NULL, _IONBF, 0);
+ plan(9);
+ cmp_ok(420, ">", 666);
+ cmp_ok(23, "==", 55, "the number 23 is definitely 55");
+ cmp_ok(23, "==", 55);
+ cmp_ok(23, "!=", 55);
+ cmp_ok(23, "frob", 55);
+ cmp_ok(23, "<=", 55);
+ cmp_ok(55, "+", -55);
+ cmp_ok(23, "%", 5);
+ cmp_ok(55, "%", 5);
+ done_testing();
+}
+
diff --git a/t/diesok.c b/t/diesok.c
new file mode 100644
index 0000000..d101014
--- /dev/null
+++ b/t/diesok.c
@@ -0,0 +1,15 @@
+#include "tap.h"
+
+int main () {
+ setvbuf(stdout, NULL, _IONBF, 0);
+ plan(5);
+ ok(1, "sanity");
+ dies_ok({int x = 0; x = x/x;}, "can't divide by zero");
+ lives_ok({int x; x = 3/7;}, "this is a perfectly fine statement");
+ dies_ok({abort();}, "abort kills the program");
+ dies_ok(
+ {printf("stdout\n"); fprintf(stderr, "stderr\n"); abort();},
+ "supress output");
+ done_testing();
+}
+
diff --git a/t/is.c b/t/is.c
new file mode 100644
index 0000000..ecc6d75
--- /dev/null
+++ b/t/is.c
@@ -0,0 +1,25 @@
+#include "tap.h"
+
+int main () {
+ setvbuf(stdout, NULL, _IONBF, 0);
+ plan(18);
+ is("this", "that", "this is that"); /* bang */
+ is("this", "this", "this is this");
+ is("this", "that"); /* bang */
+ is("this", "this");
+ is(NULL, NULL, "null is null");
+ is(NULL, "this", "null is this"); /* bang */
+ is("this", NULL, "this is null"); /* bang */
+ is("foo\nfoo\nfoo", "bar\nbar\nbar"); /* bang */
+ is("foo\nfoo\nfoo", "foo\nfoo\nfoo");
+ isnt("this", "that", "this isnt that");
+ isnt("this", "this", "this isnt this"); /* bang */
+ isnt("this", "that");
+ isnt("this", "this"); /* bang */
+ isnt(NULL, NULL, "null isnt null"); /* bang */
+ isnt(NULL, "this", "null isnt this");
+ isnt("this", NULL, "this isnt null");
+ isnt("foo\nfoo\nfoo", "bar\nbar\nbar");
+ isnt("foo\nfoo\nfoo", "foo\nfoo\nfoo"); /* bang */
+ done_testing();
+}
diff --git a/t/like.c b/t/like.c
new file mode 100644
index 0000000..b311c69
--- /dev/null
+++ b/t/like.c
@@ -0,0 +1,11 @@
+#include "tap.h"
+
+int main () {
+ setvbuf(stdout, NULL, _IONBF, 0);
+ plan(3);
+ like("strange", "range", "strange ~~ /range/");
+ unlike("strange", "anger", "strange !~~ /anger/");
+ like("stranger", "^s.(r).*\\1$", "matches the regex");
+ done_testing();
+}
+
diff --git a/t/notediag.c b/t/notediag.c
new file mode 100644
index 0000000..d1e50f9
--- /dev/null
+++ b/t/notediag.c
@@ -0,0 +1,15 @@
+#include "tap.h"
+
+int main () {
+ setvbuf(stdout, NULL, _IONBF, 0);
+ note("note no new line");
+ note("note new line\n");
+ note("");
+ note(NULL);
+ diag("diag no new line");
+ diag("diag new line\n");
+ diag("");
+ diag(NULL);
+ return 1;
+}
+
diff --git a/t/simple.c b/t/simple.c
new file mode 100644
index 0000000..7b89254
--- /dev/null
+++ b/t/simple.c
@@ -0,0 +1,32 @@
+#include "tap.h"
+
+int main () {
+ setvbuf(stdout, NULL, _IONBF, 0);
+ plan(24);
+ ok(1);
+ ok(1);
+ ok(1);
+ ok(0);
+ ok(1, "foo");
+ ok(1, "bar");
+ ok(1, "baz");
+ ok(1, "quux");
+ ok(1, "thud");
+ ok(1, "wombat");
+ ok(1, "blurgle");
+ ok(1, "frob");
+ ok(0, "frobnicate");
+ ok(1, "eek");
+ ok(1, "ook");
+ ok(1, "frodo");
+ ok(1, "bilbo");
+ ok(1, "wubble");
+ ok(1, "flarp");
+ ok(1, "fnord");
+ pass();
+ fail();
+ pass("good");
+ fail("bad");
+ done_testing();
+}
+
diff --git a/t/skip.c b/t/skip.c
new file mode 100644
index 0000000..149ef53
--- /dev/null
+++ b/t/skip.c
@@ -0,0 +1,24 @@
+#include "tap.h"
+
+int main () {
+ setvbuf(stdout, NULL, _IONBF, 0);
+ plan(8);
+ skip(0, 3, "%s cannot fork", "windows");
+ ok(1, "quux");
+ ok(1, "thud");
+ ok(1, "wombat");
+ endskip;
+ skip(1, 1, "need to be on windows");
+ ok(0, "blurgle");
+ endskip;
+ skip(0, 3);
+ ok(1, "quux");
+ ok(1, "thud");
+ ok(1, "wombat");
+ endskip;
+ skip(1, 1);
+ ok(0, "blurgle");
+ endskip;
+ done_testing();
+}
+
diff --git a/t/synopsis.c b/t/synopsis.c
new file mode 100644
index 0000000..c7b3041
--- /dev/null
+++ b/t/synopsis.c
@@ -0,0 +1,16 @@
+#include "tap.h"
+
+int foo () {return 3;}
+char *bar () {return "fnord";}
+
+int main () {
+ setvbuf(stdout, NULL, _IONBF, 0);
+ plan(5);
+ ok(foo() == 3);
+ is(bar(), "eek");
+ ok(foo() <= 8732, "foo <= %d", 8732);
+ like(bar(), "f(yes|no)r*[a-f]$", "is like");
+ cmp_ok(foo(), ">=", 10, "foo is greater than ten");
+ done_testing();
+}
+
diff --git a/t/tap.t b/t/tap.t
new file mode 100755
index 0000000..d6ef667
--- /dev/null
+++ b/t/tap.t
@@ -0,0 +1,211 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Test::More tests => 9;
+use Test::Differences;
+
+my $x = $^O eq 'MSWin32' ? ".exe" : "";
+
+eq_or_diff ~~`t/cmpok$x 2>&1`, <<'END', "cmp_ok";
+1..9
+not ok 1
+# Failed test at cmpok.c line 6.
+# 420
+# >
+# 666
+not ok 2 - the number 23 is definitely 55
+# Failed test 'the number 23 is definitely 55'
+# at cmpok.c line 7.
+# 23
+# ==
+# 55
+not ok 3
+# Failed test at cmpok.c line 8.
+# 23
+# ==
+# 55
+ok 4
+# unrecognized operator 'frob'
+not ok 5
+# Failed test at cmpok.c line 10.
+# 23
+# frob
+# 55
+ok 6
+not ok 7
+# Failed test at cmpok.c line 12.
+# 55
+# +
+# -55
+ok 8
+not ok 9
+# Failed test at cmpok.c line 14.
+# 55
+# %
+# 5
+# Looks like you failed 6 tests of 9 run.
+END
+
+eq_or_diff ~~`t/diesok$x 2>&1`, <<'END', "dies_ok";
+1..5
+ok 1 - sanity
+ok 2 - can't divide by zero
+ok 3 - this is a perfectly fine statement
+ok 4 - abort kills the program
+ok 5 - supress output
+END
+
+eq_or_diff ~~`t/is$x 2>&1`, <<'END', "is";
+1..18
+not ok 1 - this is that
+# Failed test 'this is that'
+# at is.c line 6.
+# got: 'this'
+# expected: 'that'
+ok 2 - this is this
+not ok 3
+# Failed test at is.c line 8.
+# got: 'this'
+# expected: 'that'
+ok 4
+ok 5 - null is null
+not ok 6 - null is this
+# Failed test 'null is this'
+# at is.c line 11.
+# got: '(null)'
+# expected: 'this'
+not ok 7 - this is null
+# Failed test 'this is null'
+# at is.c line 12.
+# got: 'this'
+# expected: '(null)'
+not ok 8
+# Failed test at is.c line 13.
+# got: 'foo
+# foo
+# foo'
+# expected: 'bar
+# bar
+# bar'
+ok 9
+ok 10 - this isnt that
+not ok 11 - this isnt this
+# Failed test 'this isnt this'
+# at is.c line 16.
+# got: 'this'
+# expected: anything else
+ok 12
+not ok 13
+# Failed test at is.c line 18.
+# got: 'this'
+# expected: anything else
+not ok 14 - null isnt null
+# Failed test 'null isnt null'
+# at is.c line 19.
+# got: '(null)'
+# expected: anything else
+ok 15 - null isnt this
+ok 16 - this isnt null
+ok 17
+not ok 18
+# Failed test at is.c line 23.
+# got: 'foo
+# foo
+# foo'
+# expected: anything else
+# Looks like you failed 9 tests of 18 run.
+END
+
+eq_or_diff ~~`t/like$x 2>&1`, <<'END', "like";
+1..3
+ok 1 - strange ~~ /range/
+ok 2 - strange !~~ /anger/
+ok 3 - matches the regex
+END
+
+eq_or_diff ~~`t/notediag$x 2>&1`, <<'END', "note and diag";
+# note no new line
+# note new line
+# diag no new line
+# diag new line
+END
+
+eq_or_diff ~~`t/simple$x 2>&1`, <<'END', "simple";
+1..24
+ok 1
+ok 2
+ok 3
+not ok 4
+# Failed test at simple.c line 9.
+ok 5 - foo
+ok 6 - bar
+ok 7 - baz
+ok 8 - quux
+ok 9 - thud
+ok 10 - wombat
+ok 11 - blurgle
+ok 12 - frob
+not ok 13 - frobnicate
+# Failed test 'frobnicate'
+# at simple.c line 18.
+ok 14 - eek
+ok 15 - ook
+ok 16 - frodo
+ok 17 - bilbo
+ok 18 - wubble
+ok 19 - flarp
+ok 20 - fnord
+ok 21
+not ok 22
+# Failed test at simple.c line 27.
+ok 23 - good
+not ok 24 - bad
+# Failed test 'bad'
+# at simple.c line 29.
+# Looks like you failed 4 tests of 24 run.
+END
+
+eq_or_diff ~~`t/skip$x 2>&1`, <<'END', "skip";
+1..8
+ok 1 - quux
+ok 2 - thud
+ok 3 - wombat
+ok 4 # skip need to be on windows
+ok 5 - quux
+ok 6 - thud
+ok 7 - wombat
+ok 8 # skip
+END
+
+eq_or_diff ~~`t/synopsis$x 2>&1`, <<'END', "synopsis";
+1..5
+ok 1
+not ok 2
+# Failed test at synopsis.c line 10.
+# got: 'fnord'
+# expected: 'eek'
+ok 3 - foo <= 8732
+ok 4 - is like
+not ok 5 - foo is greater than ten
+# Failed test 'foo is greater than ten'
+# at synopsis.c line 13.
+# 3
+# >=
+# 10
+# Looks like you failed 2 tests of 5 run.
+END
+
+eq_or_diff ~~`t/todo$x 2>&1`, <<'END', "todo";
+1..6
+not ok 1 - foo # TODO
+# Failed (TODO) test 'foo'
+# at todo.c line 7.
+ok 2 - bar # TODO
+ok 3 - baz # TODO
+not ok 4 - quux # TODO im not ready
+# Failed (TODO) test 'quux'
+# at todo.c line 12.
+ok 5 - thud # TODO im not ready
+ok 6 - wombat # TODO im not ready
+END
+
diff --git a/t/todo.c b/t/todo.c
new file mode 100644
index 0000000..af15f11
--- /dev/null
+++ b/t/todo.c
@@ -0,0 +1,18 @@
+#include "tap.h"
+
+int main () {
+ setvbuf(stdout, NULL, _IONBF, 0);
+ plan(6);
+ todo();
+ ok(0, "foo");
+ ok(1, "bar");
+ ok(1, "baz");
+ endtodo;
+ todo("im not ready");
+ ok(0, "quux");
+ ok(1, "thud");
+ ok(1, "wombat");
+ endtodo;
+ done_testing();
+}
+
diff --git a/tap.c b/tap.c
new file mode 100644
index 0000000..7dcd0e9
--- /dev/null
+++ b/tap.c
@@ -0,0 +1,324 @@
+/*
+libtap - Write tests in C
+Copyright (C) 2011 Jake Gelbman <[email protected]>
+This file is licensed under the GPL v3
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include "tap.h"
+
+static int expected_tests = NO_PLAN;
+static int failed_tests;
+static int current_test;
+static char *todo_mesg;
+
+static char *
+vstrdupf (const char *fmt, va_list args) {
+ char *str;
+ int size;
+ va_list args2;
+ va_copy(args2, args);
+ if (!fmt)
+ fmt = "";
+ size = vsnprintf(NULL, 0, fmt, args2) + 2;
+ str = malloc(size);
+ vsprintf(str, fmt, args);
+ va_end(args2);
+ return str;
+}
+
+void
+cplan (int tests, const char *fmt, ...) {
+ expected_tests = tests;
+ if (tests == SKIP_ALL) {
+ char *why;
+ va_list args;
+ va_start(args, fmt);
+ why = vstrdupf(fmt, args);
+ va_end(args);
+ printf("1..0 ");
+ note("SKIP %s\n", why);
+ exit(0);
+ }
+ if (tests != NO_PLAN) {
+ printf("1..%d\n", tests);
+ }
+}
+
+int
+vok_at_loc (const char *file, int line, int test, const char *fmt,
+ va_list args)
+{
+ char *name = vstrdupf(fmt, args);
+ printf("%sok %d", test ? "" : "not ", ++current_test);
+ if (*name)
+ printf(" - %s", name);
+ if (todo_mesg) {
+ printf(" # TODO");
+ if (*todo_mesg)
+ printf(" %s", todo_mesg);
+ }
+ printf("\n");
+ if (!test) {
+ if (*name)
+ diag(" Failed%s test '%s'\n at %s line %d.",
+ todo_mesg ? " (TODO)" : "", name, file, line);
+ else
+ diag(" Failed%s test at %s line %d.",
+ todo_mesg ? " (TODO)" : "", file, line);
+ if (!todo_mesg)
+ failed_tests++;
+ }
+ free(name);
+ return test;
+}
+
+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;
+}
+
+static int
+mystrcmp (const char *a, const char *b) {
+ return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
+}
+
+#define eq(a, b) (!mystrcmp(a, b))
+#define ne(a, b) (mystrcmp(a, b))
+
+int
+is_at_loc (const char *file, int line, const char *got, const char *expected,
+ const char *fmt, ...)
+{
+ int test = eq(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: '%s'", expected);
+ }
+ return test;
+}
+
+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;
+}
+
+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;
+}
+
+static void
+vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
+ char *mesg, *line;
+ int i;
+ if (!fmt)
+ return;
+ mesg = vstrdupf(fmt, args);
+ line = mesg;
+ for (i = 0; *line; i++) {
+ char c = mesg[i];
+ if (!c || c == '\n') {
+ mesg[i] = '\0';
+ fprintf(fh, "# %s\n", line);
+ if (!c)
+ break;
+ mesg[i] = c;
+ line = mesg + i + 1;
+ }
+ }
+ free(mesg);
+ return;
+}
+
+int
+diag (const char *fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ vdiag_to_fh(stderr, fmt, args);
+ va_end(args);
+ return 0;
+}
+
+int
+note (const char *fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ vdiag_to_fh(stdout, fmt, args);
+ va_end(args);
+ return 0;
+}
+
+int
+exit_status () {
+ int retval = 0;
+ if (expected_tests == NO_PLAN) {
+ printf("1..%d\n", current_test);
+ }
+ else if (current_test != expected_tests) {
+ diag("Looks like you planned %d test%s but ran %d.",
+ expected_tests, expected_tests > 1 ? "s" : "", current_test);
+ retval = 255;
+ }
+ if (failed_tests) {
+ diag("Looks like you failed %d test%s of %d run.",
+ failed_tests, failed_tests > 1 ? "s" : "", current_test);
+ if (expected_tests == NO_PLAN)
+ retval = failed_tests;
+ else
+ retval = expected_tests - current_test + failed_tests;
+ }
+ return retval;
+}
+
+int
+bail_out (int ignore, const char *fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ printf("Bail out! ");
+ vprintf(fmt, args);
+ printf("\n");
+ va_end(args);
+ exit(255);
+ return 0;
+}
+
+void
+skippy (int n, const char *fmt, ...) {
+ char *why;
+ va_list args;
+ va_start(args, fmt);
+ why = vstrdupf(fmt, args);
+ va_end(args);
+ while (n --> 0) {
+ printf("ok %d ", ++current_test);
+ note("skip %s\n", why);
+ }
+ free(why);
+}
+
+void
+ctodo (int ignore, const char *fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ todo_mesg = vstrdupf(fmt, args);
+ va_end(args);
+}
+
+void
+cendtodo () {
+ free(todo_mesg);
+ todo_mesg = NULL;
+}
+
+#ifndef _WIN32
+#include <sys/mman.h>
+#include <regex.h>
+
+#ifdef __APPLE__
+#define MAP_ANONYMOUS MAP_ANON
+#endif
+
+/* Create a shared memory int to keep track of whether a piece of code executed
+dies. to be used in the dies_ok and lives_ok macros */
+int
+tap_test_died (int status) {
+ static int *test_died = NULL;
+ int prev;
+ if (!test_died) {
+ test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+ *test_died = 0;
+ }
+ prev = *test_died;
+ *test_died = status;
+ return prev;
+}
+
+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;
+ 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_list args;
+ 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;
+}
+#endif
+
diff --git a/tap.h b/tap.h
new file mode 100644
index 0000000..09935e8
--- /dev/null
+++ b/tap.h
@@ -0,0 +1,112 @@
+/*
+libtap - Write tests in C
+Copyright (C) 2011 Jake Gelbman <[email protected]>
+This file is licensed under the GPL v3
+*/
+
+#ifndef __TAP_H__
+#define __TAP_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef va_copy
+#ifdef __va_copy
+#define va_copy __va_copy
+#else
+#define va_copy(d, s) ((d) = (s))
+#endif
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+int vok_at_loc (const char *file, int line, int test, const char *fmt,
+ va_list args);
+int ok_at_loc (const char *file, int line, int test, const char *fmt,
+ ...);
+int is_at_loc (const char *file, int line, const char *got,
+ const char *expected, const char *fmt, ...);
+int isnt_at_loc (const char *file, int line, const char *got,
+ const char *expected, const char *fmt, ...);
+int cmp_ok_at_loc (const char *file, int line, int a, const char *op,
+ int b, const char *fmt, ...);
+int bail_out (int ignore, const char *fmt, ...);
+void cplan (int tests, const char *fmt, ...);
+int diag (const char *fmt, ...);
+int note (const char *fmt, ...);
+int exit_status (void);
+void skippy (int n, const char *fmt, ...);
+void ctodo (int ignore, const char *fmt, ...);
+void cendtodo (void);
+
+#define NO_PLAN -1
+#define SKIP_ALL -2
+#define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
+#define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
+#define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
+#define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
+#define plan(...) cplan(__VA_ARGS__, NULL)
+#define done_testing() return exit_status()
+#define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
+#define pass(...) ok(1, "" __VA_ARGS__)
+#define fail(...) ok(0, "" __VA_ARGS__)
+
+#define skip(test, ...) do {if (test) {skippy(__VA_ARGS__, NULL); break;}
+#define endskip } while (0)
+
+#define todo(...) ctodo(0, "" __VA_ARGS__, NULL)
+#define endtodo cendtodo()
+
+#define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
+#define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
+
+#ifdef _WIN32
+#define like(...) skippy(1, "like is not implemented on MSWin32")
+#define unlike like
+#define dies_ok_common(...) \
+ skippy(1, "Death detection is not supported on MSWin32")
+#else
+#define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
+#define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
+int like_at_loc (int for_match, const char *file, int line,
+ const char *got, const char *expected,
+ const char *fmt, ...);
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+int tap_test_died (int status);
+#define dies_ok_common(for_death, code, ...) \
+ do { \
+ tap_test_died(1); \
+ int cpid = fork(); \
+ switch (cpid) { \
+ case -1: \
+ perror("fork error"); \
+ exit(1); \
+ case 0: \
+ close(1); \
+ close(2); \
+ code \
+ tap_test_died(0); \
+ exit(0); \
+ } \
+ if (waitpid(cpid, NULL, 0) < 0) { \
+ perror("waitpid error"); \
+ exit(1); \
+ } \
+ int it_died = tap_test_died(0); \
+ if (!it_died) \
+ {code} \
+ ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \
+ } while (0)
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
|
scrooloose/snipmate-snippets
|
15cb6bf4fad5b11f83d2ddb7186aadc0604329c1
|
added a bunch of css snippets and one eruby snippet
|
diff --git a/css/background/all.snippet b/css/background/all.snippet
new file mode 100644
index 0000000..5e94d2c
--- /dev/null
+++ b/css/background/all.snippet
@@ -0,0 +1 @@
+background:${6: #${1:DDD}} url($2) ${3:repeat/repeat-x/repeat-y/no-repeat} ${4:scroll/fixed} ${5:top left/top center/top right/center left/center center/center right/bottom left/bottom center/bottom right/x-% y-%/x-pos y-pos};$0
diff --git a/css/background/attachment.snippet b/css/background/attachment.snippet
new file mode 100644
index 0000000..cb0c8f8
--- /dev/null
+++ b/css/background/attachment.snippet
@@ -0,0 +1 @@
+background-attachment: ${1:scroll/fixed};$0
diff --git a/css/background/color.snippet b/css/background/color.snippet
new file mode 100644
index 0000000..ebf4bc7
--- /dev/null
+++ b/css/background/color.snippet
@@ -0,0 +1 @@
+background-color: #${1:DDD};$0
diff --git a/css/background/color_name.snippet b/css/background/color_name.snippet
new file mode 100644
index 0000000..c736f99
--- /dev/null
+++ b/css/background/color_name.snippet
@@ -0,0 +1 @@
+background-color: ${1:red};$0
diff --git a/css/background/color_rgb.snippet b/css/background/color_rgb.snippet
new file mode 100644
index 0000000..a818f86
--- /dev/null
+++ b/css/background/color_rgb.snippet
@@ -0,0 +1 @@
+background-color: rgb(${1:255},${2:255},${3:255});$0
diff --git a/css/background/color_transparent.snippet b/css/background/color_transparent.snippet
new file mode 100644
index 0000000..d4ecdd1
--- /dev/null
+++ b/css/background/color_transparent.snippet
@@ -0,0 +1 @@
+background-color: transparent;$0
diff --git a/css/background/image_none.snippet b/css/background/image_none.snippet
new file mode 100644
index 0000000..1112ab7
--- /dev/null
+++ b/css/background/image_none.snippet
@@ -0,0 +1 @@
+background-image: none;$0
diff --git a/css/background/image_url.snippet b/css/background/image_url.snippet
new file mode 100644
index 0000000..83bee3e
--- /dev/null
+++ b/css/background/image_url.snippet
@@ -0,0 +1 @@
+background-image: url($1);$0
diff --git a/css/background/position.snippet b/css/background/position.snippet
new file mode 100644
index 0000000..ccdcb69
--- /dev/null
+++ b/css/background/position.snippet
@@ -0,0 +1 @@
+background-position: ${1:top left/top center/top right/center left/center center/center right/bottom left/bottom center/bottom right/x-% y-%/x-pos y-pos};$0
diff --git a/css/background/repeat.snippet b/css/background/repeat.snippet
new file mode 100644
index 0000000..5c6ce16
--- /dev/null
+++ b/css/background/repeat.snippet
@@ -0,0 +1 @@
+background-repeat: ${1:repeat/repeat-x/repeat-y/no-repeat};$0
diff --git a/css/border/basic.snippet b/css/border/basic.snippet
new file mode 100644
index 0000000..bb6adc0
--- /dev/null
+++ b/css/border/basic.snippet
@@ -0,0 +1 @@
+border: ${1:1px} ${2:solid} #${3:999};$0
diff --git a/css/border/color.snippet b/css/border/color.snippet
new file mode 100644
index 0000000..b3e7721
--- /dev/null
+++ b/css/border/color.snippet
@@ -0,0 +1 @@
+border-color: ${1:999};$0
diff --git a/css/border/style.snippet b/css/border/style.snippet
new file mode 100644
index 0000000..0dac5f1
--- /dev/null
+++ b/css/border/style.snippet
@@ -0,0 +1 @@
+border-style: ${1:none/hidden/dotted/dashed/solid/double/groove/ridge/inset/outset};$0
diff --git a/css/border/width.snippet b/css/border/width.snippet
new file mode 100644
index 0000000..7c5fba0
--- /dev/null
+++ b/css/border/width.snippet
@@ -0,0 +1 @@
+border-width: ${1:1px};$0
diff --git a/css/borderb/basic.snippet b/css/borderb/basic.snippet
new file mode 100644
index 0000000..e0b7c21
--- /dev/null
+++ b/css/borderb/basic.snippet
@@ -0,0 +1 @@
+border-bottom: ${1:1}px ${2:solid} #${3:999};$0
diff --git a/css/borderb/color.snippet b/css/borderb/color.snippet
new file mode 100644
index 0000000..d980e49
--- /dev/null
+++ b/css/borderb/color.snippet
@@ -0,0 +1 @@
+border-bottom-color: #${1:999};$0
diff --git a/css/borderb/style.snippet b/css/borderb/style.snippet
new file mode 100644
index 0000000..24617c6
--- /dev/null
+++ b/css/borderb/style.snippet
@@ -0,0 +1 @@
+border-bottom-style: ${1:none/hidden/dotted/dashed/solid/double/groove/ridge/inset/outset};$0
diff --git a/css/borderb/width.snippet b/css/borderb/width.snippet
new file mode 100644
index 0000000..2689cd5
--- /dev/null
+++ b/css/borderb/width.snippet
@@ -0,0 +1 @@
+border-bottom-width: ${1:1}px ${2:solid} #${3:999};$0
diff --git a/css/borderl/basic.snippet b/css/borderl/basic.snippet
new file mode 100644
index 0000000..dd4dd2a
--- /dev/null
+++ b/css/borderl/basic.snippet
@@ -0,0 +1 @@
+border-left: ${1:1}px ${2:solid} #${3:999};$0
diff --git a/css/borderl/color.snippet b/css/borderl/color.snippet
new file mode 100644
index 0000000..68afecb
--- /dev/null
+++ b/css/borderl/color.snippet
@@ -0,0 +1 @@
+border-left-color: #${1:999};$0
diff --git a/css/borderl/style.snippet b/css/borderl/style.snippet
new file mode 100644
index 0000000..074cbfa
--- /dev/null
+++ b/css/borderl/style.snippet
@@ -0,0 +1 @@
+border-left-style: ${1:none/hidden/dotted/dashed/solid/double/groove/ridge/inset/outset};$0
diff --git a/css/borderl/width.snippet b/css/borderl/width.snippet
new file mode 100644
index 0000000..1e2acef
--- /dev/null
+++ b/css/borderl/width.snippet
@@ -0,0 +1 @@
+border-left-width: ${1:1}px ${2:solid} #${3:999};$0
diff --git a/css/borderr/basic.snippet b/css/borderr/basic.snippet
new file mode 100644
index 0000000..a0a3e4b
--- /dev/null
+++ b/css/borderr/basic.snippet
@@ -0,0 +1 @@
+border-right: ${1:1}px ${2:solid} #${3:999};$0
diff --git a/css/borderr/color.snippet b/css/borderr/color.snippet
new file mode 100644
index 0000000..320accc
--- /dev/null
+++ b/css/borderr/color.snippet
@@ -0,0 +1 @@
+border-right-color: #${1:999};$0
diff --git a/css/borderr/style.snippet b/css/borderr/style.snippet
new file mode 100644
index 0000000..8b03f66
--- /dev/null
+++ b/css/borderr/style.snippet
@@ -0,0 +1 @@
+border-right-style: ${1:none/hidden/dotted/dashed/solid/double/groove/ridge/inset/outset};$0
diff --git a/css/borderr/width.snippet b/css/borderr/width.snippet
new file mode 100644
index 0000000..9df0426
--- /dev/null
+++ b/css/borderr/width.snippet
@@ -0,0 +1 @@
+border-right-width: ${1:1}px ${2:solid} #${3:999};$0
diff --git a/css/bordert/basic.snippet b/css/bordert/basic.snippet
new file mode 100644
index 0000000..e233448
--- /dev/null
+++ b/css/bordert/basic.snippet
@@ -0,0 +1 @@
+border-top: ${1:1}px ${2:solid} #${3:999};$0
diff --git a/css/bordert/color.snippet b/css/bordert/color.snippet
new file mode 100644
index 0000000..1a79fb4
--- /dev/null
+++ b/css/bordert/color.snippet
@@ -0,0 +1 @@
+border-top-color: #${1:999};$0
diff --git a/css/bordert/style.snippet b/css/bordert/style.snippet
new file mode 100644
index 0000000..d6ae011
--- /dev/null
+++ b/css/bordert/style.snippet
@@ -0,0 +1 @@
+border-top-style: ${1:none/hidden/dotted/dashed/solid/double/groove/ridge/inset/outset};$0
diff --git a/css/bordert/width.snippet b/css/bordert/width.snippet
new file mode 100644
index 0000000..5faaef1
--- /dev/null
+++ b/css/bordert/width.snippet
@@ -0,0 +1 @@
+border-top-width: ${1:1}px ${2:solid} #${3:999};$0
diff --git a/css/clear.snippet b/css/clear.snippet
new file mode 100644
index 0000000..16b3930
--- /dev/null
+++ b/css/clear.snippet
@@ -0,0 +1 @@
+clear: ${1:left/right/both/none};$0
diff --git a/css/color.snippet b/css/color.snippet
new file mode 100644
index 0000000..3d2728a
--- /dev/null
+++ b/css/color.snippet
@@ -0,0 +1 @@
+color: #${1:DDD};$0
diff --git a/css/colorn.snippet b/css/colorn.snippet
new file mode 100644
index 0000000..52da6c9
--- /dev/null
+++ b/css/colorn.snippet
@@ -0,0 +1 @@
+color: ${1:red};$0
diff --git a/css/colorr.snippet b/css/colorr.snippet
new file mode 100644
index 0000000..4204aad
--- /dev/null
+++ b/css/colorr.snippet
@@ -0,0 +1 @@
+color: rgb(${1:255},${2:255},${3:255});$0
diff --git a/css/cursor.snippet b/css/cursor.snippet
new file mode 100644
index 0000000..c2e45c7
--- /dev/null
+++ b/css/cursor.snippet
@@ -0,0 +1 @@
+cursor: ${1:default/auto/crosshair/pointer/move/*-resize/text/wait/help};$0
diff --git a/css/cursuru.snippet b/css/cursuru.snippet
new file mode 100644
index 0000000..35b1ef2
--- /dev/null
+++ b/css/cursuru.snippet
@@ -0,0 +1 @@
+cursor: url($1);$0
diff --git a/css/direction.snippet b/css/direction.snippet
new file mode 100644
index 0000000..e0a495a
--- /dev/null
+++ b/css/direction.snippet
@@ -0,0 +1 @@
+direction: ${1:ltr|rtl};$0
diff --git a/css/display/block.snippet b/css/display/block.snippet
new file mode 100644
index 0000000..d35d1c2
--- /dev/null
+++ b/css/display/block.snippet
@@ -0,0 +1 @@
+display: block;$0
diff --git a/css/display/common.snippet b/css/display/common.snippet
new file mode 100644
index 0000000..38100a8
--- /dev/null
+++ b/css/display/common.snippet
@@ -0,0 +1 @@
+display: ${1:none/inline/block/list-item/run-in/compact/marker};$0
diff --git a/css/display/inline.snippet b/css/display/inline.snippet
new file mode 100644
index 0000000..1969678
--- /dev/null
+++ b/css/display/inline.snippet
@@ -0,0 +1 @@
+display: inline;$0
diff --git a/css/display/table.snippet b/css/display/table.snippet
new file mode 100644
index 0000000..eeb4da0
--- /dev/null
+++ b/css/display/table.snippet
@@ -0,0 +1 @@
+display: ${1:table/inline-table/table-row-group/table-header-group/table-footer-group/table-row/table-column-group/table-column/table-cell/table-caption};$0
diff --git a/css/float.snippet b/css/float.snippet
new file mode 100644
index 0000000..b43a23c
--- /dev/null
+++ b/css/float.snippet
@@ -0,0 +1 @@
+float: ${1:left/right/none};$0
diff --git a/css/font/all.snippet b/css/font/all.snippet
new file mode 100644
index 0000000..30900a1
--- /dev/null
+++ b/css/font/all.snippet
@@ -0,0 +1 @@
+font: ${1:normal/italic/oblique} ${2:normal/small-caps} ${3:normal/bold} ${4:1em/1.5em} ${5:Arial}, ${6:sans-}serif;$0
diff --git a/css/font/family.snippet b/css/font/family.snippet
new file mode 100644
index 0000000..b48c3f6
--- /dev/null
+++ b/css/font/family.snippet
@@ -0,0 +1 @@
+font-family: ${1:Arial, "MS Trebuchet"}, ${2:sans-}serif;$0
diff --git a/css/font/size.snippet b/css/font/size.snippet
new file mode 100644
index 0000000..4a43b04
--- /dev/null
+++ b/css/font/size.snippet
@@ -0,0 +1 @@
+font-size: ${1:100%};$0
diff --git a/css/font/size_font.snippet b/css/font/size_font.snippet
new file mode 100644
index 0000000..185b615
--- /dev/null
+++ b/css/font/size_font.snippet
@@ -0,0 +1 @@
+font: ${1:75%} ${2:"Lucida Grande", "Trebuchet MS", Verdana,} ${3:sans-}serif;$0
diff --git a/css/font/style.snippet b/css/font/style.snippet
new file mode 100644
index 0000000..94b6e1d
--- /dev/null
+++ b/css/font/style.snippet
@@ -0,0 +1 @@
+font-style: ${1:normal/italic/oblique};$0
diff --git a/css/font/variant.snippet b/css/font/variant.snippet
new file mode 100644
index 0000000..f0aa67f
--- /dev/null
+++ b/css/font/variant.snippet
@@ -0,0 +1 @@
+font-variant: ${1:normal/small-caps};$0
diff --git a/css/font/weight.snippet b/css/font/weight.snippet
new file mode 100644
index 0000000..c355c88
--- /dev/null
+++ b/css/font/weight.snippet
@@ -0,0 +1 @@
+font-weight: ${1:normal/bold};$0
diff --git a/css/i.snippet b/css/i.snippet
new file mode 100644
index 0000000..5ca99ef
--- /dev/null
+++ b/css/i.snippet
@@ -0,0 +1 @@
+${1:!important}
diff --git a/css/letter.snippet b/css/letter.snippet
new file mode 100644
index 0000000..53f64a1
--- /dev/null
+++ b/css/letter.snippet
@@ -0,0 +1 @@
+letter-spacing: ${1}${2:em/px};$0
diff --git a/css/letterem.snippet b/css/letterem.snippet
new file mode 100644
index 0000000..4d81aa3
--- /dev/null
+++ b/css/letterem.snippet
@@ -0,0 +1 @@
+letter-spacing: $1em;$0
diff --git a/css/letterpx.snippet b/css/letterpx.snippet
new file mode 100644
index 0000000..d6d3fee
--- /dev/null
+++ b/css/letterpx.snippet
@@ -0,0 +1 @@
+letter-spacing: $1px;$0
diff --git a/css/list-style/image.snippet b/css/list-style/image.snippet
new file mode 100644
index 0000000..f6f0bc8
--- /dev/null
+++ b/css/list-style/image.snippet
@@ -0,0 +1 @@
+list-style-image: url($1);$0
diff --git a/css/list-style/position.snippet b/css/list-style/position.snippet
new file mode 100644
index 0000000..904f45d
--- /dev/null
+++ b/css/list-style/position.snippet
@@ -0,0 +1 @@
+list-style-position: ${1:inside/outside};$0
diff --git a/css/list-style/type_asian.snippet b/css/list-style/type_asian.snippet
new file mode 100644
index 0000000..220cf07
--- /dev/null
+++ b/css/list-style/type_asian.snippet
@@ -0,0 +1 @@
+list-style-type: ${1:cjk-ideographic/hiragana/katakana/hiragana-iroha/katakana-iroha};$0
diff --git a/css/list-style/type_marker.snippet b/css/list-style/type_marker.snippet
new file mode 100644
index 0000000..5c9350a
--- /dev/null
+++ b/css/list-style/type_marker.snippet
@@ -0,0 +1 @@
+list-style-type: ${1:none/disc/circle/square};$0
diff --git a/css/list-style/type_numeric.snippet b/css/list-style/type_numeric.snippet
new file mode 100644
index 0000000..05efdce
--- /dev/null
+++ b/css/list-style/type_numeric.snippet
@@ -0,0 +1 @@
+list-style-type: ${1:decimal/decimal-leading-zero/zero};$0
diff --git a/css/list-style/type_other.snippet b/css/list-style/type_other.snippet
new file mode 100644
index 0000000..0e987a9
--- /dev/null
+++ b/css/list-style/type_other.snippet
@@ -0,0 +1 @@
+list-style-type: ${1:hebrew/armenian/georgian};$0
diff --git a/css/list-style/type_position_image.snippet b/css/list-style/type_position_image.snippet
new file mode 100644
index 0000000..8d7397b
--- /dev/null
+++ b/css/list-style/type_position_image.snippet
@@ -0,0 +1 @@
+list-style: ${1:none/disc/circle/square/decimal/zero} ${2:inside/outside} url($3);$0
diff --git a/css/list-style/type_roman_alpha_greek.snippet b/css/list-style/type_roman_alpha_greek.snippet
new file mode 100644
index 0000000..7a6a762
--- /dev/null
+++ b/css/list-style/type_roman_alpha_greek.snippet
@@ -0,0 +1 @@
+list-style-type: ${1:lower-roman/upper-roman/lower-alpha/upper-alpha/lower-greek/lower-latin/upper-latin};$0
diff --git a/css/margin.snippet b/css/margin.snippet
new file mode 100644
index 0000000..06d3fa9
--- /dev/null
+++ b/css/margin.snippet
@@ -0,0 +1 @@
+margin: ${1:20px} ${2:0px} ${3:40px} ${4:0px};$0
diff --git a/css/marginb.snippet b/css/marginb.snippet
new file mode 100644
index 0000000..abb7f41
--- /dev/null
+++ b/css/marginb.snippet
@@ -0,0 +1 @@
+margin-bottom: ${1:20px};$0
diff --git a/css/marginl.snippet b/css/marginl.snippet
new file mode 100644
index 0000000..5ecc61b
--- /dev/null
+++ b/css/marginl.snippet
@@ -0,0 +1 @@
+margin-left: ${1:20px};$0
diff --git a/css/margino/T_R_B_L.snippet b/css/margino/T_R_B_L.snippet
new file mode 100644
index 0000000..06d3fa9
--- /dev/null
+++ b/css/margino/T_R_B_L.snippet
@@ -0,0 +1 @@
+margin: ${1:20px} ${2:0px} ${3:40px} ${4:0px};$0
diff --git a/css/margino/V_H.snippet b/css/margino/V_H.snippet
new file mode 100644
index 0000000..e342797
--- /dev/null
+++ b/css/margino/V_H.snippet
@@ -0,0 +1 @@
+margin: ${1:20px} ${2:0px};$0
diff --git a/css/margino/all.snippet b/css/margino/all.snippet
new file mode 100644
index 0000000..1be5f95
--- /dev/null
+++ b/css/margino/all.snippet
@@ -0,0 +1 @@
+margin: ${1:20px};$0
diff --git a/css/margino/bottom.snippet b/css/margino/bottom.snippet
new file mode 100644
index 0000000..abb7f41
--- /dev/null
+++ b/css/margino/bottom.snippet
@@ -0,0 +1 @@
+margin-bottom: ${1:20px};$0
diff --git a/css/margino/left.snippet b/css/margino/left.snippet
new file mode 100644
index 0000000..5ecc61b
--- /dev/null
+++ b/css/margino/left.snippet
@@ -0,0 +1 @@
+margin-left: ${1:20px};$0
diff --git a/css/margino/right.snippet b/css/margino/right.snippet
new file mode 100644
index 0000000..d600636
--- /dev/null
+++ b/css/margino/right.snippet
@@ -0,0 +1 @@
+margin-right: ${1:20px};$0
diff --git a/css/margino/top.snippet b/css/margino/top.snippet
new file mode 100644
index 0000000..c2bc40f
--- /dev/null
+++ b/css/margino/top.snippet
@@ -0,0 +1 @@
+margin-top: ${1:20px};$0
diff --git a/css/marginr.snippet b/css/marginr.snippet
new file mode 100644
index 0000000..d600636
--- /dev/null
+++ b/css/marginr.snippet
@@ -0,0 +1 @@
+margin-right: ${1:20px};$0
diff --git a/css/margint.snippet b/css/margint.snippet
new file mode 100644
index 0000000..c2bc40f
--- /dev/null
+++ b/css/margint.snippet
@@ -0,0 +1 @@
+margin-top: ${1:20px};$0
diff --git a/css/marker/offset_auto.snippet b/css/marker/offset_auto.snippet
new file mode 100644
index 0000000..f4c107a
--- /dev/null
+++ b/css/marker/offset_auto.snippet
@@ -0,0 +1 @@
+marker-offset: auto;$0
diff --git a/css/marker/offset_length.snippet b/css/marker/offset_length.snippet
new file mode 100644
index 0000000..864e750
--- /dev/null
+++ b/css/marker/offset_length.snippet
@@ -0,0 +1 @@
+marker-offset: ${1:10px};$0
diff --git a/css/opacity.snippet b/css/opacity.snippet
new file mode 100644
index 0000000..de7d62b
--- /dev/null
+++ b/css/opacity.snippet
@@ -0,0 +1,3 @@
+opacity: ${1:0.5};${100:
+}-moz-opacity: ${1:0.5};${100:
+}filter:alpha(opacity=${2:${1/(1?)0?\.(.*)/$1$2/}${1/^\d*\.\d\d+$|^\d*$|(^\d\.\d$)/(?1:0)/}});$0
diff --git a/css/overflow.snippet b/css/overflow.snippet
new file mode 100644
index 0000000..3caac03
--- /dev/null
+++ b/css/overflow.snippet
@@ -0,0 +1 @@
+overflow: ${1:visible/hidden/scroll/auto};$0
diff --git a/css/padding.snippet b/css/padding.snippet
new file mode 100644
index 0000000..db2a3ef
--- /dev/null
+++ b/css/padding.snippet
@@ -0,0 +1 @@
+padding: ${1:20px} ${2:0px} ${3:40px} ${4:0px};$0
diff --git a/css/paddingb.snippet b/css/paddingb.snippet
new file mode 100644
index 0000000..66ad6be
--- /dev/null
+++ b/css/paddingb.snippet
@@ -0,0 +1 @@
+padding-bottom: ${1:20px};$0
diff --git a/css/paddingl.snippet b/css/paddingl.snippet
new file mode 100644
index 0000000..0853f49
--- /dev/null
+++ b/css/paddingl.snippet
@@ -0,0 +1 @@
+padding-left: ${1:20px};$0
diff --git a/css/paddingo/T_R_B_L.snippet b/css/paddingo/T_R_B_L.snippet
new file mode 100644
index 0000000..db2a3ef
--- /dev/null
+++ b/css/paddingo/T_R_B_L.snippet
@@ -0,0 +1 @@
+padding: ${1:20px} ${2:0px} ${3:40px} ${4:0px};$0
diff --git a/css/paddingo/V_H.snippet b/css/paddingo/V_H.snippet
new file mode 100644
index 0000000..0b92d8e
--- /dev/null
+++ b/css/paddingo/V_H.snippet
@@ -0,0 +1 @@
+padding: ${1:20px} ${2:0px};$0
diff --git a/css/paddingo/all.snippet b/css/paddingo/all.snippet
new file mode 100644
index 0000000..6d38bf7
--- /dev/null
+++ b/css/paddingo/all.snippet
@@ -0,0 +1 @@
+padding: ${1:20px};$0
diff --git a/css/paddingo/bottom.snippet b/css/paddingo/bottom.snippet
new file mode 100644
index 0000000..66ad6be
--- /dev/null
+++ b/css/paddingo/bottom.snippet
@@ -0,0 +1 @@
+padding-bottom: ${1:20px};$0
diff --git a/css/paddingo/left.snippet b/css/paddingo/left.snippet
new file mode 100644
index 0000000..0853f49
--- /dev/null
+++ b/css/paddingo/left.snippet
@@ -0,0 +1 @@
+padding-left: ${1:20px};$0
diff --git a/css/paddingo/right.snippet b/css/paddingo/right.snippet
new file mode 100644
index 0000000..91a4c80
--- /dev/null
+++ b/css/paddingo/right.snippet
@@ -0,0 +1 @@
+padding-right: ${1:20px};$0
diff --git a/css/paddingo/top.snippet b/css/paddingo/top.snippet
new file mode 100644
index 0000000..9ba6335
--- /dev/null
+++ b/css/paddingo/top.snippet
@@ -0,0 +1 @@
+padding-top: ${1:20px};$0
diff --git a/css/paddingr.snippet b/css/paddingr.snippet
new file mode 100644
index 0000000..91a4c80
--- /dev/null
+++ b/css/paddingr.snippet
@@ -0,0 +1 @@
+padding-right: ${1:20px};$0
diff --git a/css/paddingt.snippet b/css/paddingt.snippet
new file mode 100644
index 0000000..9ba6335
--- /dev/null
+++ b/css/paddingt.snippet
@@ -0,0 +1 @@
+padding-top: ${1:20px};$0
diff --git a/css/position.snippet b/css/position.snippet
new file mode 100644
index 0000000..2643aae
--- /dev/null
+++ b/css/position.snippet
@@ -0,0 +1 @@
+position: ${1:static/relative/absolute/fixed};$0
diff --git a/css/scrollbar.snippet b/css/scrollbar.snippet
new file mode 100644
index 0000000..f017249
--- /dev/null
+++ b/css/scrollbar.snippet
@@ -0,0 +1,8 @@
+scrollbar-base-color: ${1:#CCCCCC};${2:
+scrollbar-arrow-color: ${3:#000000};
+scrollbar-track-color: ${4:#999999};
+scrollbar-3dlight-color: ${5:#EEEEEE};
+scrollbar-highlight-color: ${6:#FFFFFF};
+scrollbar-face-color: ${7:#CCCCCC};
+scrollbar-shadow-color: ${9:#999999};
+scrollbar-darkshadow-color: ${8:#666666};}
diff --git a/css/text/align.snippet b/css/text/align.snippet
new file mode 100644
index 0000000..c3a4db3
--- /dev/null
+++ b/css/text/align.snippet
@@ -0,0 +1 @@
+text-align: ${1:left/right/center/justify};$0
diff --git a/css/text/decoration.snippet b/css/text/decoration.snippet
new file mode 100644
index 0000000..1af58ee
--- /dev/null
+++ b/css/text/decoration.snippet
@@ -0,0 +1 @@
+text-decoration: ${1:none/underline/overline/line-through/blink};$0
diff --git a/css/text/indent.snippet b/css/text/indent.snippet
new file mode 100644
index 0000000..2dac54b
--- /dev/null
+++ b/css/text/indent.snippet
@@ -0,0 +1 @@
+text-indent: ${1:10}px;$0
diff --git a/css/text/shadow_hex.snippet b/css/text/shadow_hex.snippet
new file mode 100644
index 0000000..f6559e4
--- /dev/null
+++ b/css/text/shadow_hex.snippet
@@ -0,0 +1 @@
+text-shadow: #${1:DDD} ${2:10px} ${3:10px} ${4:2px};$0
diff --git a/css/text/shadow_none.snippet b/css/text/shadow_none.snippet
new file mode 100644
index 0000000..57a9eb3
--- /dev/null
+++ b/css/text/shadow_none.snippet
@@ -0,0 +1 @@
+text-shadow: none;$0
diff --git a/css/text/shadow_rgb.snippet b/css/text/shadow_rgb.snippet
new file mode 100644
index 0000000..9b5eacb
--- /dev/null
+++ b/css/text/shadow_rgb.snippet
@@ -0,0 +1 @@
+text-shadow: rgb(${1:255},${2:255},${3:255}) ${4:10px} ${5:10px} ${6:2px};$0
diff --git a/css/text/transform.snippet b/css/text/transform.snippet
new file mode 100644
index 0000000..e5cec4c
--- /dev/null
+++ b/css/text/transform.snippet
@@ -0,0 +1 @@
+text-transform: ${1:capitalize/uppercase/lowercase};$0
diff --git a/css/text/transform_none.snippet b/css/text/transform_none.snippet
new file mode 100644
index 0000000..8618047
--- /dev/null
+++ b/css/text/transform_none.snippet
@@ -0,0 +1 @@
+text-transform: none;$0
diff --git a/css/vertical.snippet b/css/vertical.snippet
new file mode 100644
index 0000000..5f76ac1
--- /dev/null
+++ b/css/vertical.snippet
@@ -0,0 +1 @@
+vertical-align: ${1:baseline/sub/super/top/text-top/middle/bottom/text-bottom/length/%};$0
diff --git a/css/visibility.snippet b/css/visibility.snippet
new file mode 100644
index 0000000..5f76ac1
--- /dev/null
+++ b/css/visibility.snippet
@@ -0,0 +1 @@
+vertical-align: ${1:baseline/sub/super/top/text-top/middle/bottom/text-bottom/length/%};$0
diff --git a/css/white.snippet b/css/white.snippet
new file mode 100644
index 0000000..066260a
--- /dev/null
+++ b/css/white.snippet
@@ -0,0 +1 @@
+white-space: ${1:normal/pre/nowrap};$0
diff --git a/css/word/spacing_length.snippet b/css/word/spacing_length.snippet
new file mode 100644
index 0000000..647ea3e
--- /dev/null
+++ b/css/word/spacing_length.snippet
@@ -0,0 +1 @@
+word-spacing: ${1:10px};$0
diff --git a/css/word/spacing_normal.snippet b/css/word/spacing_normal.snippet
new file mode 100644
index 0000000..9461551
--- /dev/null
+++ b/css/word/spacing_normal.snippet
@@ -0,0 +1 @@
+word-spacing: normal;$0
diff --git a/css/z.snippet b/css/z.snippet
new file mode 100644
index 0000000..fd19d5f
--- /dev/null
+++ b/css/z.snippet
@@ -0,0 +1 @@
+z-index: $1;$0
|
scrooloose/snipmate-snippets
|
b6b739145253089aaae745d7d13f2aefd9560ce4
|
Added div to html
|
diff --git a/html/div.snippet b/html/div.snippet
new file mode 100644
index 0000000..1ee10bf
--- /dev/null
+++ b/html/div.snippet
@@ -0,0 +1,3 @@
+<div id="${1}">
+ ${2}
+</div>
|
scrooloose/snipmate-snippets
|
a9f4887259ec04628db39be2419c00805de20ad5
|
added snippets for Test::Unit 2.2.0 assertions
|
diff --git a/ruby/asam.snippet b/ruby/asam.snippet
new file mode 100644
index 0000000..3c95b31
--- /dev/null
+++ b/ruby/asam.snippet
@@ -0,0 +1 @@
+assert_alias_method ${1:object}, ${2:alias_name}, ${3:original_name}
diff --git a/ruby/asb.snippet b/ruby/asb.snippet
new file mode 100644
index 0000000..ab1eff7
--- /dev/null
+++ b/ruby/asb.snippet
@@ -0,0 +1 @@
+assert_boolean ${1:actual}
diff --git a/ruby/asc.snippet b/ruby/asc.snippet
new file mode 100644
index 0000000..c6badc3
--- /dev/null
+++ b/ruby/asc.snippet
@@ -0,0 +1 @@
+assert_compare ${1:expected}, ${2:operator}, ${3:actual}
diff --git a/ruby/ascd.snippet b/ruby/ascd.snippet
new file mode 100644
index 0000000..bc77908
--- /dev/null
+++ b/ruby/ascd.snippet
@@ -0,0 +1 @@
+assert_const_defined ${1:object}, ${2:constant_name}
diff --git a/ruby/asem.snippet b/ruby/asem.snippet
new file mode 100644
index 0000000..4642832
--- /dev/null
+++ b/ruby/asem.snippet
@@ -0,0 +1 @@
+assert_empty ${1:object}
diff --git a/ruby/asf.snippet b/ruby/asf.snippet
new file mode 100644
index 0000000..27ff6da
--- /dev/null
+++ b/ruby/asf.snippet
@@ -0,0 +1 @@
+assert_false ${1:actual}
diff --git a/ruby/asfa.snippet b/ruby/asfa.snippet
new file mode 100644
index 0000000..f45fa53
--- /dev/null
+++ b/ruby/asfa.snippet
@@ -0,0 +1 @@
+assert_fail_assertion { ${1:block} }
diff --git a/ruby/asi.snippet b/ruby/asi.snippet
new file mode 100644
index 0000000..dedf94d
--- /dev/null
+++ b/ruby/asi.snippet
@@ -0,0 +1 @@
+assert_include ${1:collection}, ${2:object}
diff --git a/ruby/asie.snippet b/ruby/asie.snippet
new file mode 100644
index 0000000..f13d0a3
--- /dev/null
+++ b/ruby/asie.snippet
@@ -0,0 +1 @@
+assert_in_epsilon ${1:expected_float}, ${2:actual_float}
diff --git a/ruby/asncd.snippet b/ruby/asncd.snippet
new file mode 100644
index 0000000..b4dcd73
--- /dev/null
+++ b/ruby/asncd.snippet
@@ -0,0 +1 @@
+assert_not_const_defined ${1:object}, ${2:constant_name}
diff --git a/ruby/asnem.snippet b/ruby/asnem.snippet
new file mode 100644
index 0000000..43d0772
--- /dev/null
+++ b/ruby/asnem.snippet
@@ -0,0 +1 @@
+assert_not_empty ${1:object}
diff --git a/ruby/asni.snippet b/ruby/asni.snippet
new file mode 100644
index 0000000..d450d9e
--- /dev/null
+++ b/ruby/asni.snippet
@@ -0,0 +1 @@
+assert_not_include ${1:collection}, ${2:object}
diff --git a/ruby/asnid.snippet b/ruby/asnid.snippet
new file mode 100644
index 0000000..23e039a
--- /dev/null
+++ b/ruby/asnid.snippet
@@ -0,0 +1 @@
+assert_not_in_delta ${1:expected_float}, ${2:actual_float}
diff --git a/ruby/asnie.snippet b/ruby/asnie.snippet
new file mode 100644
index 0000000..25eb751
--- /dev/null
+++ b/ruby/asnie.snippet
@@ -0,0 +1 @@
+assert_not_in_epsilon ${1:expected_float}, ${2:actual_float}
diff --git a/ruby/asnp.snippet b/ruby/asnp.snippet
new file mode 100644
index 0000000..a540f84
--- /dev/null
+++ b/ruby/asnp.snippet
@@ -0,0 +1 @@
+assert_not_predicate ${1:object}, ${2:predicate}
diff --git a/ruby/asnr.snippet b/ruby/asnr.snippet
new file mode 100644
index 0000000..fc9a820
--- /dev/null
+++ b/ruby/asnr.snippet
@@ -0,0 +1 @@
+assert_nothing_raised { ${1:block} }
diff --git a/ruby/asnrt.snippet b/ruby/asnrt.snippet
new file mode 100644
index 0000000..fb063d2
--- /dev/null
+++ b/ruby/asnrt.snippet
@@ -0,0 +1 @@
+assert_not_respond_to ${1:object}, ${2:method}
diff --git a/ruby/asnse.snippet b/ruby/asnse.snippet
new file mode 100644
index 0000000..befde12
--- /dev/null
+++ b/ruby/asnse.snippet
@@ -0,0 +1 @@
+assert_not_send ${1:send_array}
diff --git a/ruby/asp.snippet b/ruby/asp.snippet
new file mode 100644
index 0000000..c23fd3f
--- /dev/null
+++ b/ruby/asp.snippet
@@ -0,0 +1 @@
+assert_predicate ${1:object}, ${2:predicate}
diff --git a/ruby/aspe.snippet b/ruby/aspe.snippet
new file mode 100644
index 0000000..3a3eed4
--- /dev/null
+++ b/ruby/aspe.snippet
@@ -0,0 +1 @@
+assert_path_exist ${1:path}
diff --git a/ruby/aspne.snippet b/ruby/aspne.snippet
new file mode 100644
index 0000000..f7a8873
--- /dev/null
+++ b/ruby/aspne.snippet
@@ -0,0 +1 @@
+assert_path_not_exist ${1:path}
diff --git a/ruby/asrko.snippet b/ruby/asrko.snippet
new file mode 100644
index 0000000..f82820e
--- /dev/null
+++ b/ruby/asrko.snippet
@@ -0,0 +1 @@
+assert_raise_kind_of(${1:kinds...}) { ${2:block} }
diff --git a/ruby/asrm.snippet b/ruby/asrm.snippet
new file mode 100644
index 0000000..f62f208
--- /dev/null
+++ b/ruby/asrm.snippet
@@ -0,0 +1 @@
+assert_raise_message ${1:expected_message}
diff --git a/ruby/asse.snippet b/ruby/asse.snippet
new file mode 100644
index 0000000..4fb9ef9
--- /dev/null
+++ b/ruby/asse.snippet
@@ -0,0 +1 @@
+assert_send ${1:send_array}
diff --git a/ruby/astr.snippet b/ruby/astr.snippet
new file mode 100644
index 0000000..b9d14f6
--- /dev/null
+++ b/ruby/astr.snippet
@@ -0,0 +1 @@
+assert_true ${1:actual}
|
scrooloose/snipmate-snippets
|
fc0b41cd02c142442ede3f39bc444e897232dd3f
|
Added try catch snippet for php
|
diff --git a/php/try.snippet b/php/try.snippet
new file mode 100644
index 0000000..66a7f65
--- /dev/null
+++ b/php/try.snippet
@@ -0,0 +1,6 @@
+try {
+ ${1:// code...}
+} catch (${2:Exception} $e) {
+ ${3:// code...}
+}
+
|
scrooloose/snipmate-snippets
|
68c133b51caa7e5c628e0103391998eb750f5538
|
detect correctly Windows OS work with pathogen.vim too
|
diff --git a/Rakefile b/Rakefile
index 22ce218..15cece2 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,22 +1,24 @@
#require 'fileutils'
#include FileUtils
namespace :snippets_dir do
task :find do
- @snippets_dir = File.join(ENV['VIMFILES'] || ENV['HOME'] || ENV['USERPROFILE'], RUBY_PLATFORM =~ /mswin32/ ? "vimfiles" : ".vim", "snippets")
+ vim_dir = File.join(ENV['VIMFILES'] || ENV['HOME'] || ENV['USERPROFILE'], RUBY_PLATFORM =~ /mswin|msys|mingw32/ ? "vimfiles" : ".vim")
+ pathogen_dir = File.join(vim_dir, "bundle")
+ @snippets_dir = File.directory?(pathogen_dir) ? File.join(pathogen_dir, "snipmate", "snippets") : File.join(vim_dir, "snippets")
end
desc "Purge the contents of the vim snippets directory"
task :purge => ["snippets_dir:find"] do
rm_rf @snippets_dir, :verbose => true if File.directory? @snippets_dir
mkdir @snippets_dir, :verbose => true
end
end
desc "Copy the snippets directories into ~/.vim/snippets"
task :deploy_local => ["snippets_dir:purge"] do
Dir.foreach(".") do |f|
cp_r f, @snippets_dir, :verbose => true if File.directory?(f) && f =~ /^[^\.]/
end
cp "support_functions.vim", @snippets_dir, :verbose => true
end
|
scrooloose/snipmate-snippets
|
50574d8577a69b242dcded6ce9635bf5d0320067
|
Use double quotes for RSpec it blocks
|
diff --git a/ruby-rspec/it.snippet b/ruby-rspec/it.snippet
index 5f3900b..8af38db 100644
--- a/ruby-rspec/it.snippet
+++ b/ruby-rspec/it.snippet
@@ -1,3 +1,3 @@
-it '${1}' do
+it "${1}" do
${2}
end
|
scrooloose/snipmate-snippets
|
f8e281cfa24b67d8886317bf71368c7210eb4836
|
Simplify RSpec require
|
diff --git a/ruby-rspec/desc.snippet b/ruby-rspec/desc.snippet
index c733bd1..6311aa1 100644
--- a/ruby-rspec/desc.snippet
+++ b/ruby-rspec/desc.snippet
@@ -1,5 +1,5 @@
-require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+require 'spec_helper'
-describe ${1:controller} do
+describe ${1:`Snippet_RubyClassNameFromFilename()`} do
${2}
end
diff --git a/support_functions.vim b/support_functions.vim
index 389666c..a09e81d 100644
--- a/support_functions.vim
+++ b/support_functions.vim
@@ -1,115 +1,115 @@
"ruby {{{1
function! Snippet_RubyClassNameFromFilename(...)
let name = expand("%:t:r")
if len(name) == 0
if a:0 == 0
let name = 'MyClass'
else
let name = a:1
endif
endif
- return Snippet_Camelcase(name)
+ return Snippet_Camelcase(substitute(name, '_spec$', '', ''))
endfunction
function! Snippet_MigrationNameFromFilename(...)
let name = substitute(expand("%:t:r"), '^.\{-}_', '', '')
if len(name) == 0
if a:0 == 0
let name = 'MyClass'
else
let name = a:1
endif
endif
return Snippet_Camelcase(name)
endfunction
"python {{{1
function! Snippet_PythonClassNameFromFilename(...)
let name = expand("%:t:r")
if len(name) == 0
if a:0 == 0
let name = 'MyClass'
else
let name = a:1
endif
endif
return Snippet_Camelcase(name)
endfunction
"php {{{1
function! Snippet_PHPClassNameFromFilename(...)
let name = expand("%:t:r:r")
if len(name) == 0
if a:0 == 0
let name = 'MyClass'
else
let name = a:1
endif
endif
return name
endfunction
"java {{{1
function! Snippet_JavaClassNameFromFilename(...)
let name = expand("%:t:r")
if len(name) == 0
if a:0 == 0
let name = 'MyClass'
else
let name = a:1
endif
endif
return name
endfunction
function! Snippet_JavaInstanceVarType(name)
let oldview = winsaveview()
if searchdecl(a:name) == 0
normal! B
let old_reg = @"
normal! yaW
let type = @"
let @" = old_reg
call winrestview(oldview)
let type = substitute(type, '\s\+$', '', '')
"searchdecl treats 'return foo;' as a declaration of foo
if type != 'return'
return type
endif
endif
return "<+type+>"
endfunction
"global {{{1
function! s:start_comment()
return substitute(&commentstring, '^\([^ ]*\)\s*%s\(.*\)$', '\1', '')
endfunction
function! s:end_comment()
return substitute(&commentstring, '^.*%s\(.*\)$', '\1', '')
endfunction
function! Snippet_Modeline()
return s:start_comment() . " vim: set ${1:settings}:" . s:end_comment()
endfunction
function! Snippet_Camelcase(s)
"upcase the first letter
let toReturn = substitute(a:s, '^\(.\)', '\=toupper(submatch(1))', '')
"turn all '_x' into 'X'
return substitute(toReturn, '_\(.\)', '\=toupper(submatch(1))', 'g')
endfunction
function! Snippet_Underscore(s)
"down the first letter
let toReturn = substitute(a:s, '^\(.\)', '\=tolower(submatch(1))', '')
"turn all 'X' into '_x'
return substitute(toReturn, '\([A-Z]\)', '\=tolower("_".submatch(1))', 'g')
endfunction
" modeline {{{1
" vim: set fdm=marker:
|
scrooloose/snipmate-snippets
|
8e6192909d72595c5909cecd3c567d3152592d60
|
Javascript log -> console.log() snippet
|
diff --git a/javascript/log.snippet b/javascript/log.snippet
new file mode 100644
index 0000000..b4cf84f
--- /dev/null
+++ b/javascript/log.snippet
@@ -0,0 +1 @@
+console.log(${1});
|
scrooloose/snipmate-snippets
|
8e4c0724bbca1c4a7e7d67b07a175c5f540a0649
|
Added an Class Extend snippet to PHP
|
diff --git a/php/classe.snippet b/php/classe.snippet
new file mode 100644
index 0000000..2f2b0bc
--- /dev/null
+++ b/php/classe.snippet
@@ -0,0 +1,12 @@
+/**
+ * ${1}
+ */
+class ${2:ClassName} extends ${3:AnotherClass}
+{
+ ${4}
+ function ${5:__construct}(${6:argument})
+ {
+ ${7:// code...}
+ }
+}
+
|
scrooloose/snipmate-snippets
|
f189e5b5b00c360b2b86f475c0d5db8d1fddd380
|
fix the lorem snippet
|
diff --git a/_/lorem.snippet b/_/lorem.snippet
index 5a21b06..cee7a92 100644
--- a/_/lorem.snippet
+++ b/_/lorem.snippet
@@ -1 +1 @@
-Lorem ipsum dolor sit amet, consectetur magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum<++>\<c-o>:normal! gqq\<CR>
+Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
scrooloose/snipmate-snippets
|
c37351df1541fcfdd5e4e22050ebc3b3eb320b00
|
fix the eruby/unlesse snippet
|
diff --git a/eruby/unlesse.snippet b/eruby/unlesse.snippet
index fff2996..6f44739 100644
--- a/eruby/unlesse.snippet
+++ b/eruby/unlesse.snippet
@@ -1,4 +1,4 @@
-<% if ${1} %>
+<% unless ${1} %>
${2}
<% else %>
<% end %>
|
scrooloose/snipmate-snippets
|
d4095107c2a335d8b5bdaf9d2e596991f9e32b4c
|
added snippets for xslt
|
diff --git a/xslt/call.snippet b/xslt/call.snippet
new file mode 100644
index 0000000..2fe4f9d
--- /dev/null
+++ b/xslt/call.snippet
@@ -0,0 +1,3 @@
+ <xsl:call-template name="${1:template}">
+ ${2}
+ </xsl:call-template>
diff --git a/xslt/choose.snippet b/xslt/choose.snippet
new file mode 100644
index 0000000..1a87754
--- /dev/null
+++ b/xslt/choose.snippet
@@ -0,0 +1,7 @@
+ <xsl:choose>
+ <xsl:when test="${1:test}">
+ ${2}
+ </xsl:when>
+ <xsl:otherwise>
+ </xsl:otherwise>
+ </xsl:choose>
diff --git a/xslt/mat.snippet b/xslt/mat.snippet
new file mode 100644
index 0000000..a566e0e
--- /dev/null
+++ b/xslt/mat.snippet
@@ -0,0 +1,3 @@
+ <xsl:template match="${1:match}"/>
+ ${2}
+ </xsl:template>
diff --git a/xslt/out.snippet b/xslt/out.snippet
new file mode 100644
index 0000000..88e70c2
--- /dev/null
+++ b/xslt/out.snippet
@@ -0,0 +1 @@
+ <xsl:output omit-xml-declaration="${1:yes}" method="${2:html}"/>
diff --git a/xslt/param.snippet b/xslt/param.snippet
new file mode 100644
index 0000000..f4f9a50
--- /dev/null
+++ b/xslt/param.snippet
@@ -0,0 +1 @@
+ <xsl:param name="${1:name}" />
diff --git a/xslt/sty.snippet b/xslt/sty.snippet
new file mode 100644
index 0000000..f6751c7
--- /dev/null
+++ b/xslt/sty.snippet
@@ -0,0 +1,3 @@
+ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ ${1}
+ </xsl:stylesheet>
diff --git a/xslt/tem.snippet b/xslt/tem.snippet
new file mode 100644
index 0000000..bcd86d6
--- /dev/null
+++ b/xslt/tem.snippet
@@ -0,0 +1,3 @@
+ <xsl:template name="${1:name}">
+ ${2}
+ </xsl:template>
diff --git a/xslt/value.snippet b/xslt/value.snippet
new file mode 100644
index 0000000..9128cc6
--- /dev/null
+++ b/xslt/value.snippet
@@ -0,0 +1 @@
+ <xsl:value-of select="${1:select}"/>
diff --git a/xslt/var.snippet b/xslt/var.snippet
new file mode 100644
index 0000000..d21b77c
--- /dev/null
+++ b/xslt/var.snippet
@@ -0,0 +1,3 @@
+ <xsl:variable name="${1:name}"/>
+ ${2}
+ </xsl:variable>
diff --git a/xslt/wparam.snippet b/xslt/wparam.snippet
new file mode 100644
index 0000000..2284b71
--- /dev/null
+++ b/xslt/wparam.snippet
@@ -0,0 +1 @@
+ <xsl:with-param name="${1:name}" select="${2:select}" />
diff --git a/xslt/xdec.snippet b/xslt/xdec.snippet
new file mode 100644
index 0000000..f1e4420
--- /dev/null
+++ b/xslt/xdec.snippet
@@ -0,0 +1,2 @@
+ <?xml version="1.0" ecoding="${1:encoding}"?>
+ ${2}
|
scrooloose/snipmate-snippets
|
f9f420418df3578c10833fe1a7f33adaedacf8c0
|
isbl stands for it_should_behave_like
|
diff --git a/ruby-rspec/isbl.snippet b/ruby-rspec/isbl.snippet
new file mode 100644
index 0000000..728223f
--- /dev/null
+++ b/ruby-rspec/isbl.snippet
@@ -0,0 +1 @@
+it_should_behave_like '${1:do something}'
|
scrooloose/snipmate-snippets
|
2c21d7086ed342454c21e7d4d8539b082f2234d9
|
sef stands for shared_examples_for
|
diff --git a/ruby-rspec/sef.snippet b/ruby-rspec/sef.snippet
new file mode 100644
index 0000000..89d3411
--- /dev/null
+++ b/ruby-rspec/sef.snippet
@@ -0,0 +1,3 @@
+shared_examples_for "${1:do something}" do
+ ${2}
+end
|
scrooloose/snipmate-snippets
|
3e4b05e9f2e73dc67a1dc8a19996523e0890bcaa
|
fixing commonly used rails snippets
|
diff --git a/ruby-rails/hm.snippet b/ruby-rails/hm.snippet
index a622201..9204df5 100644
--- a/ruby-rails/hm.snippet
+++ b/ruby-rails/hm.snippet
@@ -1 +1 @@
-has_many :<+object+>s<+, :class_name => "<+object+>", :foreign_key => "<+reference+>_id"+>
+has_many :${1:object}
diff --git a/ruby-rails/hmt.snippet b/ruby-rails/hmt.snippet
index 9cd81df..4128e03 100644
--- a/ruby-rails/hmt.snippet
+++ b/ruby-rails/hmt.snippet
@@ -1 +1 @@
-has_many :<+association_name+>, :through => :<+join_association+><+, :source => '<++>'+>
+has_many :${1:object}, :through => :${2:object}
diff --git a/ruby-rails/ho.snippet b/ruby-rails/ho.snippet
index f7ec6d8..77e14e7 100644
--- a/ruby-rails/ho.snippet
+++ b/ruby-rails/ho.snippet
@@ -1 +1 @@
-has_one :${1:object}, :class_name => "${2:Class}", :foreign_key => "${3:class}_id"
+has_one :${1:object}
diff --git a/ruby-rails/va.snippet b/ruby-rails/va.snippet
index 4a3b997..064bb7b 100644
--- a/ruby-rails/va.snippet
+++ b/ruby-rails/va.snippet
@@ -1 +1 @@
-validates_associated :<+attribute+><+, :on => :<+:create+>+>
+validates_associated :${1:attribute}
diff --git a/ruby-rails/vao.snippet b/ruby-rails/vao.snippet
index c1fb637..4c6c98b 100644
--- a/ruby-rails/vao.snippet
+++ b/ruby-rails/vao.snippet
@@ -1 +1 @@
-validates_acceptance_of :<+terms+><+, :accept => "<++>", :message => "<+terms_message+>"+>
+validates_acceptance_of :${1:terms}
diff --git a/ruby-rails/vc.snippet b/ruby-rails/vc.snippet
index d2b39aa..0aa1a75 100644
--- a/ruby-rails/vc.snippet
+++ b/ruby-rails/vc.snippet
@@ -1 +1 @@
-validates_confirmation_of :<+attribute+><+, :on => :<+create+>, :message => "<+should match confirmation+>"+>
+validates_confirmation_of :${1:attribute}
diff --git a/ruby-rails/ve.snippet b/ruby-rails/ve.snippet
index e962476..b6a4c4d 100644
--- a/ruby-rails/ve.snippet
+++ b/ruby-rails/ve.snippet
@@ -1 +1 @@
-validates_exclusion_of :<+attribute+><+, :in => <+%w( <+mov avi+> )+>, :on => :<+create+>, :message => "<+extension %s is not allowed+>"+>
+validates_exclusion_of :${1:attribute}, :in => ${2:%w( mov avi )}
diff --git a/ruby-rails/vf.snippet b/ruby-rails/vf.snippet
index 6564847..adc142c 100644
--- a/ruby-rails/vf.snippet
+++ b/ruby-rails/vf.snippet
@@ -1 +1 @@
-validates_format_of :${1:attribute}, :with => /${2:regex}/<+, :on => :<+create+>, :message => "<+is invalid+>"+>
+validates_format_of :${1:attribute}, :with => /${2:regex}/
diff --git a/ruby-rails/vi.snippet b/ruby-rails/vi.snippet
index 7ee5afc..8ba16d2 100644
--- a/ruby-rails/vi.snippet
+++ b/ruby-rails/vi.snippet
@@ -1 +1 @@
-validates_inclusion_of :<+attribute+><+, :in => <+%w( <+mov avi+> )+>, :on => :<+create+>, :message => "<+extension %s is not included in the list+>"+>
+validates_inclusion_of :${1:attribute}, :in => %w(${2: mov avi })
diff --git a/ruby-rails/vl.snippet b/ruby-rails/vl.snippet
index 01a7dfd..71d802b 100644
--- a/ruby-rails/vl.snippet
+++ b/ruby-rails/vl.snippet
@@ -1 +1 @@
-validates_length_of :<+attribute+>, :within => <+3..20+><+, :on => :<+create+>, :message => "<+must be present+>"+>
+validates_length_of :${1:attribute}, :within => ${2:3}..${3:20}
diff --git a/ruby-rails/vn.snippet b/ruby-rails/vn.snippet
index c74aa2c..34bfaa7 100644
--- a/ruby-rails/vn.snippet
+++ b/ruby-rails/vn.snippet
@@ -1 +1 @@
-validates_numericality_of :<+attribute+><+, :on => :<+create+>, :message => "<+is not a number+>"+>
+validates_numericality_of :${1:attribute}
diff --git a/ruby-rails/vu.snippet b/ruby-rails/vu.snippet
index 51d85ea..0c06e65 100644
--- a/ruby-rails/vu.snippet
+++ b/ruby-rails/vu.snippet
@@ -1 +1 @@
-validates_uniqueness_of :<+attribute+><+, :on => :<+create+>, :message => "<+must be unique+>"+>
+validates_uniqueness_of :${1:attribute}
|
scrooloose/snipmate-snippets
|
e42aef33c821728a071bda52d01cadb6b86d47a4
|
fix html and factory girl. remove conflicting ruby snippets. dont need rjs
|
diff --git a/html/body.snippet b/html/body.snippet
index f4d5c24..692403d 100644
--- a/html/body.snippet
+++ b/html/body.snippet
@@ -1,3 +1,3 @@
-<body<+ id="<+id+>"<+ onload="<++>"+>+>>
- <++>
-</body>
\ No newline at end of file
+<body id="${1}">
+ ${2}
+</body>
diff --git a/html/h1.snippet b/html/h1.snippet
index da92bc1..21e88b8 100644
--- a/html/h1.snippet
+++ b/html/h1.snippet
@@ -1 +1 @@
-<h1<+ id="<+id+>"+>><++></h1>
+<h1 id="${1}">${2}</h1>
diff --git a/html/input.snippet b/html/input.snippet
index d2b04df..a8814b2 100644
--- a/html/input.snippet
+++ b/html/input.snippet
@@ -1 +1 @@
-<input type="text" name="<++>" <+value="<++>"+> <+size="<++>"+> <+maxlength="<++>"+> />
+<input type="${1:text/submit/hidden/button}" name="${2}" value="${3:value}" id="${4:$2}"/>${5}
diff --git a/html/option.snippet b/html/option.snippet
index 80ebbfe..b7383d0 100644
--- a/html/option.snippet
+++ b/html/option.snippet
@@ -1 +1 @@
-<option<+ value="<+option+>"+>><+value+></option>
+<option value="${1}">${2}</option>
diff --git a/html/select.snippet b/html/select.snippet
index 0307f28..252e3f7 100644
--- a/html/select.snippet
+++ b/html/select.snippet
@@ -1,5 +1,3 @@
-<select name="<+some_name+>" id="<+id+>"<+<+ multiple+><+ onchange="<++>"+><+ size="<+1+>"+>+>>
- <option<+ value="<+option1+>"+>><+value1+></option>
- <option<+ value="<+option2+>"+>><+value2+></option>
- <++>
+<select name="${1}" id="${2}">
+ ${3}
</select>
diff --git a/ruby-factorygirl/fac.snippet b/ruby-factorygirl/fac.snippet
index 68624af..05cc3e8 100644
--- a/ruby-factorygirl/fac.snippet
+++ b/ruby-factorygirl/fac.snippet
@@ -1 +1 @@
-Factory(:<+factory_name+><+, <++>+>)<++>
+Factory(:${1}, ${2})${3}
diff --git a/ruby-factorygirl/facb.snippet b/ruby-factorygirl/facb.snippet
index 2a3f5ab..299c033 100644
--- a/ruby-factorygirl/facb.snippet
+++ b/ruby-factorygirl/facb.snippet
@@ -1 +1 @@
-Factory.build(:<+factory_name+><+, <++>+>)<++>
+Factory.build(:${1}, ${2})${3}
diff --git a/ruby-factorygirl/facd.snippet b/ruby-factorygirl/facd.snippet
index 4410f7a..41d1503 100644
--- a/ruby-factorygirl/facd.snippet
+++ b/ruby-factorygirl/facd.snippet
@@ -1,4 +1,4 @@
-Factory.define(:${1:model}) do |${2:m}|
+Factory.define(:${1:model}) do |${2:f}|
${3}
end
${4}
diff --git a/ruby-rails-rjs/hide.snippet b/ruby-rails-rjs/hide.snippet
deleted file mode 100644
index edd1235..0000000
--- a/ruby-rails-rjs/hide.snippet
+++ /dev/null
@@ -1 +0,0 @@
-page.hide <+"<+id(s)+>"+>
diff --git a/ruby-rails-rjs/ins.snippet b/ruby-rails-rjs/ins.snippet
deleted file mode 100644
index a1f9daf..0000000
--- a/ruby-rails-rjs/ins.snippet
+++ /dev/null
@@ -1 +0,0 @@
-page.insert_html :<+top+>, <+"<+id+>"+>, :<+partial => "<+template+>"+>
diff --git a/ruby-rails-rjs/rep.snippet b/ruby-rails-rjs/rep.snippet
deleted file mode 100644
index 2b265f1..0000000
--- a/ruby-rails-rjs/rep.snippet
+++ /dev/null
@@ -1 +0,0 @@
-page.replace <+"<+id+>"+>, :<+partial => "<+template+>"+>
diff --git a/ruby-rails-rjs/reph.snippet b/ruby-rails-rjs/reph.snippet
deleted file mode 100644
index 5acf810..0000000
--- a/ruby-rails-rjs/reph.snippet
+++ /dev/null
@@ -1 +0,0 @@
-page.replace_html <+"<+id+>"+>, :<+partial => "<+template+>"+>
diff --git a/ruby-rails-rjs/show.snippet b/ruby-rails-rjs/show.snippet
deleted file mode 100644
index f2cbeed..0000000
--- a/ruby-rails-rjs/show.snippet
+++ /dev/null
@@ -1 +0,0 @@
-page.show <+"<+id(s)+>"+>
diff --git a/ruby-rails-rjs/tog.snippet b/ruby-rails-rjs/tog.snippet
deleted file mode 100644
index bdb78c6..0000000
--- a/ruby-rails-rjs/tog.snippet
+++ /dev/null
@@ -1 +0,0 @@
-page.toggle <+"<+id(s)+>"+>
diff --git a/ruby-rails-rjs/vis.snippet b/ruby-rails-rjs/vis.snippet
deleted file mode 100644
index da1fcb6..0000000
--- a/ruby-rails-rjs/vis.snippet
+++ /dev/null
@@ -1 +0,0 @@
-page.visual_effect :<+toggle_slide+>, <+"<+DOM ID+>"+>
diff --git a/ruby-shoulda/shns.snippet b/ruby-shoulda/shns.snippet
deleted file mode 100644
index a02046d..0000000
--- a/ruby-shoulda/shns.snippet
+++ /dev/null
@@ -1 +0,0 @@
-should_have_named_scope :${1:scope}, :conditions => {${2:conditions}}
diff --git a/ruby/anr.snippet b/ruby/anr.snippet
deleted file mode 100644
index 633d432..0000000
--- a/ruby/anr.snippet
+++ /dev/null
@@ -1 +0,0 @@
-assert_nothing_raised(${1:Exception}) { ${2} }
diff --git a/ruby/ass.snippet b/ruby/ass.snippet
deleted file mode 100644
index 923e90d..0000000
--- a/ruby/ass.snippet
+++ /dev/null
@@ -1 +0,0 @@
-assert_send [${1:object}, :${2:message}, ${3:args}]
|
scrooloose/snipmate-snippets
|
b1b1279e7be4fa7ee2d8ef38c0efe1667dac3705
|
add sshconfig/host snippet
|
diff --git a/sshconfig/host.snippet b/sshconfig/host.snippet
new file mode 100644
index 0000000..5992a2d
--- /dev/null
+++ b/sshconfig/host.snippet
@@ -0,0 +1,3 @@
+Host ${1:name}
+ Hostname ${2:example.com}
+ User ${3:username}
|
scrooloose/snipmate-snippets
|
8182fb7cf6c87fb2e3f07fec52c7738efb4d928c
|
fix rakefile to recognize the home directory
|
diff --git a/Rakefile b/Rakefile
index f8f3bed..22ce218 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,26 +1,22 @@
-require 'fileutils'
-include FileUtils
+#require 'fileutils'
+#include FileUtils
namespace :snippets_dir do
task :find do
- @snippets_dir = File.join(ENV['VIMFILES'] || if RUBY_PLATFORM =~ /mswin32/
- "#{ENV['HOME'] || ENV['USERPROFILE']}\\vimfiles"
- else
- "~/.vim"
- end, "snippets")
+ @snippets_dir = File.join(ENV['VIMFILES'] || ENV['HOME'] || ENV['USERPROFILE'], RUBY_PLATFORM =~ /mswin32/ ? "vimfiles" : ".vim", "snippets")
end
desc "Purge the contents of the vim snippets directory"
task :purge => ["snippets_dir:find"] do
rm_rf @snippets_dir, :verbose => true if File.directory? @snippets_dir
mkdir @snippets_dir, :verbose => true
end
end
desc "Copy the snippets directories into ~/.vim/snippets"
-task :deploy_local => ["snippets_dir:find", "snippets_dir:purge"] do
+task :deploy_local => ["snippets_dir:purge"] do
Dir.foreach(".") do |f|
cp_r f, @snippets_dir, :verbose => true if File.directory?(f) && f =~ /^[^\.]/
end
cp "support_functions.vim", @snippets_dir, :verbose => true
end
|
scrooloose/snipmate-snippets
|
842e5d5f2278ccafceee36638219616bd241d2dc
|
refactor Rakefile
|
diff --git a/Rakefile b/Rakefile
index a602b4d..f8f3bed 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,31 +1,26 @@
-desc "Copy the snippets directories into ~/.vim/snippets"
-task :deploy_local do
- run "rm -rf ~/.vim/snippets"
- run "mkdir ~/.vim/snippets"
- run "cp -r _ ~/.vim/snippets/"
- run "cp -r ant ~/.vim/snippets/"
- run "cp -r c ~/.vim/snippets/"
- run "cp -r eruby ~/.vim/snippets/"
- run "cp -r eruby-rails ~/.vim/snippets/"
- run "cp -r haml ~/.vim/snippets/"
- run "cp -r html ~/.vim/snippets/"
- run "cp -r java ~/.vim/snippets/"
- run "cp -r javascript ~/.vim/snippets/"
- run "cp -r javascript-jquery ~/.vim/snippets/"
- run "cp -r objc ~/.vim/snippets/"
- run "cp -r php ~/.vim/snippets/"
- run "cp -r python ~/.vim/snippets/"
- run "cp -r ruby ~/.vim/snippets/"
- run "cp -r ruby-factorygirl ~/.vim/snippets/"
- run "cp -r ruby-rails ~/.vim/snippets/"
- run "cp -r ruby-rails-rjs ~/.vim/snippets/"
- run "cp -r ruby-rspec ~/.vim/snippets/"
- run "cp -r vim ~/.vim/snippets/"
- run "cp -r zend ~/.vim/snippets/"
- run "cp support_functions.vim ~/.vim/snippets/"
+require 'fileutils'
+include FileUtils
+
+namespace :snippets_dir do
+ task :find do
+ @snippets_dir = File.join(ENV['VIMFILES'] || if RUBY_PLATFORM =~ /mswin32/
+ "#{ENV['HOME'] || ENV['USERPROFILE']}\\vimfiles"
+ else
+ "~/.vim"
+ end, "snippets")
+ end
+
+ desc "Purge the contents of the vim snippets directory"
+ task :purge => ["snippets_dir:find"] do
+ rm_rf @snippets_dir, :verbose => true if File.directory? @snippets_dir
+ mkdir @snippets_dir, :verbose => true
+ end
end
-def run(cmd)
- puts "Executing: #{cmd}"
- system cmd
+desc "Copy the snippets directories into ~/.vim/snippets"
+task :deploy_local => ["snippets_dir:find", "snippets_dir:purge"] do
+ Dir.foreach(".") do |f|
+ cp_r f, @snippets_dir, :verbose => true if File.directory?(f) && f =~ /^[^\.]/
+ end
+ cp "support_functions.vim", @snippets_dir, :verbose => true
end
|
scrooloose/snipmate-snippets
|
1637f516ffa3acccf0d51d89591133bff3f18b0c
|
added content_tag snippet
|
diff --git a/eruby-rails/ct.snippet b/eruby-rails/ct.snippet
new file mode 100644
index 0000000..c31743e
--- /dev/null
+++ b/eruby-rails/ct.snippet
@@ -0,0 +1 @@
+<%= content_tag '${1:DIV}', ${2:content}${3:,options} -%>
|
scrooloose/snipmate-snippets
|
5cb12da5eb75e2f25d38d60bc3df253caf904f5c
|
Added rest of Shoulda's activerecord helper methods. Renamed some snippet variables.
|
diff --git a/ruby-shoulda/sbt.snippet b/ruby-shoulda/sbt.snippet
index e8097f5..90d25c8 100644
--- a/ruby-shoulda/sbt.snippet
+++ b/ruby-shoulda/sbt.snippet
@@ -1 +1 @@
-should_belong_to :${1:field}
+should_belong_to :${1:association}
diff --git a/ruby-shoulda/selal.snippet b/ruby-shoulda/selal.snippet
new file mode 100644
index 0000000..2fc48b4
--- /dev/null
+++ b/ruby-shoulda/selal.snippet
@@ -0,0 +1 @@
+should_ensure_length_at_least :${1:field}, ${2:min_length}
diff --git a/ruby-shoulda/seli.snippet b/ruby-shoulda/seli.snippet
new file mode 100644
index 0000000..8bc2bf8
--- /dev/null
+++ b/ruby-shoulda/seli.snippet
@@ -0,0 +1 @@
+should_ensure_length_is :${1:field}, ${2:length}
diff --git a/ruby-shoulda/shabtm.snippet b/ruby-shoulda/shabtm.snippet
new file mode 100644
index 0000000..03c70e2
--- /dev/null
+++ b/ruby-shoulda/shabtm.snippet
@@ -0,0 +1 @@
+should_have_and_belong_to_many :${1:association}
diff --git a/ruby-shoulda/shcm.snippet b/ruby-shoulda/shcm.snippet
new file mode 100644
index 0000000..6948aea
--- /dev/null
+++ b/ruby-shoulda/shcm.snippet
@@ -0,0 +1 @@
+should_have_class_methods :${1:method}
diff --git a/ruby-shoulda/shdc.snippet b/ruby-shoulda/shdc.snippet
new file mode 100644
index 0000000..d841d65
--- /dev/null
+++ b/ruby-shoulda/shdc.snippet
@@ -0,0 +1 @@
+should_have_db_columns :${1:field}
diff --git a/ruby-shoulda/shi.snippet b/ruby-shoulda/shi.snippet
new file mode 100644
index 0000000..d6d2b38
--- /dev/null
+++ b/ruby-shoulda/shi.snippet
@@ -0,0 +1 @@
+should_have_indices :${1:field}
diff --git a/ruby-shoulda/shim.snippet b/ruby-shoulda/shim.snippet
new file mode 100644
index 0000000..1f44252
--- /dev/null
+++ b/ruby-shoulda/shim.snippet
@@ -0,0 +1 @@
+should_have_instance_methods :${1:method}
diff --git a/ruby-shoulda/shm.snippet b/ruby-shoulda/shm.snippet
index 6cd3f8c..8c98c17 100644
--- a/ruby-shoulda/shm.snippet
+++ b/ruby-shoulda/shm.snippet
@@ -1 +1 @@
-should_have_many :${1:field}
+should_have_many :${1:association}
diff --git a/ruby-shoulda/shns.snippet b/ruby-shoulda/shns.snippet
new file mode 100644
index 0000000..a02046d
--- /dev/null
+++ b/ruby-shoulda/shns.snippet
@@ -0,0 +1 @@
+should_have_named_scope :${1:scope}, :conditions => {${2:conditions}}
diff --git a/ruby-shoulda/sho.snippet b/ruby-shoulda/sho.snippet
new file mode 100644
index 0000000..a652b4f
--- /dev/null
+++ b/ruby-shoulda/sho.snippet
@@ -0,0 +1 @@
+should_have_one :${1:association}
diff --git a/ruby-shoulda/shroa.snippet b/ruby-shoulda/shroa.snippet
new file mode 100644
index 0000000..022015d
--- /dev/null
+++ b/ruby-shoulda/shroa.snippet
@@ -0,0 +1 @@
+should_have_read_only_attributes :${1:field}
|
scrooloose/snipmate-snippets
|
7b2c33943485494d9f895c4610606f7a7c290dd6
|
Added snippets for some shoulda helper methods.
|
diff --git a/ruby-rspec/shm.snippet b/ruby-rspec/shdm.snippet
similarity index 100%
rename from ruby-rspec/shm.snippet
rename to ruby-rspec/shdm.snippet
diff --git a/ruby-shoulda/context.snippet b/ruby-shoulda/context.snippet
new file mode 100644
index 0000000..0e5a7fd
--- /dev/null
+++ b/ruby-shoulda/context.snippet
@@ -0,0 +1,5 @@
+context "${1:context}" do
+
+ ${2}
+
+end
diff --git a/ruby-shoulda/samao.snippet b/ruby-shoulda/samao.snippet
new file mode 100644
index 0000000..cfd4e59
--- /dev/null
+++ b/ruby-shoulda/samao.snippet
@@ -0,0 +1 @@
+should_allow_mass_assignment_of :${1:field}
diff --git a/ruby-shoulda/savf.snippet b/ruby-shoulda/savf.snippet
new file mode 100644
index 0000000..39cfd6f
--- /dev/null
+++ b/ruby-shoulda/savf.snippet
@@ -0,0 +1 @@
+should_allow_values_for :${1:field}, "${2:value}"
diff --git a/ruby-shoulda/sbt.snippet b/ruby-shoulda/sbt.snippet
new file mode 100644
index 0000000..e8097f5
--- /dev/null
+++ b/ruby-shoulda/sbt.snippet
@@ -0,0 +1 @@
+should_belong_to :${1:field}
diff --git a/ruby-shoulda/selir.snippet b/ruby-shoulda/selir.snippet
new file mode 100644
index 0000000..1f0bdc9
--- /dev/null
+++ b/ruby-shoulda/selir.snippet
@@ -0,0 +1 @@
+should_ensure_length_in_range :${1:field}, ${2:start}..${3:end}
diff --git a/ruby-shoulda/setup.snippet b/ruby-shoulda/setup.snippet
new file mode 100644
index 0000000..68b895c
--- /dev/null
+++ b/ruby-shoulda/setup.snippet
@@ -0,0 +1,3 @@
+setup do
+ ${1}
+end
diff --git a/ruby-shoulda/sevir.snippet b/ruby-shoulda/sevir.snippet
new file mode 100644
index 0000000..195f748
--- /dev/null
+++ b/ruby-shoulda/sevir.snippet
@@ -0,0 +1 @@
+should_ensure_value_in_range :${1:field}, ${2:start}..${3:end}
diff --git a/ruby-shoulda/shm.snippet b/ruby-shoulda/shm.snippet
new file mode 100644
index 0000000..6cd3f8c
--- /dev/null
+++ b/ruby-shoulda/shm.snippet
@@ -0,0 +1 @@
+should_have_many :${1:field}
diff --git a/ruby-shoulda/snamao.snippet b/ruby-shoulda/snamao.snippet
new file mode 100644
index 0000000..236190b
--- /dev/null
+++ b/ruby-shoulda/snamao.snippet
@@ -0,0 +1 @@
+should_not_allow_mass_assignment_of :${1:field}
diff --git a/ruby-shoulda/snavf.snippet b/ruby-shoulda/snavf.snippet
new file mode 100644
index 0000000..029c5ba
--- /dev/null
+++ b/ruby-shoulda/snavf.snippet
@@ -0,0 +1 @@
+should_not_allow_values_for :${1:field}, "${2:value}"
diff --git a/ruby-shoulda/svao.snippet b/ruby-shoulda/svao.snippet
new file mode 100644
index 0000000..8eccb88
--- /dev/null
+++ b/ruby-shoulda/svao.snippet
@@ -0,0 +1 @@
+should_validate_acceptance_of :${1:field}
diff --git a/ruby-shoulda/svno.snippet b/ruby-shoulda/svno.snippet
new file mode 100644
index 0000000..a90c1ca
--- /dev/null
+++ b/ruby-shoulda/svno.snippet
@@ -0,0 +1 @@
+should_validate_numericality_of :${1:field}
diff --git a/ruby-shoulda/svpo.snippet b/ruby-shoulda/svpo.snippet
new file mode 100644
index 0000000..13598f8
--- /dev/null
+++ b/ruby-shoulda/svpo.snippet
@@ -0,0 +1 @@
+should_validate_presence_of :${1:field}
diff --git a/ruby-shoulda/svuo.snippet b/ruby-shoulda/svuo.snippet
new file mode 100644
index 0000000..6e26912
--- /dev/null
+++ b/ruby-shoulda/svuo.snippet
@@ -0,0 +1 @@
+should_validate_uniqueness_of :${1:field}, :scoped_to => ${2:arrayofnames}
|
scrooloose/snipmate-snippets
|
53968e73e04c93a51d525e544d77554ee331bde3
|
more fixes to the method snippet
|
diff --git a/objc/m/method.snippet b/objc/m/method.snippet
index 3cf3aa6..9f7390e 100644
--- a/objc/m/method.snippet
+++ b/objc/m/method.snippet
@@ -1,4 +1,4 @@
- (${1:id}) ${2:method}
{${3}
- return nil;
+ ${4:return nil;}
}
|
scrooloose/snipmate-snippets
|
baa078d036a5fde40b71d35c26d04456c9a59f5e
|
fix bug by adding text in the snippet placeholder
|
diff --git a/eruby-rails/lt.snippet b/eruby-rails/lt.snippet
index be074d7..b6c9a5b 100644
--- a/eruby-rails/lt.snippet
+++ b/eruby-rails/lt.snippet
@@ -1 +1 @@
-<%= link_to "${1}", ${2:dest} %>
+<%= link_to "${1:name}", ${2:dest} %>
|
scrooloose/snipmate-snippets
|
e6f2fe3890355b6b82f0267c4c6b7e052ea1f602
|
fix issue with if snippet
|
diff --git a/eruby/if.snippet b/eruby/if.snippet
index c5e8f22..cc6d87c 100644
--- a/eruby/if.snippet
+++ b/eruby/if.snippet
@@ -1,3 +1,3 @@
-<% if ${1} %>
+<% if ${1:condition} %>
${2}
<% end %>
|
scrooloose/snipmate-snippets
|
dc907ab72693d8bf8653363202cd36cf0a0689d5
|
add before_filter
|
diff --git a/ruby-rails/bf.snippet b/ruby-rails/bf.snippet
new file mode 100644
index 0000000..ad25cc9
--- /dev/null
+++ b/ruby-rails/bf.snippet
@@ -0,0 +1 @@
+before_filter :${1:method}
|
scrooloose/snipmate-snippets
|
5d08c0dbebe9165faec5772830958cd5ba302a38
|
fix mccc snippet
|
diff --git a/ruby-rails/mccc.snippet b/ruby-rails/mccc.snippet
index d19d1fd..2915a37 100644
--- a/ruby-rails/mccc.snippet
+++ b/ruby-rails/mccc.snippet
@@ -1,2 +1 @@
t.column :${1:title}, :${2:string}
-mccc${3}
|
scrooloose/snipmate-snippets
|
7c59b63b6c36fa70beaabc997d1e275a1906dd72
|
changed m objc snippet
|
diff --git a/objc/M.snippet b/objc/m/class method.snippet
similarity index 100%
rename from objc/M.snippet
rename to objc/m/class method.snippet
diff --git a/objc/m/method.snippet b/objc/m/method.snippet
new file mode 100644
index 0000000..3cf3aa6
--- /dev/null
+++ b/objc/m/method.snippet
@@ -0,0 +1,4 @@
+- (${1:id}) ${2:method}
+{${3}
+ return nil;
+}
|
scrooloose/snipmate-snippets
|
7e71ed2b4f38cc104e4430192844d29e3ad11755
|
Some formattings change
|
diff --git a/haml/cs.snippet b/haml/cs.snippet
index 598904e..8dfa8d4 100644
--- a/haml/cs.snippet
+++ b/haml/cs.snippet
@@ -1 +1 @@
-=collection_select <+object+>, <+method+>, <+collection+>, <+value_method+>, <+text_method+><+, <+[options]+>, <+[html_options]+>+>
+=collection_select :${1:object}, :${2:method}, :${3:collection}, :${4:value_method}, :${5:text_method} ${6:, [options]} ${7:, [html_options]}
diff --git a/haml/ffcb.snippet b/haml/ffcb.snippet
index 2263a36..b042ca9 100644
--- a/haml/ffcb.snippet
+++ b/haml/ffcb.snippet
@@ -1 +1 @@
-= f.check_box :${1:attribute}
+=f.check_box :${1:attribute}
diff --git a/haml/ffff.snippet b/haml/ffff.snippet
index 4935bd2..fb86c2f 100644
--- a/haml/ffff.snippet
+++ b/haml/ffff.snippet
@@ -1 +1 @@
-= f.file_field :${1:attribute}
+=f.file_field :${1:attribute}
diff --git a/haml/ffhf.snippet b/haml/ffhf.snippet
index 218676e..06cd91e 100644
--- a/haml/ffhf.snippet
+++ b/haml/ffhf.snippet
@@ -1 +1 @@
-= f.hidden_field :${1:attribute}
+=f.hidden_field :${1:attribute}
diff --git a/haml/ffl.snippet b/haml/ffl.snippet
index ba820dd..c51d49e 100644
--- a/haml/ffl.snippet
+++ b/haml/ffl.snippet
@@ -1 +1 @@
-= f.label :${1:attribute}
+=f.label :${1:attribute}
diff --git a/haml/ffpf.snippet b/haml/ffpf.snippet
index 0febcd0..f200dc4 100644
--- a/haml/ffpf.snippet
+++ b/haml/ffpf.snippet
@@ -1 +1 @@
-= f.password_field :${1:attribute}
+=f.password_field :${1:attribute}
diff --git a/haml/ffrb.snippet b/haml/ffrb.snippet
index 58e1230..a6c3ffe 100644
--- a/haml/ffrb.snippet
+++ b/haml/ffrb.snippet
@@ -1 +1 @@
-= f.radio_button :${1:attribute}, :${2:tag_value}
+=f.radio_button :${1:attribute}, :${2:tag_value}
diff --git a/haml/ffs.snippet b/haml/ffs.snippet
index 91e805b..8489ac4 100644
--- a/haml/ffs.snippet
+++ b/haml/ffs.snippet
@@ -1 +1 @@
-= f.submit "<+Submit+>"<+, :disable_with => '<+Submitting+>'+>
+=f.submit "<+Submit+>"<+, :disable_with => '<+Submitting+>'+>
diff --git a/haml/ffta.snippet b/haml/ffta.snippet
index 5dadea5..df89124 100644
--- a/haml/ffta.snippet
+++ b/haml/ffta.snippet
@@ -1 +1 @@
-= f.text_area :${1:attribute}
+=f.text_area :${1:attribute}
diff --git a/haml/fftf.snippet b/haml/fftf.snippet
index b85e11c..80b4bd9 100644
--- a/haml/fftf.snippet
+++ b/haml/fftf.snippet
@@ -1 +1 @@
-= f.text_field :${1:attribute}
+=f.text_field :${1:attribute}
diff --git a/haml/if.snippet b/haml/if.snippet
index 9462ff5..d1e38b7 100644
--- a/haml/if.snippet
+++ b/haml/if.snippet
@@ -1,2 +1,2 @@
-- if ${1}
+-if ${1}
${2}
diff --git a/haml/ife.snippet b/haml/ife.snippet
index fe0a5e8..b8d12d8 100644
--- a/haml/ife.snippet
+++ b/haml/ife.snippet
@@ -1,4 +1,4 @@
-- if ${1}
+-if ${1}
${2}
-- else
+-else
diff --git a/haml/it.snippet b/haml/it.snippet
index 41ad078..9e15a59 100644
--- a/haml/it.snippet
+++ b/haml/it.snippet
@@ -1 +1 @@
-= image_tag "${1}"
+=image_tag "${1}"
diff --git a/haml/jit.snippet b/haml/jit.snippet
index 3ad3db5..af6edd2 100644
--- a/haml/jit.snippet
+++ b/haml/jit.snippet
@@ -1 +1 @@
-= javascript_include_tag <+:all+><+, :cache => <+true+>+>
+=javascript_include_tag <+:all+><+, :cache => <+true+>+>
diff --git a/haml/jsit.snippet b/haml/jsit.snippet
index d5e8f55..ea4d2fd 100644
--- a/haml/jsit.snippet
+++ b/haml/jsit.snippet
@@ -1 +1 @@
-= javascript_include_tag "${1}"
+=javascript_include_tag "${1}"
diff --git a/haml/lia.snippet b/haml/lia.snippet
index a074da2..9fa23df 100644
--- a/haml/lia.snippet
+++ b/haml/lia.snippet
@@ -1 +1 @@
-= link_to "${1:link text}", :action => "${2:index}"
+=link_to "${1:link text}", :action => "${2:index}"
diff --git a/haml/liai.snippet b/haml/liai.snippet
index 48c8d7b..bd4f851 100644
--- a/haml/liai.snippet
+++ b/haml/liai.snippet
@@ -1 +1 @@
-= link_to "<+link text+>", :action => "<+edit+>", :id => <+@<+item+>+>
+=link_to "<+link text+>", :action => "<+edit+>", :id => <+@<+item+>+>
diff --git a/haml/lic.snippet b/haml/lic.snippet
index dee0b49..9c64226 100644
--- a/haml/lic.snippet
+++ b/haml/lic.snippet
@@ -1 +1 @@
-= link_to "${1:link text}", :controller => "${2:items}"
+=link_to "${1:link text}", :controller => "${2:items}"
diff --git a/haml/lica.snippet b/haml/lica.snippet
index 2f7ea3a..67e9bc0 100644
--- a/haml/lica.snippet
+++ b/haml/lica.snippet
@@ -1 +1 @@
-= link_to "${1:link text}", :controller => "${2:items}", :action => "${3:index}"
+=link_to "${1:link text}", :controller => "${2:items}", :action => "${3:index}"
diff --git a/haml/licai.snippet b/haml/licai.snippet
index 99a4300..58b6583 100644
--- a/haml/licai.snippet
+++ b/haml/licai.snippet
@@ -1 +1 @@
-= link_to "<+link text+>", :controller => "<+items+>", :action => "<+edit+>", :id => <+@<+item+>+>
+=link_to "<+link text+>", :controller => "<+items+>", :action => "<+edit+>", :id => <+@<+item+>+>
diff --git a/haml/lim.snippet b/haml/lim.snippet
index acc065f..25821e4 100644
--- a/haml/lim.snippet
+++ b/haml/lim.snippet
@@ -1 +1 @@
-= link_to <+model+>.<+name+>, <+<+model+>_path(<+model+>)+>
+=link_to <+model+>.<+name+>, <+<+model+>_path(<+model+>)+>
diff --git a/haml/linp.snippet b/haml/linp.snippet
index 6e5bc33..4fdfab6 100644
--- a/haml/linp.snippet
+++ b/haml/linp.snippet
@@ -1 +1 @@
-= link_to <+"<+link text+>"+>, <+<+parent+>_<+child+>_path(<+@+><+parent+>, <+@+><+child+>)+>
+=link_to <+"<+link text+>"+>, <+<+parent+>_<+child+>_path(<+@+><+parent+>, <+@+><+child+>)+>
diff --git a/haml/linpp.snippet b/haml/linpp.snippet
index 2116280..0f98772 100644
--- a/haml/linpp.snippet
+++ b/haml/linpp.snippet
@@ -1 +1 @@
-= link_to <+"<+link text+>"+>, <+<+parent+>_<+child+>_path(<+@+><+parent+>)+>
+=link_to <+"<+link text+>"+>, <+<+parent+>_<+child+>_path(<+@+><+parent+>)+>
diff --git a/haml/lip.snippet b/haml/lip.snippet
index ba30c32..d882c5d 100644
--- a/haml/lip.snippet
+++ b/haml/lip.snippet
@@ -1 +1 @@
-= link_to <+"<+link text+>"+>, <+<+model+>_path(<+@+><+instance+>)+>
+=link_to <+"<+link text+>"+>, <+<+model+>_path(<+@+><+instance+>)+>
diff --git a/haml/lipp.snippet b/haml/lipp.snippet
index 0d383bf..7484b24 100644
--- a/haml/lipp.snippet
+++ b/haml/lipp.snippet
@@ -1 +1 @@
-= link_to <+"<+link text+>"+>, <+<+model+>s_path+>
+=link_to <+"<+link text+>"+>, <+<+model+>s_path+>
diff --git a/haml/lt.snippet b/haml/lt.snippet
index ad66392..d66cd76 100644
--- a/haml/lt.snippet
+++ b/haml/lt.snippet
@@ -1 +1 @@
-= link_to "${1}", ${2:dest}
+=link_to "${1}", ${2:dest}
diff --git a/haml/ofcfs.snippet b/haml/ofcfs.snippet
index 51f7420..7d60712 100644
--- a/haml/ofcfs.snippet
+++ b/haml/ofcfs.snippet
@@ -1 +1 @@
-= options_from_collection_for_select <+collection+>, <+value_method+>, <+text_method+><+, <+[selected_value]+>+>
+=options_from_collection_for_select <+collection+>, <+value_method+>, <+text_method+><+, <+[selected_value]+>+>
diff --git a/haml/rf.snippet b/haml/rf.snippet
index e5476a0..5758eb4 100644
--- a/haml/rf.snippet
+++ b/haml/rf.snippet
@@ -1 +1 @@
-= render :file => "${1:file}"${2}
+=render :file => "${1:file}"${2}
diff --git a/haml/rp.snippet b/haml/rp.snippet
index 28e5c18..038225e 100644
--- a/haml/rp.snippet
+++ b/haml/rp.snippet
@@ -1 +1 @@
-= render :partial => "${1:file}"${2}
+=render :partial => "${1:file}"${2}
diff --git a/haml/rt.snippet b/haml/rt.snippet
index f7960bd..5d3d2ff 100644
--- a/haml/rt.snippet
+++ b/haml/rt.snippet
@@ -1 +1 @@
-= render :template => "${1:file}"${2}
+=render :template => "${1:file}"${2}
diff --git a/haml/slt.snippet b/haml/slt.snippet
index d5c89ff..294405a 100644
--- a/haml/slt.snippet
+++ b/haml/slt.snippet
@@ -1 +1 @@
-= stylesheet_link_tag <+:all+><+, :cache => <+true+>+>
+=stylesheet_link_tag <+:all+><+, :cache => <+true+>+>
diff --git a/haml/sslt.snippet b/haml/sslt.snippet
index 066a170..1597d2f 100644
--- a/haml/sslt.snippet
+++ b/haml/sslt.snippet
@@ -1 +1 @@
-= stylesheet_link_tag "${1}"
+=stylesheet_link_tag "${1}"
diff --git a/haml/st.snippet b/haml/st.snippet
index 1f927ac..60a889e 100644
--- a/haml/st.snippet
+++ b/haml/st.snippet
@@ -1 +1 @@
-= submit_tag "<+Save changes+>"<+, :id => "<+submit+>"+><+, :name => "<+submit+>"+><+, :class => "<+form_name+>"+><+, :disabled => <+false+>+><+, :disable_with => "<+Please wait+>"+>
+=submit_tag "<+Save changes+>"<+, :id => "<+submit+>"+><+, :name => "<+submit+>"+><+, :class => "<+form_name+>"+><+, :disabled => <+false+>+><+, :disable_with => "<+Please wait+>"+>
diff --git a/haml/unless.snippet b/haml/unless.snippet
index a788eb9..2e52103 100644
--- a/haml/unless.snippet
+++ b/haml/unless.snippet
@@ -1,3 +1,3 @@
-- unless ${1}
+-unless ${1}
${2}
diff --git a/haml/unlesse.snippet b/haml/unlesse.snippet
index fe0a5e8..b8d12d8 100644
--- a/haml/unlesse.snippet
+++ b/haml/unlesse.snippet
@@ -1,4 +1,4 @@
-- if ${1}
+-if ${1}
${2}
-- else
+-else
|
scrooloose/snipmate-snippets
|
fdc40c3a974c4b4d9fb874df2704563687bae660
|
Fix for ffl
|
diff --git a/haml/ffl.snippet b/haml/ffl.snippet
index 38f90f7..ba820dd 100644
--- a/haml/ffl.snippet
+++ b/haml/ffl.snippet
@@ -1 +1 @@
-= f.label :<+attribute+><+, '<+attribute+>'+>
+= f.label :${1:attribute}
|
scrooloose/snipmate-snippets
|
e5c0b5c4eb6493c4c30181700aa24f8726b9dec8
|
Translate snippets from eruby to haml
|
diff --git a/haml/if.snippet b/haml/if.snippet
new file mode 100644
index 0000000..9462ff5
--- /dev/null
+++ b/haml/if.snippet
@@ -0,0 +1,2 @@
+- if ${1}
+ ${2}
diff --git a/haml/ife.snippet b/haml/ife.snippet
new file mode 100644
index 0000000..fe0a5e8
--- /dev/null
+++ b/haml/ife.snippet
@@ -0,0 +1,4 @@
+- if ${1}
+ ${2}
+- else
+
diff --git a/haml/unless.snippet b/haml/unless.snippet
new file mode 100644
index 0000000..a788eb9
--- /dev/null
+++ b/haml/unless.snippet
@@ -0,0 +1,3 @@
+- unless ${1}
+ ${2}
+
diff --git a/haml/unlesse.snippet b/haml/unlesse.snippet
new file mode 100644
index 0000000..fe0a5e8
--- /dev/null
+++ b/haml/unlesse.snippet
@@ -0,0 +1,4 @@
+- if ${1}
+ ${2}
+- else
+
|
scrooloose/snipmate-snippets
|
ccf100d78a04fd1fc7d8c0c6479ce8a96fa5073f
|
Add haml snippets (translation from eruby-rails)
|
diff --git a/Rakefile b/Rakefile
index 6c705ca..a602b4d 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,30 +1,31 @@
desc "Copy the snippets directories into ~/.vim/snippets"
task :deploy_local do
run "rm -rf ~/.vim/snippets"
run "mkdir ~/.vim/snippets"
run "cp -r _ ~/.vim/snippets/"
run "cp -r ant ~/.vim/snippets/"
run "cp -r c ~/.vim/snippets/"
run "cp -r eruby ~/.vim/snippets/"
run "cp -r eruby-rails ~/.vim/snippets/"
+ run "cp -r haml ~/.vim/snippets/"
run "cp -r html ~/.vim/snippets/"
run "cp -r java ~/.vim/snippets/"
run "cp -r javascript ~/.vim/snippets/"
run "cp -r javascript-jquery ~/.vim/snippets/"
run "cp -r objc ~/.vim/snippets/"
run "cp -r php ~/.vim/snippets/"
run "cp -r python ~/.vim/snippets/"
run "cp -r ruby ~/.vim/snippets/"
run "cp -r ruby-factorygirl ~/.vim/snippets/"
run "cp -r ruby-rails ~/.vim/snippets/"
run "cp -r ruby-rails-rjs ~/.vim/snippets/"
run "cp -r ruby-rspec ~/.vim/snippets/"
run "cp -r vim ~/.vim/snippets/"
run "cp -r zend ~/.vim/snippets/"
run "cp support_functions.vim ~/.vim/snippets/"
end
def run(cmd)
puts "Executing: #{cmd}"
system cmd
end
diff --git a/haml/conf.snippet b/haml/conf.snippet
new file mode 100644
index 0000000..a4723cd
--- /dev/null
+++ b/haml/conf.snippet
@@ -0,0 +1,3 @@
+-content_for :${1:yield_label_in_layout} do
+ ${2}
+
diff --git a/haml/cs.snippet b/haml/cs.snippet
new file mode 100644
index 0000000..598904e
--- /dev/null
+++ b/haml/cs.snippet
@@ -0,0 +1 @@
+=collection_select <+object+>, <+method+>, <+collection+>, <+value_method+>, <+text_method+><+, <+[options]+>, <+[html_options]+>+>
diff --git a/haml/ff.snippet b/haml/ff.snippet
new file mode 100644
index 0000000..aeb7fbe
--- /dev/null
+++ b/haml/ff.snippet
@@ -0,0 +1,2 @@
+-form_for @${1:model} do |f|
+ ${2}
diff --git a/haml/ffcb.snippet b/haml/ffcb.snippet
new file mode 100644
index 0000000..2263a36
--- /dev/null
+++ b/haml/ffcb.snippet
@@ -0,0 +1 @@
+= f.check_box :${1:attribute}
diff --git a/haml/ffe.snippet b/haml/ffe.snippet
new file mode 100644
index 0000000..633bca1
--- /dev/null
+++ b/haml/ffe.snippet
@@ -0,0 +1,4 @@
+=error_messages_for :${1:model}
+
+-form_for @${2:model} do |f|
+ ${3}
diff --git a/haml/ffff.snippet b/haml/ffff.snippet
new file mode 100644
index 0000000..4935bd2
--- /dev/null
+++ b/haml/ffff.snippet
@@ -0,0 +1 @@
+= f.file_field :${1:attribute}
diff --git a/haml/ffhf.snippet b/haml/ffhf.snippet
new file mode 100644
index 0000000..218676e
--- /dev/null
+++ b/haml/ffhf.snippet
@@ -0,0 +1 @@
+= f.hidden_field :${1:attribute}
diff --git a/haml/ffl.snippet b/haml/ffl.snippet
new file mode 100644
index 0000000..38f90f7
--- /dev/null
+++ b/haml/ffl.snippet
@@ -0,0 +1 @@
+= f.label :<+attribute+><+, '<+attribute+>'+>
diff --git a/haml/ffpf.snippet b/haml/ffpf.snippet
new file mode 100644
index 0000000..0febcd0
--- /dev/null
+++ b/haml/ffpf.snippet
@@ -0,0 +1 @@
+= f.password_field :${1:attribute}
diff --git a/haml/ffrb.snippet b/haml/ffrb.snippet
new file mode 100644
index 0000000..58e1230
--- /dev/null
+++ b/haml/ffrb.snippet
@@ -0,0 +1 @@
+= f.radio_button :${1:attribute}, :${2:tag_value}
diff --git a/haml/ffs.snippet b/haml/ffs.snippet
new file mode 100644
index 0000000..91e805b
--- /dev/null
+++ b/haml/ffs.snippet
@@ -0,0 +1 @@
+= f.submit "<+Submit+>"<+, :disable_with => '<+Submitting+>'+>
diff --git a/haml/ffta.snippet b/haml/ffta.snippet
new file mode 100644
index 0000000..5dadea5
--- /dev/null
+++ b/haml/ffta.snippet
@@ -0,0 +1 @@
+= f.text_area :${1:attribute}
diff --git a/haml/fftf.snippet b/haml/fftf.snippet
new file mode 100644
index 0000000..b85e11c
--- /dev/null
+++ b/haml/fftf.snippet
@@ -0,0 +1 @@
+= f.text_field :${1:attribute}
diff --git a/haml/fields.snippet b/haml/fields.snippet
new file mode 100644
index 0000000..e9c9b20
--- /dev/null
+++ b/haml/fields.snippet
@@ -0,0 +1,2 @@
+-fields_for :${1:model}, @$1 do |${2:f}|
+ ${3}
diff --git a/haml/for.snippet b/haml/for.snippet
new file mode 100644
index 0000000..40de648
--- /dev/null
+++ b/haml/for.snippet
@@ -0,0 +1,6 @@
+-if !${1:list}.blank?
+ -for ${2:item} in $1
+ ${3}
+-else
+ ${4}
+
diff --git a/haml/ft.snippet b/haml/ft.snippet
new file mode 100644
index 0000000..5a051d9
--- /dev/null
+++ b/haml/ft.snippet
@@ -0,0 +1,2 @@
+-form_tag(<+:action => "<+update+>"+><+, {:<+class+> => "<+form+>"}+>) do
+ <++>
diff --git a/haml/it.snippet b/haml/it.snippet
new file mode 100644
index 0000000..41ad078
--- /dev/null
+++ b/haml/it.snippet
@@ -0,0 +1 @@
+= image_tag "${1}"
diff --git a/haml/jit.snippet b/haml/jit.snippet
new file mode 100644
index 0000000..3ad3db5
--- /dev/null
+++ b/haml/jit.snippet
@@ -0,0 +1 @@
+= javascript_include_tag <+:all+><+, :cache => <+true+>+>
diff --git a/haml/jsit.snippet b/haml/jsit.snippet
new file mode 100644
index 0000000..d5e8f55
--- /dev/null
+++ b/haml/jsit.snippet
@@ -0,0 +1 @@
+= javascript_include_tag "${1}"
diff --git a/haml/lia.snippet b/haml/lia.snippet
new file mode 100644
index 0000000..a074da2
--- /dev/null
+++ b/haml/lia.snippet
@@ -0,0 +1 @@
+= link_to "${1:link text}", :action => "${2:index}"
diff --git a/haml/liai.snippet b/haml/liai.snippet
new file mode 100644
index 0000000..48c8d7b
--- /dev/null
+++ b/haml/liai.snippet
@@ -0,0 +1 @@
+= link_to "<+link text+>", :action => "<+edit+>", :id => <+@<+item+>+>
diff --git a/haml/lic.snippet b/haml/lic.snippet
new file mode 100644
index 0000000..dee0b49
--- /dev/null
+++ b/haml/lic.snippet
@@ -0,0 +1 @@
+= link_to "${1:link text}", :controller => "${2:items}"
diff --git a/haml/lica.snippet b/haml/lica.snippet
new file mode 100644
index 0000000..2f7ea3a
--- /dev/null
+++ b/haml/lica.snippet
@@ -0,0 +1 @@
+= link_to "${1:link text}", :controller => "${2:items}", :action => "${3:index}"
diff --git a/haml/licai.snippet b/haml/licai.snippet
new file mode 100644
index 0000000..99a4300
--- /dev/null
+++ b/haml/licai.snippet
@@ -0,0 +1 @@
+= link_to "<+link text+>", :controller => "<+items+>", :action => "<+edit+>", :id => <+@<+item+>+>
diff --git a/haml/lim.snippet b/haml/lim.snippet
new file mode 100644
index 0000000..acc065f
--- /dev/null
+++ b/haml/lim.snippet
@@ -0,0 +1 @@
+= link_to <+model+>.<+name+>, <+<+model+>_path(<+model+>)+>
diff --git a/haml/linp.snippet b/haml/linp.snippet
new file mode 100644
index 0000000..6e5bc33
--- /dev/null
+++ b/haml/linp.snippet
@@ -0,0 +1 @@
+= link_to <+"<+link text+>"+>, <+<+parent+>_<+child+>_path(<+@+><+parent+>, <+@+><+child+>)+>
diff --git a/haml/linpp.snippet b/haml/linpp.snippet
new file mode 100644
index 0000000..2116280
--- /dev/null
+++ b/haml/linpp.snippet
@@ -0,0 +1 @@
+= link_to <+"<+link text+>"+>, <+<+parent+>_<+child+>_path(<+@+><+parent+>)+>
diff --git a/haml/lip.snippet b/haml/lip.snippet
new file mode 100644
index 0000000..ba30c32
--- /dev/null
+++ b/haml/lip.snippet
@@ -0,0 +1 @@
+= link_to <+"<+link text+>"+>, <+<+model+>_path(<+@+><+instance+>)+>
diff --git a/haml/lipp.snippet b/haml/lipp.snippet
new file mode 100644
index 0000000..0d383bf
--- /dev/null
+++ b/haml/lipp.snippet
@@ -0,0 +1 @@
+= link_to <+"<+link text+>"+>, <+<+model+>s_path+>
diff --git a/haml/lt.snippet b/haml/lt.snippet
new file mode 100644
index 0000000..ad66392
--- /dev/null
+++ b/haml/lt.snippet
@@ -0,0 +1 @@
+= link_to "${1}", ${2:dest}
diff --git a/haml/ofcfs.snippet b/haml/ofcfs.snippet
new file mode 100644
index 0000000..51f7420
--- /dev/null
+++ b/haml/ofcfs.snippet
@@ -0,0 +1 @@
+= options_from_collection_for_select <+collection+>, <+value_method+>, <+text_method+><+, <+[selected_value]+>+>
diff --git a/haml/rf.snippet b/haml/rf.snippet
new file mode 100644
index 0000000..e5476a0
--- /dev/null
+++ b/haml/rf.snippet
@@ -0,0 +1 @@
+= render :file => "${1:file}"${2}
diff --git a/haml/rp.snippet b/haml/rp.snippet
new file mode 100644
index 0000000..28e5c18
--- /dev/null
+++ b/haml/rp.snippet
@@ -0,0 +1 @@
+= render :partial => "${1:file}"${2}
diff --git a/haml/rt.snippet b/haml/rt.snippet
new file mode 100644
index 0000000..f7960bd
--- /dev/null
+++ b/haml/rt.snippet
@@ -0,0 +1 @@
+= render :template => "${1:file}"${2}
diff --git a/haml/slt.snippet b/haml/slt.snippet
new file mode 100644
index 0000000..d5c89ff
--- /dev/null
+++ b/haml/slt.snippet
@@ -0,0 +1 @@
+= stylesheet_link_tag <+:all+><+, :cache => <+true+>+>
diff --git a/haml/sslt.snippet b/haml/sslt.snippet
new file mode 100644
index 0000000..066a170
--- /dev/null
+++ b/haml/sslt.snippet
@@ -0,0 +1 @@
+= stylesheet_link_tag "${1}"
diff --git a/haml/st.snippet b/haml/st.snippet
new file mode 100644
index 0000000..1f927ac
--- /dev/null
+++ b/haml/st.snippet
@@ -0,0 +1 @@
+= submit_tag "<+Save changes+>"<+, :id => "<+submit+>"+><+, :name => "<+submit+>"+><+, :class => "<+form_name+>"+><+, :disabled => <+false+>+><+, :disable_with => "<+Please wait+>"+>
|
scrooloose/snipmate-snippets
|
78a4cf659de88a22a6eafdc618dfdc753b48042a
|
fix some rspec-ruby indenting
|
diff --git a/ruby-rspec/desrc.snippet b/ruby-rspec/desrc.snippet
index 8ff6dc7..a9c8ac2 100644
--- a/ruby-rspec/desrc.snippet
+++ b/ruby-rspec/desrc.snippet
@@ -1,3 +1,3 @@
describe ${1:controller}, "${2:GET|POST|PUT|DELETE} ${3:/some/path}${4}" do
- ${5}
+ ${5}
end
diff --git a/ruby-rspec/it.snippet b/ruby-rspec/it.snippet
index 9317a67..5f3900b 100644
--- a/ruby-rspec/it.snippet
+++ b/ruby-rspec/it.snippet
@@ -1,3 +1,3 @@
it '${1}' do
- ${2}
+ ${2}
end
diff --git a/ruby-rspec/mat.snippet b/ruby-rspec/mat.snippet
index 983fcad..2f04771 100644
--- a/ruby-rspec/mat.snippet
+++ b/ruby-rspec/mat.snippet
@@ -1,24 +1,24 @@
class ${1:ReverseTo}
- def initialize(${2:param})
- @$2 = $2
- end
+ def initialize(${2:param})
+ @$2 = $2
+ end
- def matches?(actual)
- @actual = actual
- # Satisfy expectation here. Return false or raise an error if it's not met.
- ${3:@actual.reverse.should == @$2}
- true
- end
+ def matches?(actual)
+ @actual = actual
+ # Satisfy expectation here. Return false or raise an error if it's not met.
+ ${3:@actual.reverse.should == @$2}
+ true
+ end
- def failure_message
- "expected #{@actual.inspect} to ${4} #{@$2.inspect}, but it didn't"
- end
+ def failure_message
+ "expected #{@actual.inspect} to ${4} #{@$2.inspect}, but it didn't"
+ end
- def negative_failure_message
- "expected #{@actual.inspect} not to ${5} #{@$2.inspect}, but it did"
- end
+ def negative_failure_message
+ "expected #{@actual.inspect} not to ${5} #{@$2.inspect}, but it did"
+ end
end
def ${6:reverse_to}(${7:expected})
- ${8}.new($7)
+ ${8}.new($7)
end
|
scrooloose/snipmate-snippets
|
5f0621fbc682a1ae36edba5e200ff39f62dcb2c0
|
convert some ruby-rspec snippets from nerd snippets to snipmate
|
diff --git a/ruby-rspec/its.snippet b/ruby-rspec/its.snippet
index c22c0d4..963f404 100644
--- a/ruby-rspec/its.snippet
+++ b/ruby-rspec/its.snippet
@@ -1 +1 @@
-it "should <+do something+>"<+ do<++>+>
+it "should ${1:do something}" do${2}
diff --git a/ruby-rspec/shc.snippet b/ruby-rspec/shc.snippet
index 95cc1f4..16206fa 100644
--- a/ruby-rspec/shc.snippet
+++ b/ruby-rspec/shc.snippet
@@ -1,3 +1,3 @@
lambda do
- <++>
-end.should change(<+target+>, :<+method+>)<+<+.from(<+old_value+>).to(<+new_value+>)+><+.by(<+change+>)+>+>
+ ${1}
+end.should change(${2:target}, :${3:method}).from(${4:old_value}).to(${5:new_value}).by(${6:change})
diff --git a/ruby-rspec/shnp.snippet b/ruby-rspec/shnp.snippet
index ed10e79..9f1298b 100644
--- a/ruby-rspec/shnp.snippet
+++ b/ruby-rspec/shnp.snippet
@@ -1,2 +1 @@
-<+target+>.should_not <+be_<+predicate+>+> <++>
-<++>
+${1:target}.should_not be_${2:predicate}
diff --git a/ruby-rspec/shp.snippet b/ruby-rspec/shp.snippet
index 8eabbb9..9267b61 100644
--- a/ruby-rspec/shp.snippet
+++ b/ruby-rspec/shp.snippet
@@ -1,2 +1 @@
-<+target+>.should <+be_<+predicate+>+> <++>
-<++>
\ No newline at end of file
+${1:target}.should be_${2:predicate}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.