From f8d5060500fe46b323e49de9351097b331d45943 Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Sun, 2 Feb 2020 17:19:20 +0000 Subject: [PATCH] add system.print() This ensures that contracts using system.print won't break, and that there is some mechanism for outputting to the logs and STDOUT. Test suites which wish to avoid this can stub system.print, e.g. system.print = function(msg) end or function stubPrint() system.origPrint = system.print system.print = function(msg) printOutput[#printOutput + 1] = msg -- We don't have the table library -- table.insert(printOutput, msg) end end function showPrintOutput() system.origPrint("captured:") for i, line in pairs(printOutput) do system.origPrint(line) end system.origPrint("--------") end function assertOutputContains(pattern) for i, line in pairs(printOutput) do if string.match(line, pattern) then return true end end error("Output did not contain '" .. pattern .. "'") end function resetOutputCapture() printOutput = {} end --- core/src/main/java/ship/test/AergoMock.java | 9 +++++++++ core/src/main/java/ship/test/Athena.java | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/ship/test/AergoMock.java b/core/src/main/java/ship/test/AergoMock.java index 9be5ebd..722138d 100644 --- a/core/src/main/java/ship/test/AergoMock.java +++ b/core/src/main/java/ship/test/AergoMock.java @@ -40,4 +40,13 @@ public LuaValue call(LuaValue name, LuaValue value) { } }; + public OneArgFunction print = new OneArgFunction() { + @Override + public LuaValue call(LuaValue msg) { + System.out.println(msg.tojstring()); + logger.info(msg.tojstring()); + return NIL; + } + }; + } diff --git a/core/src/main/java/ship/test/Athena.java b/core/src/main/java/ship/test/Athena.java index 0e1bcf5..d97bf90 100644 --- a/core/src/main/java/ship/test/Athena.java +++ b/core/src/main/java/ship/test/Athena.java @@ -31,8 +31,9 @@ public LuaValue call(final LuaValue modname, final LuaValue env) { final LuaValue system = tableOf(); system.set("getItem", aergoMock.getItem); system.set("setItem", aergoMock.setItem); - + system.set("print", aergoMock.print); env.set("system", system); + return library; } }