erlang: spawn/1 + self/0 + is_pid (+13 tests)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-24 19:50:09 +00:00
parent bc1a69925e
commit 266693a2f6
4 changed files with 133 additions and 4 deletions

View File

@@ -285,6 +285,48 @@
(do (er-io-flush!) (ev "io:format(\"50~~\")") (er-io-buffer-content))
"50~")
;; ── processes: self/0, spawn/1, is_pid ──────────────────────────
(er-eval-test "self tag"
(get (ev "self()") :tag) "pid")
(er-eval-test "is_pid self"
(nm (ev "is_pid(self())")) "true")
(er-eval-test "is_pid number"
(nm (ev "is_pid(42)")) "false")
(er-eval-test "is_pid atom"
(nm (ev "is_pid(ok)")) "false")
(er-eval-test "self equals self"
(nm (ev "Pid = self(), Pid =:= Pid")) "true")
(er-eval-test "self =:= self expr"
(nm (ev "self() == self()")) "true")
(er-eval-test "spawn returns pid"
(get (ev "spawn(fun () -> ok end)") :tag) "pid")
(er-eval-test "is_pid spawn"
(nm (ev "is_pid(spawn(fun () -> ok end))")) "true")
(er-eval-test "spawn new pid distinct"
(nm (ev "P1 = self(), P2 = spawn(fun () -> ok end), P1 =:= P2"))
"false")
(er-eval-test "two spawns distinct"
(nm (ev "P1 = spawn(fun () -> ok end), P2 = spawn(fun () -> ok end), P1 =:= P2"))
"false")
(er-eval-test "spawn then drain io"
(do
(er-io-flush!)
(ev "spawn(fun () -> io:format(\"child~n\") end), io:format(\"parent~n\")")
(er-io-buffer-content))
"parent\nchild\n")
(er-eval-test "multiple spawn ordering"
(do
(er-io-flush!)
(ev "spawn(fun () -> io:format(\"a~n\") end), spawn(fun () -> io:format(\"b~n\") end), io:format(\"main~n\")")
(er-io-buffer-content))
"main\na\nb\n")
(er-eval-test "child self is its own pid"
(do
(er-io-flush!)
(ev "P = spawn(fun () -> io:format(\"~p\", [is_pid(self())]) end), io:format(\"~p;\", [is_pid(P)])")
(er-io-buffer-content))
"true;true")
(define
er-eval-test-summary
(str "eval " er-eval-test-pass "/" er-eval-test-count))