diff options
Diffstat (limited to 'stdlib/source/test/lux/debug.lux')
-rw-r--r-- | stdlib/source/test/lux/debug.lux | 75 |
1 files changed, 69 insertions, 6 deletions
diff --git a/stdlib/source/test/lux/debug.lux b/stdlib/source/test/lux/debug.lux index 1612f17b4..a41f52a8d 100644 --- a/stdlib/source/test/lux/debug.lux +++ b/stdlib/source/test/lux/debug.lux @@ -1,11 +1,15 @@ (.require [library [lux (.except) + ["[0]" ffi] [abstract [monad (.only do)]] [control ["[0]" try (.use "[1]#[0]" functor)] - ["[0]" exception]] + ["[0]" exception] + ["[0]" io] + [concurrency + ["[0]" atom]]] [data ["[0]" text (.use "[1]#[0]" equivalence) ["%" \\format (.only format)]] @@ -231,11 +235,71 @@ (type My_Text Text) +(for @.jvm (these (ffi.import java/lang/String + "[1]::[0]") + + (ffi.import java/io/ByteArrayOutputStream + "[1]::[0]" + (new []) + (toString [] java/lang/String)) + + (ffi.import java/io/OutputStream + "[1]::[0]") + + (ffi.import java/io/PrintStream + "[1]::[0]" + (new [java/io/OutputStream])) + + (ffi.import java/lang/System + "[1]::[0]" + ("static" out java/io/PrintStream) + ("static" setOut [java/io/PrintStream] void)) + + (def system_output + java/io/PrintStream + (io.run! (java/lang/System::out)))) + @.js (these (ffi.import console + "[1]::[0]" + ("static" log (-> Text Any)))) + @.python (these (ffi.import io/StringIO + "[1]::[0]" + (new []) + (getvalue [] Text)) + + (ffi.import sys + "[1]::[0]" + ("static" stdout io/StringIO)))) + +(def with_out + (template (_ <body>) + [(for @.jvm (ffi.synchronized ..system_output + (let [buffer (java/io/ByteArrayOutputStream::new) + _ (java/lang/System::setOut (java/io/PrintStream::new buffer)) + output <body> + _ (java/lang/System::setOut ..system_output)] + [(ffi.of_string (java/io/ByteArrayOutputStream::toString buffer)) + output])) + @.js (let [old (io.run! (console::log)) + buffer (atom.atom "") + _ (io.run! (console::log (function (_ it) + (io.run! (atom.write! (format it text.\n) buffer))))) + output <body> + _ (io.run! (console::log old))] + [(io.run! (atom.read! buffer)) + output]) + @.python (let [old (io.run! (sys::stdout)) + buffer (io/StringIO::new []) + _ (io.run! (sys::stdout buffer)) + output <body> + _ (io.run! (sys::stdout old))] + [(io/StringIO::getvalue buffer) + output]))])) + (def .public test Test (<| (_.covering /._) (do random.monad - [message (random.lower_case 5)] + [expected_message (random.lower_case 5)] (all _.and ..inspection ..representation @@ -264,8 +328,7 @@ /.inspection) true)) (_.coverage [/.log!] - (exec - (/.log! (format (%.symbol (symbol /.log!)) - " works: " (%.text message))) - true)) + (let [[actual_message _] (with_out (/.log! expected_message))] + (text#= (format expected_message text.\n) + actual_message))) )))) |