Skip to content

Commit

Permalink
Fix tests by removing circular dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
arnav-ag committed Apr 14, 2024
1 parent 624b807 commit 1825c2c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
23 changes: 23 additions & 0 deletions src/server/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
let heaps = [];
let stacks = [];

export const appendHeap = heap => {
heaps.push(heap);
};

export const appendStack = stack => {
stacks.push(stack);
};

export const resetHeapsAndStacks = () => {
heaps = [];
stacks = [];
};

export const getHeaps = () => {
return heaps;
};

export const getStacks = () => {
return stacks;
};
8 changes: 4 additions & 4 deletions src/server/runOogaLang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { run } from '../vm/oogavm-machine.js';
import debug from 'debug';
import { readFileSync } from 'fs';
import { prepare_and_compile } from '../vm/oogavm-toolchain.js';
import { getHeaps, getStacks, resetHeapsAndStacks } from './debug.js';

const log = debug('ooga:runOogaLang');
const standardSource = readFileSync('std/ooga-std.ooga', 'utf8');
Expand All @@ -27,8 +28,7 @@ export function runOogaLangCode(
code: string
): Promise<{ capturedOutput: string; heaps: any[]; stacks: any[] }> {
log(code);
heaps = [];
stacks = [];
resetHeapsAndStacks();
return new Promise((resolve, reject) => {
// Redirect console.log to capture output
const originalConsoleLog = console.log;
Expand All @@ -48,8 +48,8 @@ export function runOogaLangCode(
capturedOutput += 'Output: ' + value + '\n';
// Restore console.log
console.log = originalConsoleLog;
console.log(heaps);
console.log(stacks);
const heaps = getHeaps();
const stacks = getStacks();
// Resolve the promise with the captured output
resolve({ capturedOutput, heaps, stacks });
} catch (error: any) {
Expand Down
3 changes: 1 addition & 2 deletions src/vm/oogavm-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ import {
Undefined,
} from './oogavm-heap.js';
import { OogaError } from './oogavm-errors.js';
import { stringify } from 'querystring';
import { unparse } from '../utils/utils.js';
import { appendHeap, appendStack, heaps, stacks } from '../server/runOogaLang.js';
import { appendHeap, appendStack } from '../server/debug.js';

const log = debug('ooga:vm');

Expand Down

0 comments on commit 1825c2c

Please sign in to comment.