[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/sweeprolog 4ee4291703 018/166: TEST: Add ERT based tests
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/sweeprolog 4ee4291703 018/166: TEST: Add ERT based tests |
Date: |
Fri, 30 Sep 2022 04:59:22 -0400 (EDT) |
branch: elpa/sweeprolog
commit 4ee42917036e70c7e8b516a0b2a6f0b2f80d380c
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eshel Yaron <me@eshelyaron.com>
TEST: Add ERT based tests
---
.build.yml | 4 +++-
Makefile | 5 ++++-
sweep-tests.el | 18 ++++++++++++++++++
sweep.c | 22 ++++++++++++++++++----
4 files changed, 43 insertions(+), 6 deletions(-)
diff --git a/.build.yml b/.build.yml
index 7e2aed0690..394cd48260 100644
--- a/.build.yml
+++ b/.build.yml
@@ -26,6 +26,7 @@ packages:
- libyaml-dev
- zip
- git
+ - emacs
secrets:
- 750079bb-9735-473b-bebf-db897c9f0c6b
- 72d5c3dc-f83f-4cc2-96e3-b2b08f6ee8a0
@@ -38,4 +39,5 @@ tasks:
sudo localectl set-locale LANG=en_US.UTF-8
localectl set-locale LANG=en_US.UTF-8
make
- make info
+ make sweep.info
+ make check
diff --git a/Makefile b/Makefile
index e50729666a..fc31a9cc8f 100644
--- a/Makefile
+++ b/Makefile
@@ -33,7 +33,7 @@ CMAKE_OPTIONS += -DSWIPL_PACKAGES_JAVA=OFF
CMAKE_OPTIONS += -DSWIPL_PACKAGES_X=OFF
CMAKE_OPTIONS += -DSWIPL_INSTALL_IN_LIB=ON
-.PHONY: clean all swipl
+.PHONY: clean all swipl check
all: $(TARGET)
@@ -58,3 +58,6 @@ lib/libswipl.$(SOEXT):
$(BASENAME).info:: README.org
emacs -Q --batch --eval '(require (quote ox-texinfo))' --eval
"(with-current-buffer (find-file \"README.org\") (org-export-to-file (quote
texinfo) \"$@\" nil nil nil nil nil (quote org-texinfo-compile)))"
+
+check: $(TARGET)
+ emacs -batch --eval '(add-to-list (quote load-path) (expand-file-name
"."))' -l ert -l sweep -l sweep-tests.el -f ert-run-tests-batch-and-exit
diff --git a/sweep-tests.el b/sweep-tests.el
new file mode 100644
index 0000000000..c2dc790cab
--- /dev/null
+++ b/sweep-tests.el
@@ -0,0 +1,18 @@
+(ert-deftest lists:permutation/2 ()
+ "Tests calling the Prolog predicate permutation/2 from Elisp."
+ (should (equal (sweep-open-query "user" "lists" "permutation" (list 1 2 3))
t))
+ (should (equal (sweep-next-solution) (list t 1 2 3)))
+ (should (equal (sweep-next-solution) (list t 1 3 2)))
+ (should (equal (sweep-next-solution) (list t 2 1 3)))
+ (should (equal (sweep-next-solution) (list t 2 3 1)))
+ (should (equal (sweep-next-solution) (list t 3 1 2)))
+ (should (equal (sweep-next-solution) (list t 3 2 1)))
+ (should (equal (sweep-next-solution) nil))
+ (should (equal (sweep-cut-query) t)))
+
+(ert-deftest system:=/2 ()
+ "Tests calling the Prolog predicate permutation/2 from Elisp."
+ (should (equal (sweep-open-query "user" "system" "=" (list 1 2 3)) t))
+ (should (equal (sweep-next-solution) (list '! 1 2 3)))
+ (should (equal (sweep-next-solution) nil))
+ (should (equal (sweep-cut-query) t)))
diff --git a/sweep.c b/sweep.c
index 1d6a6af2af..ff148c71fb 100644
--- a/sweep.c
+++ b/sweep.c
@@ -154,9 +154,16 @@ term_to_value_compound(emacs_env *env, term_t t) {
const char * chars = NULL;
size_t len = 0;
emacs_value * vals = NULL;
+ emacs_value res = NULL;
size_t n = 0;
- (void)PL_get_compound_name_arity(t, &name, &arity);
+
+ if (!PL_get_compound_name_arity(t, &name, &arity)) {
+ ethrow(env, "Not a compound");
+ goto cleanup;
+ }
+
chars = PL_atom_nchars(name, &len);
+
vals = (emacs_value*)malloc(sizeof(emacs_value)*arity + 1);
if (vals == NULL) {
ethrow(env, "malloc failed");
@@ -167,12 +174,19 @@ term_to_value_compound(emacs_env *env, term_t t) {
vals[0] = env->make_string(env, chars, len);
for(n=1; n<=arity; n++) {
-
- (void)PL_get_arg(n, t, arg);
+ if (!PL_get_arg(n, t, arg)) {
+ ethrow(env, "get_arg falied");
+ goto cleanup;
+ }
vals[n] = term_to_value(env, arg);
}
- return econs(env, env->intern(env, "compound"), env->funcall(env,
env->intern(env, "list"), arity + 1, vals));
+ res = econs(env, env->intern(env, "compound"), env->funcall(env,
env->intern(env, "list"), arity + 1, vals));
+
+ cleanup:
+ if (vals != NULL) free(vals);
+
+ return res;
}
emacs_value
- [nongnu] branch elpa/sweeprolog created (now cada0d3871), ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 89733a1b7f 001/166: Initial commit, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 929e39e392 003/166: Vendor emacs-module.h, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 38edf9e3f2 005/166: FIXED: really initialize on load, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 99fc2242d8 009/166: Document sweep-find-predicate, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog b5b65517e2 010/166: DOC: Don't number manual headings, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog bfac04872f 013/166: DOC: fix typo, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 0ad4a77604 015/166: BUILD: set locale for CI, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog b71b13aba2 008/166: DOC: Document sweep-find-module in the manual, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 6425d68bad 006/166: Add README.org, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 4ee4291703 018/166: TEST: Add ERT based tests,
ELPA Syncer <=
- [nongnu] elpa/sweeprolog 268df47cfc 021/166: More rpath tweaks, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog b92f25f764 030/166: Cleanup sweep.el, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 972337d6d0 040/166: FIXED: accidentally left debugging remnants, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 0de5109bf8 064/166: ENHANCED: add completion-at-point in sweep-mode, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 5dfb1366e3 012/166: DOC: fix typo, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog d9546b9414 025/166: ENHANCED: make the prompts used in sweep-find-* customizable, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog e62d23140f 019/166: FIXED: Makefile setting SOEXT to dylib on linux hosts, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 7c15ebc4f1 026/166: ENHANCED: annotate predicates with the summaries from the manual, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 59b9dde951 028/166: DOC: Document sweep-pack-install, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog b67e5b5e3d 029/166: DOC: Expand the manual section about Querying Prolog, ELPA Syncer, 2022/09/30