aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-10-05 16:34:19 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-12-22 11:56:35 +0100
commit4efd8084ecf47132ba51577ee3f79d2ed2637b44 (patch)
tree09f6c30c079be1de57af19c450dd6cb5fa4ff036
parentcca3d303023d53b5d0af96751f379b2d0e28cd18 (diff)
downloadvis-4efd8084ecf47132ba51577ee3f79d2ed2637b44.tar.gz
vis-4efd8084ecf47132ba51577ee3f79d2ed2637b44.tar.xz
test/core: tweak tests to work with tis-interpreter
$ tis-inertpreter.sh --cc "-I. -I../.." text.c ../../text.c or more conveniently $ make tis
-rw-r--r--core/Makefile8
-rw-r--r--core/array.c2
-rw-r--r--core/buffer.c35
-rw-r--r--core/map.c2
-rw-r--r--core/tap.h42
-rw-r--r--core/text.c14
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);
diff --git a/core/map.c b/core/map.c
index 5fdc2eb..bcc9fb1 100644
--- a/core/map.c
+++ b/core/map.c
@@ -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);