From d27a381cb0afb07a1a0a043c820e1eae86570ad5 Mon Sep 17 00:00:00 2001 From: Bruno BARBIER Date: Sat, 29 Apr 2023 11:06:45 +0200 Subject: [PATCH 12/13] * testing/lisp/test-ob-haskell-ghci.el: Modify `test-ob-haskell-ghci` * testing/lisp/test-ob-haskell-ghci.el (test-ob-haskell-ghci--with-global-session-worker) (test-ob-haskell-ghci-with-global-session): Deleted. (test-ob-haskell-ghci-checking-buffers): New function. (test-ob-haskell-ghci): Update to handle the new meaning of sessions. --- testing/lisp/test-ob-haskell-ghci.el | 40 +++++++++++----------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/testing/lisp/test-ob-haskell-ghci.el b/testing/lisp/test-ob-haskell-ghci.el index 49d5a8684..b356f4951 100644 --- a/testing/lisp/test-ob-haskell-ghci.el +++ b/testing/lisp/test-ob-haskell-ghci.el @@ -37,43 +37,33 @@ (unless (featurep 'haskell-mode) ;;; Helpers ;; -(defun test-ob-haskell-ghci--with-global-session-worker (todo) +(defun test-ob-haskell-ghci-checking-buffers (todo) "See `test-ob-haskell-ghci--with-global-session-worker'." (when (get-buffer "*haskell*") (error "A buffer named '*haskell*' exists. Can't safely test haskell blocks")) - (unwind-protect (funcall todo) - ;; Kill the "*haskell*" buffer to not pollute other tests. + (prog1 (funcall todo) (when-let ((hb (get-buffer "*haskell*"))) - (with-current-buffer hb - (let ((kill-buffer-query-functions nil) - (kill-buffer-hook nil)) - (kill-buffer hb)))))) - -(defmacro test-ob-haskell-ghci-with-global-session (&rest body) - "Eval BODY in a new session, then destroy the session. -The library ob-haskell doesn't implement session yet. It will -always use a buffer named \"*haskell*\". We kill that buffer -after the source block execution. To be safe, we fail if such a -buffer already exists." - `(test-ob-haskell-ghci--with-global-session-worker (lambda () ,@body))) + ;; We created a "*haskell*" buffer. That shouldn't happen. + (error "'ob-haskell' created a buffer named '*haskell*'")))) + + (defun test-ob-haskell-ghci (args content &optional preamble unprotected) "Execute the code block CONTENT in a new GHCi session; return the result. Add ARGS to the code block argument line. Insert PREAMBLE -before the code block. When UNPROTECTED is non-nil, don't control -which session is used (i.e. don't call -`test-ob-haskell-ghci--with-global-session-worker')." +before the code block. When UNPROTECTED is non-nil, check pre/post conditions." (when (listp content) (setq content (string-join content "\n"))) (unless preamble (setq preamble "")) - (let ((todo (lambda () - (org-test-with-temp-text - (concat preamble "\n" "#+begin_src haskell :compile no " - args "\n" "" content "\n#+end_src") - (org-babel-execute-src-block))))) - (if unprotected (funcall todo) - (test-ob-haskell-ghci-with-global-session (funcall todo))))) + (let ((todo (lambda () + (prog1 (org-test-with-temp-text + (concat preamble "\n" "#+begin_src haskell :compile no " + args "\n" "" content "\n#+end_src") + (org-babel-execute-src-block)))))) + (if unprotected (funcall todo) + (test-ob-haskell-ghci-checking-buffers todo)))) + ;;; Tests -- 2.39.3