tasks/06-test-suite.md done
This commit is contained in:
2
Makefile
2
Makefile
@@ -1,5 +1,5 @@
|
|||||||
EMACS ?= emacs
|
EMACS ?= emacs
|
||||||
BATCH = $(EMACS) -Q -batch -L .
|
BATCH = $(EMACS) -Q -batch -L . -L test
|
||||||
|
|
||||||
.PHONY: all compile test lint clean
|
.PHONY: all compile test lint clean
|
||||||
|
|
||||||
|
|||||||
62
test/test-ob-elixir-core.el
Normal file
62
test/test-ob-elixir-core.el
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
;;; test-ob-elixir-core.el --- Core execution tests -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
|
;;; Commentary:
|
||||||
|
|
||||||
|
;; Core execution tests for ob-elixir package.
|
||||||
|
|
||||||
|
;;; Code:
|
||||||
|
|
||||||
|
(require 'ert)
|
||||||
|
(require 'ob-elixir)
|
||||||
|
|
||||||
|
;;; Command Tests
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-elixir-available ()
|
||||||
|
"Test that Elixir is available."
|
||||||
|
(should (executable-find ob-elixir-command)))
|
||||||
|
|
||||||
|
;;; Basic Execution Tests
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-simple-value ()
|
||||||
|
"Test simple value evaluation."
|
||||||
|
(skip-unless (executable-find ob-elixir-command))
|
||||||
|
(let ((result (ob-elixir--execute "1 + 1" 'value)))
|
||||||
|
(should (equal "2" result))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-simple-output ()
|
||||||
|
"Test simple output evaluation."
|
||||||
|
(skip-unless (executable-find ob-elixir-command))
|
||||||
|
(let ((result (ob-elixir--execute "IO.puts(\"hello\")" 'output)))
|
||||||
|
(should (equal "hello" result))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-multiline-value ()
|
||||||
|
"Test multiline code value evaluation."
|
||||||
|
(skip-unless (executable-find ob-elixir-command))
|
||||||
|
(let ((result (ob-elixir--execute "x = 10\ny = 20\nx + y" 'value)))
|
||||||
|
(should (equal "30" result))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-list-result ()
|
||||||
|
"Test list result."
|
||||||
|
(skip-unless (executable-find ob-elixir-command))
|
||||||
|
(let ((result (ob-elixir--execute "[1, 2, 3]" 'value)))
|
||||||
|
(should (equal "[1, 2, 3]" result))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-map-result ()
|
||||||
|
"Test map result."
|
||||||
|
(skip-unless (executable-find ob-elixir-command))
|
||||||
|
(let ((result (ob-elixir--execute "%{a: 1, b: 2}" 'value)))
|
||||||
|
;; Maps are unordered in Elixir, so accept either order
|
||||||
|
(should (or (string-match-p "%{a: 1, b: 2}" result)
|
||||||
|
(string-match-p "%{b: 2, a: 1}" result)))))
|
||||||
|
|
||||||
|
;;; Wrapper Tests
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-wrap-for-value ()
|
||||||
|
"Test value wrapper generation."
|
||||||
|
(let ((wrapped (ob-elixir--wrap-for-value "1 + 1")))
|
||||||
|
(should (string-match-p "result = " wrapped))
|
||||||
|
(should (string-match-p "IO\\.puts" wrapped))
|
||||||
|
(should (string-match-p "inspect" wrapped))))
|
||||||
|
|
||||||
|
(provide 'test-ob-elixir-core)
|
||||||
|
;;; test-ob-elixir-core.el ends here
|
||||||
58
test/test-ob-elixir-errors.el
Normal file
58
test/test-ob-elixir-errors.el
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
;;; test-ob-elixir-errors.el --- Error handling tests -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
|
;;; Commentary:
|
||||||
|
|
||||||
|
;; Error handling and detection tests for ob-elixir package.
|
||||||
|
|
||||||
|
;;; Code:
|
||||||
|
|
||||||
|
(require 'ert)
|
||||||
|
(require 'ob-elixir)
|
||||||
|
|
||||||
|
;;; Error Detection Tests
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-detect-runtime-error ()
|
||||||
|
"Test runtime error detection."
|
||||||
|
(let ((output "** (RuntimeError) something went wrong"))
|
||||||
|
(let ((error-info (ob-elixir--detect-error output)))
|
||||||
|
(should error-info)
|
||||||
|
(should (eq 'runtime (plist-get error-info :type)))
|
||||||
|
(should (equal "RuntimeError" (plist-get error-info :error-type))))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-detect-compile-error ()
|
||||||
|
"Test compile error detection."
|
||||||
|
(let ((output "** (CompileError) test.exs:1: undefined function foo/0"))
|
||||||
|
(let ((error-info (ob-elixir--detect-error output)))
|
||||||
|
(should error-info)
|
||||||
|
(should (eq 'compile (plist-get error-info :type)))
|
||||||
|
(should (equal "CompileError" (plist-get error-info :error-type))))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-no-error ()
|
||||||
|
"Test that valid output is not detected as error."
|
||||||
|
(should-not (ob-elixir--detect-error "42"))
|
||||||
|
(should-not (ob-elixir--detect-error "[1, 2, 3]"))
|
||||||
|
(should-not (ob-elixir--detect-error "\"hello\"")))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-error-execution ()
|
||||||
|
"Test that errors are properly handled during execution."
|
||||||
|
(skip-unless (executable-find ob-elixir-command))
|
||||||
|
(let ((ob-elixir-signal-errors nil))
|
||||||
|
(let ((result (ob-elixir--execute "raise \"test error\"" 'value)))
|
||||||
|
(should (string-match-p "RuntimeError" result)))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-error-signaling ()
|
||||||
|
"Test that errors are signaled when configured."
|
||||||
|
(skip-unless (executable-find ob-elixir-command))
|
||||||
|
(let ((ob-elixir-signal-errors t))
|
||||||
|
(should-error (ob-elixir--execute "raise \"test error\"" 'value)
|
||||||
|
:type 'ob-elixir-runtime-error)))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-undefined-function ()
|
||||||
|
"Test handling of undefined function error."
|
||||||
|
(skip-unless (executable-find ob-elixir-command))
|
||||||
|
(let ((ob-elixir-signal-errors nil))
|
||||||
|
(let ((result (ob-elixir--execute "undefined_function()" 'value)))
|
||||||
|
(should (string-match-p "\\(UndefinedFunctionError\\|CompileError\\)" result)))))
|
||||||
|
|
||||||
|
(provide 'test-ob-elixir-errors)
|
||||||
|
;;; test-ob-elixir-errors.el ends here
|
||||||
71
test/test-ob-elixir-org.el
Normal file
71
test/test-ob-elixir-org.el
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
;;; test-ob-elixir-org.el --- Org integration tests -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
|
;;; Commentary:
|
||||||
|
|
||||||
|
;; Org-mode integration tests for ob-elixir package.
|
||||||
|
|
||||||
|
;;; Code:
|
||||||
|
|
||||||
|
(require 'ert)
|
||||||
|
(require 'org)
|
||||||
|
(require 'ob)
|
||||||
|
(require 'ob-elixir)
|
||||||
|
|
||||||
|
;;; Helper Functions
|
||||||
|
|
||||||
|
(defun ob-elixir-test--ensure-org-babel-loaded ()
|
||||||
|
"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))))
|
||||||
|
|
||||||
|
(defun ob-elixir-test--execute-src-block (code &optional header-args)
|
||||||
|
"Execute CODE as an Elixir src block with HEADER-ARGS."
|
||||||
|
(ob-elixir-test--ensure-org-babel-loaded)
|
||||||
|
(let ((org-confirm-babel-evaluate nil))
|
||||||
|
(with-temp-buffer
|
||||||
|
(org-mode)
|
||||||
|
(insert (format "#+BEGIN_SRC elixir%s\n%s\n#+END_SRC"
|
||||||
|
(if header-args (concat " " header-args) "")
|
||||||
|
code))
|
||||||
|
(goto-char (point-min))
|
||||||
|
(forward-line 1)
|
||||||
|
(org-babel-execute-src-block))))
|
||||||
|
|
||||||
|
;;; Basic Org Tests
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-org-simple ()
|
||||||
|
"Test simple org block execution."
|
||||||
|
(skip-unless (executable-find ob-elixir-command))
|
||||||
|
(should (equal "2" (ob-elixir-test--execute-src-block "1 + 1"))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-org-with-var ()
|
||||||
|
"Test org block execution with variable."
|
||||||
|
(skip-unless (executable-find ob-elixir-command))
|
||||||
|
(should (equal "20" (ob-elixir-test--execute-src-block "x * 2" ":var x=10"))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-org-results-output ()
|
||||||
|
"Test org block with :results output."
|
||||||
|
(skip-unless (executable-find ob-elixir-command))
|
||||||
|
(should (equal "hello"
|
||||||
|
(ob-elixir-test--execute-src-block
|
||||||
|
"IO.puts(\"hello\")"
|
||||||
|
":results output"))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-org-results-value ()
|
||||||
|
"Test org block with :results value."
|
||||||
|
(skip-unless (executable-find ob-elixir-command))
|
||||||
|
(should (equal '(1 2 3)
|
||||||
|
(ob-elixir-test--execute-src-block
|
||||||
|
"[1, 2, 3]"
|
||||||
|
":results value"))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-org-table-result ()
|
||||||
|
"Test org block returning table."
|
||||||
|
(skip-unless (executable-find ob-elixir-command))
|
||||||
|
(let ((result (ob-elixir-test--execute-src-block "[[1, 2], [3, 4]]")))
|
||||||
|
(should (equal '((1 2) (3 4)) result))))
|
||||||
|
|
||||||
|
(provide 'test-ob-elixir-org)
|
||||||
|
;;; test-ob-elixir-org.el ends here
|
||||||
58
test/test-ob-elixir-results.el
Normal file
58
test/test-ob-elixir-results.el
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
;;; test-ob-elixir-results.el --- Result formatting tests -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
|
;;; Commentary:
|
||||||
|
|
||||||
|
;; Result formatting and table support tests for ob-elixir package.
|
||||||
|
|
||||||
|
;;; Code:
|
||||||
|
|
||||||
|
(require 'ert)
|
||||||
|
(require 'ob-elixir)
|
||||||
|
|
||||||
|
;;; Parsing Tests
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-parse-simple-list ()
|
||||||
|
"Test parsing simple list result."
|
||||||
|
(should (equal '(1 2 3) (ob-elixir--table-or-string "[1, 2, 3]"))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-parse-nested-list ()
|
||||||
|
"Test parsing nested list (table) result."
|
||||||
|
(should (equal '((1 2) (3 4))
|
||||||
|
(ob-elixir--table-or-string "[[1, 2], [3, 4]]"))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-parse-tuple ()
|
||||||
|
"Test parsing tuple result."
|
||||||
|
(should (equal '(1 2 3) (ob-elixir--table-or-string "{1, 2, 3}"))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-parse-scalar ()
|
||||||
|
"Test that scalars are returned as strings."
|
||||||
|
(should (equal "42" (ob-elixir--table-or-string "42")))
|
||||||
|
(should (equal ":ok" (ob-elixir--table-or-string ":ok"))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-parse-string ()
|
||||||
|
"Test parsing string result."
|
||||||
|
(should (equal "\"hello\"" (ob-elixir--table-or-string "\"hello\""))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-sanitize-table-nil ()
|
||||||
|
"Test that nil values are sanitized in tables."
|
||||||
|
(let ((ob-elixir-nil-to 'hline))
|
||||||
|
(should (equal '((1 hline) (hline 2))
|
||||||
|
(ob-elixir--sanitize-table '((1 nil) (nil 2)))))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-execution-returns-table ()
|
||||||
|
"Test that list results become tables."
|
||||||
|
(skip-unless (executable-find ob-elixir-command))
|
||||||
|
(let ((result (ob-elixir--table-or-string
|
||||||
|
(ob-elixir--execute "[[1, 2], [3, 4]]" 'value))))
|
||||||
|
(should (equal '((1 2) (3 4)) result))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-mixed-list ()
|
||||||
|
"Test parsing mixed-type list."
|
||||||
|
(skip-unless (executable-find ob-elixir-command))
|
||||||
|
(let ((result (ob-elixir--table-or-string
|
||||||
|
(ob-elixir--execute "[1, \"two\", :three]" 'value))))
|
||||||
|
(should (listp result))
|
||||||
|
(should (= 3 (length result)))))
|
||||||
|
|
||||||
|
(provide 'test-ob-elixir-results)
|
||||||
|
;;; test-ob-elixir-results.el ends here
|
||||||
90
test/test-ob-elixir-vars.el
Normal file
90
test/test-ob-elixir-vars.el
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
;;; test-ob-elixir-vars.el --- Variable handling tests -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
|
;;; Commentary:
|
||||||
|
|
||||||
|
;; Variable handling and type conversion tests for ob-elixir package.
|
||||||
|
|
||||||
|
;;; Code:
|
||||||
|
|
||||||
|
(require 'ert)
|
||||||
|
(require 'ob-elixir)
|
||||||
|
|
||||||
|
;;; Type Conversion Tests
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-convert-nil ()
|
||||||
|
"Test nil conversion."
|
||||||
|
(should (equal "nil" (ob-elixir--elisp-to-elixir nil))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-convert-true ()
|
||||||
|
"Test t conversion."
|
||||||
|
(should (equal "true" (ob-elixir--elisp-to-elixir t))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-convert-integer ()
|
||||||
|
"Test integer conversion."
|
||||||
|
(should (equal "42" (ob-elixir--elisp-to-elixir 42)))
|
||||||
|
(should (equal "-10" (ob-elixir--elisp-to-elixir -10))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-convert-float ()
|
||||||
|
"Test float conversion."
|
||||||
|
(should (equal "3.14" (ob-elixir--elisp-to-elixir 3.14))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-convert-string ()
|
||||||
|
"Test string conversion."
|
||||||
|
(should (equal "\"hello\"" (ob-elixir--elisp-to-elixir "hello"))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-convert-string-escaping ()
|
||||||
|
"Test string escaping."
|
||||||
|
(should (equal "\"say \\\"hi\\\"\""
|
||||||
|
(ob-elixir--elisp-to-elixir "say \"hi\"")))
|
||||||
|
(should (equal "\"line1\\nline2\""
|
||||||
|
(ob-elixir--elisp-to-elixir "line1\nline2"))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-convert-symbol ()
|
||||||
|
"Test symbol conversion to atom."
|
||||||
|
(should (equal ":foo" (ob-elixir--elisp-to-elixir 'foo)))
|
||||||
|
(should (equal ":ok" (ob-elixir--elisp-to-elixir 'ok))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-convert-list ()
|
||||||
|
"Test list conversion."
|
||||||
|
(should (equal "[1, 2, 3]" (ob-elixir--elisp-to-elixir '(1 2 3))))
|
||||||
|
(should (equal "[\"a\", \"b\"]" (ob-elixir--elisp-to-elixir '("a" "b")))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-convert-nested-list ()
|
||||||
|
"Test nested list conversion."
|
||||||
|
(should (equal "[[1, 2], [3, 4]]"
|
||||||
|
(ob-elixir--elisp-to-elixir '((1 2) (3 4))))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-convert-vector ()
|
||||||
|
"Test vector to tuple conversion."
|
||||||
|
(should (equal "{1, 2, 3}" (ob-elixir--elisp-to-elixir [1 2 3]))))
|
||||||
|
|
||||||
|
;;; Variable Assignment Tests
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-variable-assignments ()
|
||||||
|
"Test variable assignment generation."
|
||||||
|
(let ((params '((:var . ("x" . 5))
|
||||||
|
(:var . ("name" . "Alice")))))
|
||||||
|
(let ((assignments (org-babel-variable-assignments:elixir params)))
|
||||||
|
(should (member "x = 5" assignments))
|
||||||
|
(should (member "name = \"Alice\"" assignments)))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-var-execution ()
|
||||||
|
"Test code execution with variables."
|
||||||
|
(skip-unless (executable-find ob-elixir-command))
|
||||||
|
(let* ((params '((:var . ("x" . 10))))
|
||||||
|
(var-lines (org-babel-variable-assignments:elixir params))
|
||||||
|
(full-body (concat (mapconcat #'identity var-lines "\n")
|
||||||
|
"\nx * 2")))
|
||||||
|
(should (equal "20" (ob-elixir--execute full-body 'value)))))
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-var-list ()
|
||||||
|
"Test passing list as variable."
|
||||||
|
(skip-unless (executable-find ob-elixir-command))
|
||||||
|
(let* ((params '((:var . ("data" . (1 2 3)))))
|
||||||
|
(var-lines (org-babel-variable-assignments:elixir params))
|
||||||
|
(full-body (concat (mapconcat #'identity var-lines "\n")
|
||||||
|
"\nEnum.sum(data)")))
|
||||||
|
(should (equal "6" (ob-elixir--execute full-body 'value)))))
|
||||||
|
|
||||||
|
(provide 'test-ob-elixir-vars)
|
||||||
|
;;; test-ob-elixir-vars.el ends here
|
||||||
@@ -2,224 +2,40 @@
|
|||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
|
|
||||||
;; Test suite for ob-elixir package.
|
;; Main test file that loads all test modules.
|
||||||
|
;; Run with: make test
|
||||||
|
;; Or: emacs -batch -l ert -l test/test-ob-elixir.el -f ert-run-tests-batch-and-exit
|
||||||
|
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
(require 'ert)
|
(require 'ert)
|
||||||
|
|
||||||
;; Add parent directory to load path
|
;; Add source directory to load path
|
||||||
(let ((dir (file-name-directory (or load-file-name buffer-file-name))))
|
(let ((dir (file-name-directory (or load-file-name buffer-file-name))))
|
||||||
(add-to-list 'load-path (expand-file-name ".." dir)))
|
(add-to-list 'load-path (expand-file-name ".." dir))
|
||||||
|
(add-to-list 'load-path dir))
|
||||||
|
|
||||||
|
;; Load the package
|
||||||
(require 'ob-elixir)
|
(require 'ob-elixir)
|
||||||
|
|
||||||
|
;; Load test modules
|
||||||
|
(require 'test-ob-elixir-core)
|
||||||
|
(require 'test-ob-elixir-vars)
|
||||||
|
(require 'test-ob-elixir-results)
|
||||||
|
(require 'test-ob-elixir-errors)
|
||||||
|
(require 'test-ob-elixir-org)
|
||||||
|
|
||||||
|
;;; Smoke Test
|
||||||
|
|
||||||
|
(ert-deftest ob-elixir-test-smoke ()
|
||||||
|
"Basic smoke test - package loads and functions are defined."
|
||||||
|
(should (featurep 'ob-elixir))
|
||||||
|
(should (fboundp 'org-babel-execute:elixir))
|
||||||
|
(should (boundp 'org-babel-default-header-args:elixir)))
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-package-loads ()
|
(ert-deftest ob-elixir-test-package-loads ()
|
||||||
"Test that the package loads successfully."
|
"Test that the package loads successfully."
|
||||||
(should (featurep 'ob-elixir)))
|
(should (featurep 'ob-elixir)))
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-elixir-available ()
|
|
||||||
"Test that Elixir is available."
|
|
||||||
(should (executable-find ob-elixir-command)))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-simple-value ()
|
|
||||||
"Test simple value evaluation."
|
|
||||||
(skip-unless (executable-find ob-elixir-command))
|
|
||||||
(let ((result (ob-elixir--execute "1 + 1" 'value)))
|
|
||||||
(should (equal "2" result))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-simple-output ()
|
|
||||||
"Test simple output evaluation."
|
|
||||||
(skip-unless (executable-find ob-elixir-command))
|
|
||||||
(let ((result (ob-elixir--execute "IO.puts(\"hello\")" 'output)))
|
|
||||||
(should (equal "hello" result))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-multiline-value ()
|
|
||||||
"Test multiline code value evaluation."
|
|
||||||
(skip-unless (executable-find ob-elixir-command))
|
|
||||||
(let ((result (ob-elixir--execute "x = 10\ny = 20\nx + y" 'value)))
|
|
||||||
(should (equal "30" result))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-list-result ()
|
|
||||||
"Test list result."
|
|
||||||
(skip-unless (executable-find ob-elixir-command))
|
|
||||||
(let ((result (ob-elixir--execute "[1, 2, 3]" 'value)))
|
|
||||||
(should (equal "[1, 2, 3]" result))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-map-result ()
|
|
||||||
"Test map result."
|
|
||||||
(skip-unless (executable-find ob-elixir-command))
|
|
||||||
(let ((result (ob-elixir--execute "%{a: 1, b: 2}" 'value)))
|
|
||||||
;; Maps are unordered in Elixir, so accept either order
|
|
||||||
(should (or (string-match-p "%{a: 1, b: 2}" result)
|
|
||||||
(string-match-p "%{b: 2, a: 1}" result)))))
|
|
||||||
|
|
||||||
;;; Type Conversion Tests
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-convert-nil ()
|
|
||||||
"Test nil conversion."
|
|
||||||
(should (equal "nil" (ob-elixir--elisp-to-elixir nil))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-convert-true ()
|
|
||||||
"Test t conversion."
|
|
||||||
(should (equal "true" (ob-elixir--elisp-to-elixir t))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-convert-integer ()
|
|
||||||
"Test integer conversion."
|
|
||||||
(should (equal "42" (ob-elixir--elisp-to-elixir 42)))
|
|
||||||
(should (equal "-10" (ob-elixir--elisp-to-elixir -10))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-convert-float ()
|
|
||||||
"Test float conversion."
|
|
||||||
(should (equal "3.14" (ob-elixir--elisp-to-elixir 3.14))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-convert-string ()
|
|
||||||
"Test string conversion."
|
|
||||||
(should (equal "\"hello\"" (ob-elixir--elisp-to-elixir "hello"))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-convert-string-escaping ()
|
|
||||||
"Test string escaping."
|
|
||||||
(should (equal "\"say \\\"hi\\\"\""
|
|
||||||
(ob-elixir--elisp-to-elixir "say \"hi\"")))
|
|
||||||
(should (equal "\"line1\\nline2\""
|
|
||||||
(ob-elixir--elisp-to-elixir "line1\nline2"))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-convert-symbol ()
|
|
||||||
"Test symbol conversion to atom."
|
|
||||||
(should (equal ":foo" (ob-elixir--elisp-to-elixir 'foo)))
|
|
||||||
(should (equal ":ok" (ob-elixir--elisp-to-elixir 'ok))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-convert-list ()
|
|
||||||
"Test list conversion."
|
|
||||||
(should (equal "[1, 2, 3]" (ob-elixir--elisp-to-elixir '(1 2 3))))
|
|
||||||
(should (equal "[\"a\", \"b\"]" (ob-elixir--elisp-to-elixir '("a" "b")))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-convert-nested-list ()
|
|
||||||
"Test nested list conversion."
|
|
||||||
(should (equal "[[1, 2], [3, 4]]"
|
|
||||||
(ob-elixir--elisp-to-elixir '((1 2) (3 4))))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-convert-vector ()
|
|
||||||
"Test vector to tuple conversion."
|
|
||||||
(should (equal "{1, 2, 3}" (ob-elixir--elisp-to-elixir [1 2 3]))))
|
|
||||||
|
|
||||||
;;; Variable Injection Tests
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-variable-assignments ()
|
|
||||||
"Test variable assignment generation."
|
|
||||||
(let ((params '((:var . ("x" . 5))
|
|
||||||
(:var . ("name" . "Alice")))))
|
|
||||||
(let ((assignments (org-babel-variable-assignments:elixir params)))
|
|
||||||
(should (member "x = 5" assignments))
|
|
||||||
(should (member "name = \"Alice\"" assignments)))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-var-execution ()
|
|
||||||
"Test code execution with variables."
|
|
||||||
(skip-unless (executable-find ob-elixir-command))
|
|
||||||
(let* ((params '((:var . ("x" . 10))))
|
|
||||||
(var-lines (org-babel-variable-assignments:elixir params))
|
|
||||||
(full-body (concat (mapconcat #'identity var-lines "\n")
|
|
||||||
"\nx * 2")))
|
|
||||||
(should (equal "20" (ob-elixir--execute full-body 'value)))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-var-list ()
|
|
||||||
"Test passing list as variable."
|
|
||||||
(skip-unless (executable-find ob-elixir-command))
|
|
||||||
(let* ((params '((:var . ("data" . (1 2 3)))))
|
|
||||||
(var-lines (org-babel-variable-assignments:elixir params))
|
|
||||||
(full-body (concat (mapconcat #'identity var-lines "\n")
|
|
||||||
"\nEnum.sum(data)")))
|
|
||||||
(should (equal "6" (ob-elixir--execute full-body 'value)))))
|
|
||||||
|
|
||||||
;;; Error Handling Tests
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-detect-runtime-error ()
|
|
||||||
"Test runtime error detection."
|
|
||||||
(let ((output "** (RuntimeError) something went wrong"))
|
|
||||||
(let ((error-info (ob-elixir--detect-error output)))
|
|
||||||
(should error-info)
|
|
||||||
(should (eq 'runtime (plist-get error-info :type)))
|
|
||||||
(should (equal "RuntimeError" (plist-get error-info :error-type))))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-detect-compile-error ()
|
|
||||||
"Test compile error detection."
|
|
||||||
(let ((output "** (CompileError) test.exs:1: undefined function foo/0"))
|
|
||||||
(let ((error-info (ob-elixir--detect-error output)))
|
|
||||||
(should error-info)
|
|
||||||
(should (eq 'compile (plist-get error-info :type)))
|
|
||||||
(should (equal "CompileError" (plist-get error-info :error-type))))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-no-error ()
|
|
||||||
"Test that valid output is not detected as error."
|
|
||||||
(should-not (ob-elixir--detect-error "42"))
|
|
||||||
(should-not (ob-elixir--detect-error "[1, 2, 3]"))
|
|
||||||
(should-not (ob-elixir--detect-error "\"hello\"")))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-error-execution ()
|
|
||||||
"Test that errors are properly handled during execution."
|
|
||||||
(skip-unless (executable-find ob-elixir-command))
|
|
||||||
(let ((ob-elixir-signal-errors nil))
|
|
||||||
(let ((result (ob-elixir--execute "raise \"test error\"" 'value)))
|
|
||||||
(should (string-match-p "RuntimeError" result)))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-error-signaling ()
|
|
||||||
"Test that errors are signaled when configured."
|
|
||||||
(skip-unless (executable-find ob-elixir-command))
|
|
||||||
(let ((ob-elixir-signal-errors t))
|
|
||||||
(should-error (ob-elixir--execute "raise \"test error\"" 'value)
|
|
||||||
:type 'ob-elixir-runtime-error)))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-undefined-function ()
|
|
||||||
"Test handling of undefined function error."
|
|
||||||
(skip-unless (executable-find ob-elixir-command))
|
|
||||||
(let ((ob-elixir-signal-errors nil))
|
|
||||||
(let ((result (ob-elixir--execute "undefined_function()" 'value)))
|
|
||||||
(should (string-match-p "\\(UndefinedFunctionError\\|CompileError\\)" result)))))
|
|
||||||
|
|
||||||
;;; Result Formatting Tests
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-parse-simple-list ()
|
|
||||||
"Test parsing simple list result."
|
|
||||||
(should (equal '(1 2 3) (ob-elixir--table-or-string "[1, 2, 3]"))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-parse-nested-list ()
|
|
||||||
"Test parsing nested list (table) result."
|
|
||||||
(should (equal '((1 2) (3 4))
|
|
||||||
(ob-elixir--table-or-string "[[1, 2], [3, 4]]"))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-parse-tuple ()
|
|
||||||
"Test parsing tuple result."
|
|
||||||
(should (equal '(1 2 3) (ob-elixir--table-or-string "{1, 2, 3}"))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-parse-scalar ()
|
|
||||||
"Test that scalars are returned as strings."
|
|
||||||
(should (equal "42" (ob-elixir--table-or-string "42")))
|
|
||||||
(should (equal ":ok" (ob-elixir--table-or-string ":ok"))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-parse-string ()
|
|
||||||
"Test parsing string result."
|
|
||||||
(should (equal "\"hello\"" (ob-elixir--table-or-string "\"hello\""))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-sanitize-table-nil ()
|
|
||||||
"Test that nil values are sanitized in tables."
|
|
||||||
(let ((ob-elixir-nil-to 'hline))
|
|
||||||
(should (equal '((1 hline) (hline 2))
|
|
||||||
(ob-elixir--sanitize-table '((1 nil) (nil 2)))))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-execution-returns-table ()
|
|
||||||
"Test that list results become tables."
|
|
||||||
(skip-unless (executable-find ob-elixir-command))
|
|
||||||
(let ((result (ob-elixir--table-or-string
|
|
||||||
(ob-elixir--execute "[[1, 2], [3, 4]]" 'value))))
|
|
||||||
(should (equal '((1 2) (3 4)) result))))
|
|
||||||
|
|
||||||
(ert-deftest ob-elixir-test-mixed-list ()
|
|
||||||
"Test parsing mixed-type list."
|
|
||||||
(skip-unless (executable-find ob-elixir-command))
|
|
||||||
(let ((result (ob-elixir--table-or-string
|
|
||||||
(ob-elixir--execute "[1, \"two\", :three]" 'value))))
|
|
||||||
(should (listp result))
|
|
||||||
(should (= 3 (length result)))))
|
|
||||||
|
|
||||||
(provide 'test-ob-elixir)
|
(provide 'test-ob-elixir)
|
||||||
;;; test-ob-elixir.el ends here
|
;;; test-ob-elixir.el ends here
|
||||||
|
|||||||
Reference in New Issue
Block a user