mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
core: add assert-signal
This commit is contained in:
parent
a55c953396
commit
99fb38de73
@ -18,5 +18,12 @@
|
||||
(register fork (Fn [] Int) "fork")
|
||||
(register wait (Fn [(Ptr Int)] Int) "wait")
|
||||
(register get-exit-status (Fn [Int] Int) "WEXITSTATUS")
|
||||
(register signal (Fn [Int (Fn [Int] ())] ()) "signal")
|
||||
(register signal-abort Int "SIGABRT")
|
||||
(register signal-fpe Int "SIGFPE")
|
||||
(register signal-ill Int "SIGILL")
|
||||
(register signal-int Int "SIGINT")
|
||||
(register signal-segv Int "SIGSEGV")
|
||||
(register signal-term Int "SIGTERM")
|
||||
)
|
||||
|
||||
|
@ -81,14 +81,37 @@
|
||||
(let [pid (System.fork)
|
||||
status 0]
|
||||
(if (= pid 0)
|
||||
(x)
|
||||
(do
|
||||
(x)
|
||||
0)
|
||||
(do
|
||||
(ignore (System.wait (address status)))
|
||||
(System.get-exit-status status)))))
|
||||
|
||||
(defn assert-fails [state exit-code x descr]
|
||||
(defn handle-signal [x] (System.exit x))
|
||||
|
||||
(defn run-child-signals [x]
|
||||
(let [pid (System.fork)
|
||||
status 0]
|
||||
(if (= pid 0)
|
||||
(do
|
||||
(System.signal System.signal-abort handle-signal)
|
||||
(System.signal System.signal-fpe handle-signal)
|
||||
(System.signal System.signal-ill handle-signal)
|
||||
(System.signal System.signal-segv handle-signal)
|
||||
(System.signal System.signal-term handle-signal)
|
||||
(x)
|
||||
0)
|
||||
(do
|
||||
(ignore (System.wait (address status)))
|
||||
(System.get-exit-status status)))))
|
||||
|
||||
(defn assert-exit [state exit-code x descr]
|
||||
(assert-equal state exit-code (run-child x) descr))
|
||||
|
||||
(defn assert-signal [state signal x descr]
|
||||
(assert-equal state signal (run-child-signals x) descr))
|
||||
|
||||
(defn print-test-results [state]
|
||||
(let [passed @(State.passed state)
|
||||
failed @(State.failed state)]
|
||||
|
Loading…
Reference in New Issue
Block a user