[pl] Introduce run-time tests
Petr Pisar
ppisar at fedoraproject.org
Thu Mar 8 14:56:58 UTC 2012
commit 2d3446c58e899f76780d967ad8c6cdeeb10b6a07
Author: Petr Písař <ppisar at redhat.com>
Date: Wed Mar 7 14:10:12 2012 +0100
Introduce run-time tests
run `make' in `tests' directory to test installed SWI Prolog. These
tests require prolog to be installed because it verifies packaging.
Thus the tests cannot be run at build-time.
tests/Makefile | 10 ++++++++++
tests/c_binding/Makefile | 13 +++++++++++++
tests/c_binding/calc.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
tests/c_binding/calc.pl | 5 +++++
4 files changed, 74 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644
index 0000000..18bad73
--- /dev/null
+++ b/tests/Makefile
@@ -0,0 +1,10 @@
+.PHONY: clean-c_binding c_binding
+
+all: c_binding
+clean: clean-c_binding
+
+c_binding:
+ $(MAKE) -C $@
+
+clean-c_binding:
+ $(MAKE) -C $(subst clean-,,$@) clean
diff --git a/tests/c_binding/Makefile b/tests/c_binding/Makefile
new file mode 100644
index 0000000..10db7b2
--- /dev/null
+++ b/tests/c_binding/Makefile
@@ -0,0 +1,13 @@
+.PHONY: pi
+
+all: calc.out
+ echo '3.141592653589793' | cmp - calc.out
+
+calc.out: calc
+ ./calc 'pi' | tee calc.out
+
+calc: calc.c calc.pl
+ swipl-ld -o calc calc.c calc.pl
+
+clean:
+ rm -f calc calc.out
diff --git a/tests/c_binding/calc.c b/tests/c_binding/calc.c
new file mode 100644
index 0000000..27390b9
--- /dev/null
+++ b/tests/c_binding/calc.c
@@ -0,0 +1,46 @@
+#include <stdio.h>
+#include <SWI-Prolog.h>
+
+#define MAXLINE 1024
+
+int
+main(int argc, char **argv)
+{ char expression[MAXLINE];
+ char *e = expression;
+ char *program = argv[0];
+ char *plav[2];
+ int n;
+
+ /* combine all the arguments in a single string */
+
+ for(n=1; n<argc; n++)
+ { if ( n != 1 )
+ *e++ = ' ';
+ strcpy(e, argv[n]);
+ e += strlen(e);
+ }
+
+ /* make the argument vector for Prolog */
+
+ plav[0] = program;
+ plav[1] = NULL;
+
+ /* initialise Prolog */
+
+ if ( !PL_initialise(1, plav) )
+ PL_halt(1);
+
+ /* Lookup calc/1 and make the arguments and call */
+
+ { predicate_t pred = PL_predicate("calc", 1, "user");
+ term_t h0 = PL_new_term_refs(1);
+ int rval;
+
+ PL_put_atom_chars(h0, expression);
+ rval = PL_call_predicate(NULL, PL_Q_NORMAL, pred, h0);
+
+ PL_halt(rval ? 0 : 1);
+ }
+
+ return 0;
+}
diff --git a/tests/c_binding/calc.pl b/tests/c_binding/calc.pl
new file mode 100644
index 0000000..b5e6ca9
--- /dev/null
+++ b/tests/c_binding/calc.pl
@@ -0,0 +1,5 @@
+calc(Atom) :-
+ term_to_atom(Expr, Atom),
+ A is Expr,
+ write(A),
+ nl.
More information about the scm-commits
mailing list