erlang: exit/1 + process termination (+9 tests)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-24 21:34:21 +00:00
parent e2e801e38a
commit 97513e5b96
4 changed files with 83 additions and 1 deletions

View File

@@ -400,6 +400,38 @@
(ev "Me = self(), Me ! first, Me ! second, X = receive second -> got_second after 0 -> to end, Y = receive first -> got_first after 0 -> to end, {X, Y}")
(er-mk-tuple (list (er-mk-atom "got_second") (er-mk-atom "got_first"))))
;; ── exit/1 + process termination ─────────────────────────────────
(er-eval-test "exit normal returns nil" (ev "exit(normal)") nil)
(er-eval-test "exit normal reason"
(do (ev "exit(normal)") (nm (er-last-main-exit-reason))) "normal")
(er-eval-test "exit bye reason"
(do (ev "exit(bye)") (nm (er-last-main-exit-reason))) "bye")
(er-eval-test "exit tuple reason"
(do (ev "exit({shutdown, crash})")
(get (er-last-main-exit-reason) :tag))
"tuple")
(er-eval-test "normal completion reason"
(do (ev "42") (nm (er-last-main-exit-reason))) "normal")
(er-eval-test "exit aborts subsequent"
(do (er-io-flush!) (ev "io:format(\"a~n\"), exit(bye), io:format(\"b~n\")") (er-io-buffer-content))
"a\n")
(er-eval-test "child exit doesn't kill parent"
(do
(er-io-flush!)
(ev "spawn(fun () -> io:format(\"before~n\"), exit(quit), io:format(\"after~n\") end), io:format(\"main~n\")")
(er-io-buffer-content))
"main\nbefore\n")
(er-eval-test "child exit reason recorded on child"
(do
(er-io-flush!)
(ev "P = spawn(fun () -> exit(child_bye) end), io:format(\"~p\", [is_pid(P)])")
(er-io-buffer-content))
"true")
(er-eval-test "exit inside fn chain"
(do (ev "F = fun () -> exit(from_fn) end, F()")
(nm (er-last-main-exit-reason)))
"from_fn")
(define
er-eval-test-summary
(str "eval " er-eval-test-pass "/" er-eval-test-count))