tasks/07-session-support.md done

This commit is contained in:
2026-01-24 18:10:35 +01:00
parent 3b816ae656
commit ba4b695add
2 changed files with 341 additions and 2 deletions

View File

@@ -0,0 +1,114 @@
;;; test-ob-elixir-sessions.el --- Session tests for ob-elixir -*- lexical-binding: t; -*-
;; Copyright (C) 2024
;;; Commentary:
;; Tests for IEx session support in ob-elixir.
;;; Code:
(require 'ert)
(require 'ob-elixir)
(ert-deftest ob-elixir-test-session-creation ()
"Test session creation."
(skip-unless (executable-find ob-elixir-iex-command))
(unwind-protect
(let ((buffer (org-babel-elixir-initiate-session "test-create" nil)))
(should buffer)
(should (org-babel-comint-buffer-livep buffer)))
(ob-elixir-kill-session "test-create")))
(ert-deftest ob-elixir-test-session-persistence ()
"Test that sessions persist state."
(skip-unless (executable-find ob-elixir-iex-command))
(unwind-protect
(progn
;; First evaluation - define variable
(ob-elixir--evaluate-in-session "test-persist" "x = 42" 'value)
;; Second evaluation - use variable
(let ((result (ob-elixir--evaluate-in-session
"test-persist" "x * 2" 'value)))
(should (equal "84" result))))
(ob-elixir-kill-session "test-persist")))
(ert-deftest ob-elixir-test-session-none ()
"Test that :session none uses external process."
(skip-unless (executable-find ob-elixir-command))
(should (null (org-babel-elixir-initiate-session "none" nil))))
(ert-deftest ob-elixir-test-session-module-def ()
"Test defining module in session."
(skip-unless (executable-find ob-elixir-iex-command))
(unwind-protect
(progn
(ob-elixir--evaluate-in-session
"test-module"
"defmodule TestMod do\n def double(x), do: x * 2\nend"
'value)
(let ((result (ob-elixir--evaluate-in-session
"test-module" "TestMod.double(21)" 'value)))
(should (equal "42" result))))
(ob-elixir-kill-session "test-module")))
(ert-deftest ob-elixir-test-session-reuse ()
"Test that same session name returns same buffer."
(skip-unless (executable-find ob-elixir-iex-command))
(unwind-protect
(let ((buffer1 (org-babel-elixir-initiate-session "test-reuse" nil))
(buffer2 (org-babel-elixir-initiate-session "test-reuse" nil)))
(should (eq buffer1 buffer2)))
(ob-elixir-kill-session "test-reuse")))
(ert-deftest ob-elixir-test-multiple-sessions ()
"Test that multiple named sessions work independently."
(skip-unless (executable-find ob-elixir-iex-command))
(unwind-protect
(progn
;; Set x in session-a
(ob-elixir--evaluate-in-session "session-a" "x = 1" 'value)
;; Set x in session-b to different value
(ob-elixir--evaluate-in-session "session-b" "x = 100" 'value)
;; Verify each session has its own value
(let ((result-a (ob-elixir--evaluate-in-session "session-a" "x" 'value))
(result-b (ob-elixir--evaluate-in-session "session-b" "x" 'value)))
(should (equal "1" result-a))
(should (equal "100" result-b))))
(ob-elixir-kill-session "session-a")
(ob-elixir-kill-session "session-b")))
(ert-deftest ob-elixir-test-session-output-mode ()
"Test session output mode (capturing stdout)."
(skip-unless (executable-find ob-elixir-iex-command))
(unwind-protect
(let ((result (ob-elixir--evaluate-in-session
"test-output"
"IO.puts(\"Hello from session\")"
'output)))
(should (string-match-p "Hello from session" result)))
(ob-elixir-kill-session "test-output")))
(ert-deftest ob-elixir-test-kill-session ()
"Test killing a session."
(skip-unless (executable-find ob-elixir-iex-command))
(let ((buffer (org-babel-elixir-initiate-session "test-kill" nil)))
(should buffer)
(ob-elixir-kill-session "test-kill")
(should-not (buffer-live-p buffer))
(should-not (gethash "test-kill" ob-elixir--sessions))))
(ert-deftest ob-elixir-test-kill-all-sessions ()
"Test killing all sessions."
(skip-unless (executable-find ob-elixir-iex-command))
(let ((buffer1 (org-babel-elixir-initiate-session "test-all-1" nil))
(buffer2 (org-babel-elixir-initiate-session "test-all-2" nil)))
(should buffer1)
(should buffer2)
(ob-elixir-kill-all-sessions)
(should-not (buffer-live-p buffer1))
(should-not (buffer-live-p buffer2))
(should (= 0 (hash-table-count ob-elixir--sessions)))))
(provide 'test-ob-elixir-sessions)
;;; test-ob-elixir-sessions.el ends here