From a83167bfe8990975cee4157308fb8801ed8a0ab5 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Tue, 2 Jul 2019 22:05:05 -0700 Subject: [PATCH] Add first integration test --- experiments/maki-interpreter/cli.js | 2 +- experiments/maki-interpreter/interpreter.js | 6 ++-- .../maki-interpreter/interpreter.test.js | 32 ++++++++++++++++++ .../v1.1.1.b3 (Winamp 3.0 full)/hello_world.m | 7 ++++ .../hello_world.maki | Bin 0 -> 843 bytes .../maki-interpreter/runtime/System.js | 4 +-- .../maki-interpreter/virtualMachine.js | 4 +-- 7 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 experiments/maki-interpreter/interpreter.test.js create mode 100755 experiments/maki-interpreter/reference/maki_compiler/v1.1.1.b3 (Winamp 3.0 full)/hello_world.m create mode 100755 experiments/maki-interpreter/reference/maki_compiler/v1.1.1.b3 (Winamp 3.0 full)/hello_world.maki diff --git a/experiments/maki-interpreter/cli.js b/experiments/maki-interpreter/cli.js index 55e084f1..9bf68417 100755 --- a/experiments/maki-interpreter/cli.js +++ b/experiments/maki-interpreter/cli.js @@ -10,7 +10,7 @@ function main() { const relativePath = process.argv[2]; const buffer = fs.readFileSync(path.join(__dirname, relativePath)); const system = new System(); - run({ runtime, buffer, system }); + run({ runtime, buffer, system, log: true }); } main(); diff --git a/experiments/maki-interpreter/interpreter.js b/experiments/maki-interpreter/interpreter.js index 166da474..f5c0ad68 100644 --- a/experiments/maki-interpreter/interpreter.js +++ b/experiments/maki-interpreter/interpreter.js @@ -2,7 +2,7 @@ const parse = require("./parser"); const { getClass } = require("./objects"); const interpret = require("./virtualMachine"); -function main({ runtime, buffer, system }) { +function main({ runtime, buffer, system, log }) { const program = parse(buffer); // Set the System global @@ -11,7 +11,7 @@ function main({ runtime, buffer, system }) { // Replace class hashes with actual JavaScript classes from the runtime program.classes = program.classes.map(hash => { const resolved = runtime[hash]; - if (resolved == null) { + if (resolved == null && log) { const klass = getClass(hash); console.warn( `Class missing from runtime: ${hash} expected ${klass.name}` @@ -23,7 +23,7 @@ function main({ runtime, buffer, system }) { // Bind toplevel handlers. program.bindings.forEach(binding => { const handler = () => { - return interpret(binding.commandOffset, program); + return interpret(binding.commandOffset, program, { log }); }; // For now we only know how to handle System handlers. diff --git a/experiments/maki-interpreter/interpreter.test.js b/experiments/maki-interpreter/interpreter.test.js new file mode 100644 index 00000000..f6e48cde --- /dev/null +++ b/experiments/maki-interpreter/interpreter.test.js @@ -0,0 +1,32 @@ +const fs = require("fs"); +const path = require("path"); +const System = require("./runtime/System"); +const runtime = require("./runtime"); +const interpret = require("./interpreter"); + +function runFile(relativePath) { + const system = new System(); + const buffer = fs.readFileSync(path.join(__dirname, relativePath)); + interpret({ runtime, buffer, system, log: false }); +} + +describe("v1.1.1.b3 (Winamp 3.0 full)", () => { + test("can call messageBox with hello World", () => { + const mockMessageBox = jest.fn(); + // The VM depends upon the arity of this function, so we can't use + // `mockMessageBox` directly. + System.prototype.messageBox = function(a, b, c, d) { + mockMessageBox(a, b, c, d); + }; + runFile( + "./reference/maki_compiler/v1.1.1.b3 (Winamp 3.0 full)/hello_world.maki" + ); + expect(mockMessageBox).toHaveBeenCalledTimes(1); + expect(mockMessageBox).toHaveBeenCalledWith( + "Hello World", + "Hello Title", + 1, + null + ); + }); +}); diff --git a/experiments/maki-interpreter/reference/maki_compiler/v1.1.1.b3 (Winamp 3.0 full)/hello_world.m b/experiments/maki-interpreter/reference/maki_compiler/v1.1.1.b3 (Winamp 3.0 full)/hello_world.m new file mode 100755 index 00000000..4075b023 --- /dev/null +++ b/experiments/maki-interpreter/reference/maki_compiler/v1.1.1.b3 (Winamp 3.0 full)/hello_world.m @@ -0,0 +1,7 @@ +#include "lib/std.mi" + +System.onScriptLoaded() +{ + String response; + System.messageBox("Hello World", "Hello Title", 1, response); +} \ No newline at end of file diff --git a/experiments/maki-interpreter/reference/maki_compiler/v1.1.1.b3 (Winamp 3.0 full)/hello_world.maki b/experiments/maki-interpreter/reference/maki_compiler/v1.1.1.b3 (Winamp 3.0 full)/hello_world.maki new file mode 100755 index 0000000000000000000000000000000000000000..237bcb6c01775974f81dc8b681c999eb99917620 GIT binary patch literal 843 zcmZ>BXJ!#+U|>)K;zG~Vz;@n1uZfSBZ8b9e{5*yK>$P8#w|h?hxGU}bI=dOwM|fZI zwmkRRpu@s_sr37w1tkX<7X4e`xv%%v?%QHw4qL65Hu*X)^xn5FGP#ub^RZO31Pf`m zcXiipj_qAI!{lb?O{*BdKpR`;(n}6+olJceTrsswO zE28xd@A+#Vw=F5oyw{=kRav9gPU-S})BVqFD3|n`8Fpoc@yQ%@UWG#|UI%J<@2ZdW zJ{Id!Xt7JKcbe>rZy)4DP! z`n0!;(cjuY^BTYX4o&Ogt?n3${@NK;J1g9E^@-H*Wyfk(p1s?bDcAqTf40z1m!F*f zUDeN~WUEDa`}9OUTh8;%)9U~EJ6rxWp7EY0UBrKNAOHV{J&zb8H(V8*KL5$R{J=7< zy+1xQER|m7v|zH4*#e$kuh@#yXFoLtJN2_B?kLi*`6X?lH+x3TFNf|{9_hRnQ&B8OqcH3x|#K~@7jaUBrf%5Ogs2b zGjaQ^K;Ma}jHh^{3vPcGnR?ai?F-i#{Punef^=>+d0Wq}O5=0t|5NEG+AxRdgkhWP zg@#G)^JnahHQO@LY^LGcwY>d+ES;YiQV~mUp415gvdBMp=nFS?2`H3m1 zDIhT}hTPQR;>7e+r~C>ws5&4828@g#oiM=20Fp-ld_1s?aHSv~GZ1q#c%