diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/Makefile | 8 | ||||
| -rw-r--r-- | core/array.c | 2 | ||||
| -rw-r--r-- | core/buffer.c | 35 | ||||
| -rw-r--r-- | core/map.c | 2 | ||||
| -rw-r--r-- | core/tap.h | 42 | ||||
| -rw-r--r-- | core/text.c | 14 |
6 files changed, 77 insertions, 26 deletions
diff --git a/core/Makefile b/core/Makefile index d3d0fdd..b2b0406 100644 --- a/core/Makefile +++ b/core/Makefile @@ -1,9 +1,10 @@ -include ../../config.mk +ALL = text buffer map array SRC = $(wildcard ccan/*/*.c) CFLAGS += -I. -I../.. -test: text buffer map array +test: $(ALL) @./text @./buffer @./map @@ -35,6 +36,9 @@ debug: clean coverage: clean $(MAKE) CFLAGS_EXTRA='--coverage' +tis: clean + $(MAKE) CC="tis-interpreter.sh --cc" CFLAGS='"${CFLAGS} ${CFLAGS_STD} -DTIS_INTERPRETER=1"' CFLAGS_STD='' LDFLAGS='#' $(ALL) + clean: @echo cleaning @rm -f text @@ -43,4 +47,4 @@ clean: @rm -f array @rm -f *.gcov *.gcda *.gcno -.PHONY: clean debug coverage +.PHONY: clean debug coverage tis diff --git a/core/array.c b/core/array.c index e6c0265..db95541 100644 --- a/core/array.c +++ b/core/array.c @@ -1,10 +1,10 @@ -#include <ccan/tap/tap.h> #include <stdlib.h> #include <stddef.h> #include <stdbool.h> #include <string.h> #include <stdio.h> #include <errno.h> +#include "tap.h" #include "array.h" #include "../../util.h" diff --git a/core/buffer.c b/core/buffer.c index 14ad667..ab8488a 100644 --- a/core/buffer.c +++ b/core/buffer.c @@ -1,8 +1,8 @@ -#include <ccan/tap/tap.h> #include <stddef.h> #include <stdbool.h> #include <string.h> #include <stdio.h> +#include "tap.h" #include "buffer.h" static bool compare(Buffer *buf, const char *data, size_t len) { @@ -58,24 +58,27 @@ int main(int argc, char *argv[]) { buffer_clear(&buf); ok(buf.data && buffer_length(&buf) == 0 && buffer_capacity(&buf) == cap, "Clear"); - ok(buffer_printf(&buf, "Test: %d\n", 42) && compare0(&buf, "Test: 42\n"), "Set formatted"); - ok(buffer_printf(&buf, "%d\n", 42) && compare0(&buf, "42\n"), "Set formatted overwrite"); - buffer_clear(&buf); + skip_if(TIS_INTERPRETER, 1, "vsnprintf not supported") { - ok(buffer_printf(&buf, "") && compare0(&buf, ""), "Set formatted empty string"); - buffer_clear(&buf); + ok(buffer_printf(&buf, "Test: %d\n", 42) && compare0(&buf, "Test: 42\n"), "Set formatted"); + ok(buffer_printf(&buf, "%d\n", 42) && compare0(&buf, "42\n"), "Set formatted overwrite"); + buffer_clear(&buf); - bool append = true; - for (int i = 1; i <= 10; i++) - append &= buffer_appendf(&buf, "%d", i); - ok(append && compare0(&buf, "12345678910"), "Append formatted"); - buffer_clear(&buf); + ok(buffer_printf(&buf, "") && compare0(&buf, ""), "Set formatted empty string"); + buffer_clear(&buf); - append = true; - for (int i = 1; i <= 10; i++) - append &= buffer_appendf(&buf, ""); - ok(append && compare0(&buf, ""), "Append formatted empty string"); - buffer_clear(&buf); + bool append = true; + for (int i = 1; i <= 10; i++) + append &= buffer_appendf(&buf, "%d", i); + ok(append && compare0(&buf, "12345678910"), "Append formatted"); + buffer_clear(&buf); + + append = true; + for (int i = 1; i <= 10; i++) + append &= buffer_appendf(&buf, ""); + ok(append && compare0(&buf, ""), "Append formatted empty string"); + buffer_clear(&buf); + } buffer_release(&buf); @@ -1,9 +1,9 @@ -#include <ccan/tap/tap.h> #include <stddef.h> #include <stdbool.h> #include <string.h> #include <stdio.h> #include <errno.h> +#include "tap.h" #include "map.h" static bool get(Map *map, const char *key, const void *data) { diff --git a/core/tap.h b/core/tap.h new file mode 100644 index 0000000..98f5a35 --- /dev/null +++ b/core/tap.h @@ -0,0 +1,42 @@ +#ifndef TAP_H +#define TAP_H + +#ifdef TIS_INTERPRETER +static int failures = 0; +static int test_count = 0; +static void plan_no_plan(void) { } + +static int exit_status() { + if (failures > 255) + failures = 255; + return failures; +} + +#define ok(e, ...) do { \ + bool _e = (e); \ + printf("%sok %d - ", _e ? "" : "not ", ++test_count); \ + printf(__VA_ARGS__); \ + if (!_e) { \ + failures++; \ + printf(" Failed test (%s:%s() at line %d)\n", __FILE__, __func__, __LINE__); \ + } \ +} while (0) + +#define skip_if(cond, n, ...) \ + if (cond) skip((n), __VA_ARGS__); \ + else + +#define skip(n, ...) do { \ + int _n = (n); \ + while (_n--) { \ + printf("ok %d # skip ", ++test_count); \ + printf(__VA_ARGS__); \ + } \ +} while (0) + +#else +#include <ccan/tap/tap.h> +#define TIS_INTERPRETER 0 +#endif + +#endif diff --git a/core/text.c b/core/text.c index 01aa322..8145394 100644 --- a/core/text.c +++ b/core/text.c @@ -1,10 +1,10 @@ -#include <ccan/tap/tap.h> #include <stddef.h> #include <stdbool.h> #include <string.h> #include <errno.h> #include <stdio.h> #include <unistd.h> +#include "tap.h" #include "text.h" #include "text-util.h" @@ -32,12 +32,14 @@ int main(int argc, char *argv[]) { plan_no_plan(); - txt = text_load("/"); - ok(txt == NULL && errno == EISDIR, "Opening directory"); + skip_if(TIS_INTERPRETER, 2, "I/O related") { + txt = text_load("/"); + ok(txt == NULL && errno == EISDIR, "Opening directory"); - if (access("/etc/shadow", F_OK) == 0) { - txt = text_load("/etc/shadow"); - ok(txt == NULL && errno == EACCES, "Opening file without sufficient permissions"); + if (access("/etc/shadow", F_OK) == 0) { + txt = text_load("/etc/shadow"); + ok(txt == NULL && errno == EACCES, "Opening file without sufficient permissions"); + } } txt = text_load(NULL); |
