CMAKE_OPTIONS += -DSWIPL_PACKAGES_X=OFF
CMAKE_OPTIONS += -DSWIPL_INSTALL_IN_LIB=ON
-.PHONY: clean all swipl
+.PHONY: clean all swipl check
all: $(TARGET)
$(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
--- /dev/null
+(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)))
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");
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