This commit is contained in:
2026-01-25 00:06:56 +01:00
parent 00afc36c9e
commit 4e07ffa70c
8 changed files with 978 additions and 35 deletions

View File

@@ -54,5 +54,17 @@
(let ((result (ob-elixir--execute "undefined_function()" 'value)))
(should (string-match-p "\\(UndefinedFunctionError\\|CompileError\\)" result)))))
(ert-deftest ob-elixir-test-error-appears-in-result ()
"Test that errors appear in result even when signaling is enabled."
(skip-unless (executable-find ob-elixir-command))
(let ((ob-elixir-signal-errors t))
;; Execute via the main entry point (not ob-elixir--execute directly)
(let ((result (org-babel-execute:elixir "raise \"test error\""
'((:result-type . value)
(:result-params . ("replace"))))))
;; Result should contain the error, not be nil/empty
(should result)
(should (string-match-p "RuntimeError" result)))))
(provide 'test-ob-elixir-errors)
;;; test-ob-elixir-errors.el ends here

View File

@@ -0,0 +1,88 @@
;;; test-ob-elixir-imports.el --- Imports block tests -*- lexical-binding: t; -*-
;;; Commentary:
;; Tests for the imports block functionality.
;;; Code:
(require 'ert)
(require 'ob-elixir)
;;; Imports Block Parsing Tests
(ert-deftest ob-elixir-test-imports-block-parsing ()
"Test that imports blocks are correctly parsed."
(with-temp-buffer
(insert "#+BEGIN_IMPORTS elixir\nimport Enum\nalias Foo\n#+END_IMPORTS\n")
(goto-char (point-max))
(let ((imports (ob-elixir--find-imports-for-position (point))))
(should imports)
(should (string-match-p "import Enum" imports))
(should (string-match-p "alias Foo" imports)))))
(ert-deftest ob-elixir-test-no-imports-block ()
"Test that nil is returned when no imports block exists."
(with-temp-buffer
(insert "#+begin_src elixir\n1 + 1\n#+end_src\n")
(should (null (ob-elixir--find-imports-for-position (point))))))
(ert-deftest ob-elixir-test-imports-block-before-position ()
"Test that imports block must be before position."
(with-temp-buffer
(insert "#+begin_src elixir\n1 + 1\n#+end_src\n")
(let ((pos (point)))
(insert "#+BEGIN_IMPORTS elixir\nimport Enum\n#+END_IMPORTS\n")
(should (null (ob-elixir--find-imports-for-position pos))))))
(ert-deftest ob-elixir-test-imports-block-override ()
"Test that later imports blocks override earlier ones."
(with-temp-buffer
(insert "#+BEGIN_IMPORTS elixir\nimport Enum\n#+END_IMPORTS\n")
(insert "#+BEGIN_IMPORTS elixir\nimport String\n#+END_IMPORTS\n")
(goto-char (point-max))
(let ((imports (ob-elixir--find-imports-for-position (point))))
(should imports)
(should (string-match-p "import String" imports))
(should-not (string-match-p "import Enum" imports)))))
;;; Imports Execution Tests
(ert-deftest ob-elixir-test-imports-execution ()
"Test that imports are applied during execution."
(skip-unless (executable-find ob-elixir-command))
;; Ensure org-babel is loaded with Elixir support
(setq org-confirm-babel-evaluate nil)
(org-babel-do-load-languages
'org-babel-load-languages
'((elixir . t)))
(with-temp-buffer
(org-mode)
(insert "#+BEGIN_IMPORTS elixir\nimport Enum\n#+END_IMPORTS\n\n")
(insert "#+begin_src elixir :results value\nmap([1,2,3], &(&1 * 2))\n#+end_src\n")
(goto-char (point-min))
(search-forward "#+begin_src")
(let ((result (org-babel-execute-src-block)))
;; Without import, this would fail because map/2 requires Enum prefix
(should result)
(should (equal result '(2 4 6))))))
(ert-deftest ob-elixir-test-imports-with-alias ()
"Test that alias works in imports block."
(skip-unless (executable-find ob-elixir-command))
;; Ensure org-babel is loaded with Elixir support
(setq org-confirm-babel-evaluate nil)
(org-babel-do-load-languages
'org-babel-load-languages
'((elixir . t)))
(with-temp-buffer
(org-mode)
(insert "#+BEGIN_IMPORTS elixir\nalias String, as: S\n#+END_IMPORTS\n\n")
(insert "#+begin_src elixir :results value\nS.upcase(\"hello\")\n#+end_src\n")
(goto-char (point-min))
(search-forward "#+begin_src")
(let ((result (org-babel-execute-src-block)))
(should (equal result "\"HELLO\"")))))
(provide 'test-ob-elixir-imports)
;;; test-ob-elixir-imports.el ends here

View File

@@ -24,6 +24,9 @@
(require 'test-ob-elixir-results)
(require 'test-ob-elixir-errors)
(require 'test-ob-elixir-org)
(require 'test-ob-elixir-deps)
(require 'test-ob-elixir-imports)
;; (require 'test-ob-elixir-sessions)
;;; Smoke Test