Add first integration test

This commit is contained in:
Jordan Eldredge 2019-07-02 22:05:05 -07:00
parent e0210fb5c1
commit a83167bfe8
7 changed files with 47 additions and 8 deletions

View file

@ -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();

View file

@ -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.

View file

@ -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
);
});
});

View file

@ -0,0 +1,7 @@
#include "lib/std.mi"
System.onScriptLoaded()
{
String response;
System.messageBox("Hello World", "Hello Title", 1, response);
}

View file

@ -35,8 +35,8 @@ class System extends MakiObject {
getParam() {
return "Some String";
}
messagebox(message, var2, var3, var4) {
alert(message);
messageBox(message, msgtitle, flag, notanymoreId) {
console.log({ message, msgtitle, flag, notanymoreId });
}
}

View file

@ -1,7 +1,7 @@
const { printCommand } = require("./prettyPrinter");
const log = true;
function interpret(start, { commands, methods, variables, classes }) {
function interpret(start, program, { log = false }) {
const { commands, methods, variables, classes } = program;
// Run all the commands that are safe to run. Increment this number to find
// the next bug.
const stack = [];