diff options
author | Emilio Cobos Álvarez <me@emiliocobos.me> | 2016-04-16 03:39:00 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <me@emiliocobos.me> | 2016-04-16 03:39:25 +0200 |
commit | 8ad2e2d06ba9a9067bc87c1a0fdc9ec544bcac99 (patch) | |
tree | 55da1f08c4c5d2a37a04168cdbc96971a811b104 | |
parent | 3cf04d17d85b5766d7c120a4ee6ce97598b38ec7 (diff) |
tests: Add a simple test suite that checks that every test is compiling
and passing tests correctly
Ideally it should be done in rust, but I was too lazy right now.
Should be easy to port.
-rw-r--r-- | Makefile | 34 | ||||
-rwxr-xr-x | tests/tools/run-bindgen.py | 36 |
2 files changed, 70 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..be0441c9 --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ + +TEST_HEADERS := $(wildcard tests/headers/*.h) $(wildcard tests/headers/*.hpp) + +TEST_TARGETS := $(TEST_HEADERS:.h=.rs) +TEST_TARGETS := $(TEST_TARGETS:.hpp=.rs) +TEST_TARGETS := $(patsubst tests/headers/%, tests/expectations/%, $(TEST_TARGETS)) + +BINDGEN := ./target/debug/bindgen + +.PHONY: $(BINDGEN) +$(BINDGEN): + cargo build + +.PHONY: test +test: regen-tests + @echo > /dev/null + + +.PHONY: regen-tests +regen-tests: $(BINDGEN) clean-tests $(TEST_TARGETS) + @echo > /dev/null + +.PHONY: clean-tests +clean-tests: + $(RM) $(TEST_TARGETS) + +# TODO: Add options to add flags and whatnot +tests/expectations/%.rs: tests/headers/%.h + @mkdir -p $(dir $@) + ./tests/tools/run-bindgen.py $(BINDGEN) $< $@ + +tests/expectations/%.rs: tests/headers/%.hpp + @mkdir -p $(dir $@) + ./tests/tools/run-bindgen.py $(BINDGEN) $< $@ diff --git a/tests/tools/run-bindgen.py b/tests/tools/run-bindgen.py new file mode 100755 index 00000000..e654fef3 --- /dev/null +++ b/tests/tools/run-bindgen.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +import os +import sys +import subprocess +import tempfile + +BINDGEN_FLAGS_PREFIX = "// bindgen-flags: "; +COMMON_PRELUDE = """ +#![feature(const_fn)] +""" + +if len(sys.argv) != 4: + print("Usage: {} [bindgen-path] [c-path] [rust-path]\n".format(sys.argv[0])) + +flags = []; +with open(sys.argv[2]) as f: + for line in f: + if line.startswith(BINDGEN_FLAGS_PREFIX): + flags = line.strip().split(BINDGEN_FLAGS_PREFIX)[1].split(' ') + +base_command = [sys.argv[1], sys.argv[2], "-o", sys.argv[3]] + +for line in COMMON_PRELUDE.split('\n'): + flags.append("-raw-line") + flags.append(line) + +base_command.extend(flags); +subprocess.check_call(base_command, cwd=os.getcwd()) + + +name = None +with tempfile.NamedTemporaryFile(delete=False) as tests: + name = tests.name + subprocess.check_call(["rustc", "--test", sys.argv[3], "-o", tests.name]) +subprocess.check_call([tests.name]) |