mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-09-29 18:36:26 +00:00
ob-ruby: clean up the session code some more and work around an I/O sync problem in comint
* lisp/ob-ruby.el (org-babel-ruby-evaluate): Clean up the session code and remove a superfluous `butlast'. Work around a problem in comint where the first prompt in a session may be printed after the evaluation has already started, thus producing a spurious line in the output. * testing/lisp/test-ob-ruby.el (test-ob-ruby/session-output-1, test-ob-ruby/session-output-2 test-ob-ruby/session-output-3): Test correct transfer of interpreter state across several session invocations.
This commit is contained in:
parent
4ef78e68c1
commit
7585fe449b
|
@ -209,23 +209,32 @@ return the value of the last statement in BODY, as elisp."
|
||||||
;; comint session evaluation
|
;; comint session evaluation
|
||||||
(case result-type
|
(case result-type
|
||||||
(output
|
(output
|
||||||
(mapconcat
|
(let ((eoe-string (format "puts \"%s\"" org-babel-ruby-eoe-indicator)))
|
||||||
#'identity
|
;; Force the session to be ready before the actual session
|
||||||
(butlast
|
;; code is run. There is some problem in comint that will
|
||||||
(split-string
|
;; sometimes show the prompt after the the input has already
|
||||||
(mapconcat
|
;; been inserted and that throws off the extraction of the
|
||||||
#'org-babel-trim
|
;; result for Babel.
|
||||||
(butlast
|
(org-babel-comint-with-output
|
||||||
(org-babel-comint-with-output
|
(buffer org-babel-ruby-eoe-indicator t eoe-string)
|
||||||
(buffer org-babel-ruby-eoe-indicator t body)
|
(insert eoe-string) (comint-send-input nil t))
|
||||||
(mapc
|
;; Now we can start the evaluation.
|
||||||
(lambda (line)
|
(mapconcat
|
||||||
(insert (org-babel-chomp line)) (comint-send-input nil t))
|
#'identity
|
||||||
(list "conf.echo=false;_org_prompt_mode=conf.prompt_mode;conf.prompt_mode=:NULL"
|
(butlast
|
||||||
body
|
(split-string
|
||||||
"conf.prompt_mode=_org_prompt_mode;conf.echo=true" org-babel-ruby-eoe-indicator))
|
(mapconcat
|
||||||
) 2)
|
#'org-babel-trim
|
||||||
"\n") "[\r\n]")) "\n"))
|
(org-babel-comint-with-output
|
||||||
|
(buffer org-babel-ruby-eoe-indicator t body)
|
||||||
|
(mapc
|
||||||
|
(lambda (line)
|
||||||
|
(insert (org-babel-chomp line)) (comint-send-input nil t))
|
||||||
|
(list "conf.echo=false;_org_prompt_mode=conf.prompt_mode;conf.prompt_mode=:NULL"
|
||||||
|
body
|
||||||
|
"conf.prompt_mode=_org_prompt_mode;conf.echo=true"
|
||||||
|
eoe-string)))
|
||||||
|
"\n") "[\r\n]") 4) "\n")))
|
||||||
(value
|
(value
|
||||||
(let* ((tmp-file (org-babel-temp-file "ruby-"))
|
(let* ((tmp-file (org-babel-temp-file "ruby-"))
|
||||||
(ppp (or (member "code" result-params)
|
(ppp (or (member "code" result-params)
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
(unless (featurep 'ob-ruby)
|
(unless (featurep 'ob-ruby)
|
||||||
(signal 'missing-test-dependency "Support for Ruby code blocks"))
|
(signal 'missing-test-dependency "Support for Ruby code blocks"))
|
||||||
|
|
||||||
(ert-deftest test-ob-ruby/session-output ()
|
(ert-deftest test-ob-ruby/session-output-1 ()
|
||||||
(should (equal (org-test-with-temp-text "#+begin_src ruby :session :results output
|
(should (equal (org-test-with-temp-text "#+begin_src ruby :session :results output
|
||||||
s = \"1\"
|
s = \"1\"
|
||||||
s = \"2\"
|
s = \"2\"
|
||||||
|
@ -41,6 +41,38 @@ puts s
|
||||||
#+RESULTS:
|
#+RESULTS:
|
||||||
: 3
|
: 3
|
||||||
|
|
||||||
|
")))
|
||||||
|
(ert-deftest test-ob-ruby/session-output-2 ()
|
||||||
|
(should (equal (org-test-with-temp-text "#+begin_src ruby :session :results output
|
||||||
|
s = \"5\"
|
||||||
|
puts s
|
||||||
|
#+end_src"
|
||||||
|
(org-ctrl-c-ctrl-c)
|
||||||
|
(substring-no-properties
|
||||||
|
(buffer-string)))
|
||||||
|
"#+begin_src ruby :session :results output
|
||||||
|
s = \"5\"
|
||||||
|
puts s
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+RESULTS:
|
||||||
|
: 5
|
||||||
|
|
||||||
|
")))
|
||||||
|
(ert-deftest test-ob-ruby/session-output-3 ()
|
||||||
|
(should (equal (org-test-with-temp-text "#+begin_src ruby :session :results output
|
||||||
|
puts s
|
||||||
|
#+end_src"
|
||||||
|
(org-ctrl-c-ctrl-c)
|
||||||
|
(substring-no-properties
|
||||||
|
(buffer-string)))
|
||||||
|
"#+begin_src ruby :session :results output
|
||||||
|
puts s
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+RESULTS:
|
||||||
|
: 5
|
||||||
|
|
||||||
")))
|
")))
|
||||||
|
|
||||||
(provide 'test-ob-ruby)
|
(provide 'test-ob-ruby)
|
||||||
|
|
Loading…
Reference in a new issue