git » libfiu » commit 5712e84

tests: Add Python tests

author Alberto Bertogli
2012-03-28 21:17:20 UTC
committer Alberto Bertogli
2012-03-28 21:19:32 UTC
parent fbfaa640bbe8a2b32dfb7a73e503dc3d35666e62

tests: Add Python tests

This patch adds a simple Python test, and also renames the existing ones in C
to make their names more descriptive.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

Makefile +1 -1
tests/Makefile +36 -10
tests/{test-1.c => test-enable_stack.c} +0 -0
tests/{test-2.c => test-enable_stack_by_name.c} +0 -0
tests/test-failinfo_refcount.py +21 -0

diff --git a/Makefile b/Makefile
index c980b21..bae9e6b 100644
--- a/Makefile
+++ b/Makefile
@@ -51,7 +51,7 @@ utils_install: utils
 utils_uninstall:
 	$(MAKE) -C utils uninstall
 
-test: libfiu
+test: libfiu bindings
 	$(MAKE) -C tests
 
 bindings: python2 python3
diff --git a/tests/Makefile b/tests/Makefile
index 6dee4a9..9fb7875 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -11,28 +11,39 @@ ifdef PROFILE
 ALL_CFLAGS += -g -pg -fprofile-arcs -ftest-coverage
 endif
 
-
-OBJS = test-1.o test-2.o
-
-
 ifneq ($(V), 1)
 	NICE_CC = @echo "  CC  $@"; $(CC)
 	NICE_RUN = @echo "  RUN $<"; LD_LIBRARY_PATH=../libfiu/
+	NICE_PY_RUN = @echo "  PY  $<"; \
+		      LD_LIBRARY_PATH=../libfiu/ \
+		      PYTHONPATH=../bindings/python/
 else
 	NICE_CC = $(CC)
 	NICE_RUN = LD_LIBRARY_PATH=../libfiu/
+	NICE_PY_RUN = LD_LIBRARY_PATH=../libfiu/ \
+		      PYTHONPATH=../bindings/python/
 endif
 
 default: tests
 
 all: tests
 
-tests: run-test-1 run-test-2
+tests: c-tests py-tests
+
+#
+# C tests
+#
 
-test-%: test-%.o
+C_SRCS := $(wildcard test-*.c)
+C_OBJS := $(patsubst %.c,%.o,$(C_SRCS))
+C_BINS := $(patsubst %.c,%,$(C_SRCS))
+
+c-tests: $(patsubst %.c,c-run-%,$(C_SRCS))
+
+test-%: test-%.o build-flags
 	$(NICE_CC) $(ALL_CFLAGS) $< -lfiu -o $@
 
-run-%: % FORCE
+c-run-%: %
 	$(NICE_RUN) ./$<
 
 
@@ -45,18 +56,33 @@ build-flags: .force-build-flags
 		echo "$(BF)" > build-flags; \
 	fi
 
-$(OBJS): build-flags
-
 .c.o:
 	$(NICE_CC) $(ALL_CFLAGS) -c $< -o $@
 
+
+#
+# Python tests
+#
+
+PY_TESTS := $(wildcard test-*.py)
+
+py-tests: $(patsubst %.py,py-run-%,$(PY_TESTS))
+
+py-run-%: %.py
+	$(NICE_PY_RUN) python ./$<
+
+
 clean:
-	rm -f $(OBJS) test1
+	# Normally, $C_OBJS and $C_BINS are removed by make after building,
+	# since here they're considered "intermediate files"; however we
+	# also remove them when cleaning just in case.
+	rm -f $(C_OBJS) $(C_BINS)
 	rm -f *.bb *.bbg *.da *.gcov *.gcda *.gcno gmon.out build-flags
 
 FORCE:
 
 .PHONY: default all clean \
+	tests c-tests py-tests \
 	.force-build-flags
 
 
diff --git a/tests/test-1.c b/tests/test-enable_stack.c
similarity index 100%
rename from tests/test-1.c
rename to tests/test-enable_stack.c
diff --git a/tests/test-2.c b/tests/test-enable_stack_by_name.c
similarity index 100%
rename from tests/test-2.c
rename to tests/test-enable_stack_by_name.c
diff --git a/tests/test-failinfo_refcount.py b/tests/test-failinfo_refcount.py
new file mode 100644
index 0000000..79062be
--- /dev/null
+++ b/tests/test-failinfo_refcount.py
@@ -0,0 +1,21 @@
+
+"""
+Test that we keep references to failinfo as needed.
+"""
+
+import fiu
+
+# Object we'll use for failinfo
+finfo = [1, 2, 3]
+
+fiu.enable('p1', failinfo = finfo)
+
+assert fiu.fail('p1')
+assert fiu.failinfo('p1') is finfo
+
+finfo_id = id(finfo)
+del finfo
+
+assert fiu.failinfo('p1') == [1, 2, 3]
+assert id(fiu.failinfo('p1')) == finfo_id
+