diff options
author | nea <nea@nea.moe> | 2023-08-11 02:26:00 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-08-11 02:26:00 +0200 |
commit | 69f8367389c9d6f60ca594053d9d470e5a8ec999 (patch) | |
tree | 4fe2d341ca9ec9b8aaa0ec5cb18c53bf63265844 /src/OutputCapture.kt | |
parent | 912c9918d9a5afbfb023b650bed6e2754f030d5e (diff) | |
download | nealisp-69f8367389c9d6f60ca594053d9d470e5a8ec999.tar.gz nealisp-69f8367389c9d6f60ca594053d9d470e5a8ec999.tar.bz2 nealisp-69f8367389c9d6f60ca594053d9d470e5a8ec999.zip |
Add output capture and more test reports
Diffstat (limited to 'src/OutputCapture.kt')
-rw-r--r-- | src/OutputCapture.kt | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/OutputCapture.kt b/src/OutputCapture.kt new file mode 100644 index 0000000..7fc8849 --- /dev/null +++ b/src/OutputCapture.kt @@ -0,0 +1,23 @@ +package moe.nea.lisp + +object OutputCapture { + data class CapturedOutput( + internal var string: StringBuilder, + ) { + val asString get() = string.toString() + } + + object Meta : StackFrame.MetaKey<CapturedOutput> + + fun captureOutput(stackFrame: StackFrame): CapturedOutput { + val output = CapturedOutput(StringBuilder()) + stackFrame.setMeta(Meta, output) + return output + } + + fun print(stackFrame: StackFrame, text: String) { + val output = stackFrame.getMeta(Meta) + output?.string?.append(text) + print(text) + } +}
\ No newline at end of file |