-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
129 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
;;; test-ob-prolog.el --- tests for ob-prolog.el | ||
|
||
;; Copyright (c) 2015 Bjarte Johansen | ||
;; Authors: Bjarte Johansen | ||
|
||
;; This file is not part of GNU Emacs. | ||
|
||
;; This program is free software; you can redistribute it and/or modify | ||
;; it under the terms of the GNU General Public License as published by | ||
;; the Free Software Foundation, either version 3 of the License, or | ||
;; (at your option) any later version. | ||
|
||
;; This program is distributed in the hope that it will be useful, | ||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
;; GNU General Public License for more details. | ||
|
||
;; You should have received a copy of the GNU General Public License | ||
;; along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
;;; Code: | ||
|
||
(require 'ert) | ||
(require 'org-id) | ||
|
||
|
||
(unless (featurep 'ob-prolog) | ||
(signal 'missing-test-dependency "Support for Prolog code blocks")) | ||
|
||
(defmacro test-ob-prolog/test-src-block (number &rest body) | ||
(declare (indent 1)) | ||
(let ((buf (make-symbol "buf")) | ||
(visited-p (make-symbol "visited-p")) | ||
(file-pos (make-symbol "file-pos")) | ||
(file "test-ob-prolog.org")) | ||
`(let ((,visited-p (get-file-buffer ,file)) | ||
(,buf (find-file-noselect ,file))) | ||
(unwind-protect | ||
(with-current-buffer ,buf | ||
(goto-char (point-min)) | ||
(condition-case nil | ||
(progn | ||
(org-show-subtree) | ||
(org-show-block-all)) | ||
(error nil)) | ||
(dotimes (,(make-symbol "_") ,number) | ||
(org-babel-next-src-block)) | ||
(save-restriction ,@body)) | ||
(unless ,visited-p | ||
(kill-buffer ,buf)))))) | ||
(def-edebug-spec test-ob-prolog/test-src-block (form body)) | ||
|
||
(ert-deftest test-ob-prolog/simple-execution () | ||
"Test simple execution of prolog source block." | ||
(test-ob-prolog/test-src-block 1 | ||
(should (string= "Hello, org_mode." | ||
(org-babel-execute-src-block))))) | ||
|
||
(ert-deftest test-ob-prolog/goal-execution () | ||
"Test execution of goal argument to prolog source block." | ||
(test-ob-prolog/test-src-block 2 | ||
(should (string= "Hello, world!" | ||
(org-babel-execute-src-block))))) | ||
|
||
(ert-deftest test-ob-prolog/simple-running-session () | ||
(test-ob-prolog/test-src-block 3 | ||
(should (string= "A = 41." | ||
(org-babel-execute-src-block))))) | ||
|
||
(ert-deftest test-ob-prolog/simple-running-session () | ||
(test-ob-prolog/test-src-block 4 | ||
(should (string= "A = 42." | ||
(org-babel-execute-src-block))))) | ||
|
||
(ert-deftest test-ob-prolog/simple-running-session () | ||
(test-ob-prolog/test-src-block 6 | ||
(should (string= "A = [0, 1, 2, 3]." | ||
(org-babel-execute-src-block))))) | ||
|
||
;;; test-ob-prolog ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#+PROPERTY: results silent scalar | ||
#+TITLE: Tests for ob-prolog | ||
|
||
|
||
* Basic prolog source block | ||
#+BEGIN_SRC prolog | ||
:- format('Hello, ~a.', org_mode). | ||
#+END_SRC | ||
|
||
* Source block with goal | ||
#+BEGIN_SRC prolog :goal main | ||
main :- | ||
write('Hello, world!'). | ||
#+END_SRC | ||
|
||
* Simple running session | ||
#+HEADER: :session *prolog-1* | ||
#+HEADER: :goal fourtyone(A) | ||
#+BEGIN_SRC prolog | ||
fourtyone(A) :- A is 41. | ||
#+END_SRC | ||
|
||
* Calling predicate from session | ||
#+HEADER :session *prolog-1* | ||
#+HEADER :goal answer(A) | ||
#+BEGIN_SRC prolog | ||
answer(C) :- | ||
fourtyone(B), | ||
C is B+1. | ||
#+END_SRC | ||
|
||
|
||
* Test interaction with other blocks | ||
#+NAME: f | ||
#+BEGIN_SRC elisp :results vector | ||
'(1 2 3) | ||
#+END_SRC | ||
|
||
#+HEADER: :var a=f() | ||
#+HEADER: :var b=0 | ||
#+HEADER: :goal main(A) | ||
#+HEADER: :session *prolog-1* | ||
#+BEGIN_SRC prolog | ||
main(B) :- recorded(a, A), recorded(b, C), append([C], A, B). | ||
#+END_SRC |