tasks/04-error-handling.md done

This commit is contained in:
2026-01-24 17:36:22 +01:00
parent af9cb22209
commit 879ffd08e7
2 changed files with 159 additions and 7 deletions

View File

@@ -131,5 +131,50 @@
"\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)))))
(provide 'test-ob-elixir)
;;; test-ob-elixir.el ends here