diff --git a/src/stepper/__tests__/__snapshots__/stepper.ts.snap b/src/stepper/__tests__/__snapshots__/stepper.ts.snap index bc6f585b4..56f93aa86 100644 --- a/src/stepper/__tests__/__snapshots__/stepper.ts.snap +++ b/src/stepper/__tests__/__snapshots__/stepper.ts.snap @@ -2095,6 +2095,8 @@ false ? 1 : 100 * factorial(100 - 1); " `; +exports[`Evaluation of empty code and imports Evaluate empty program 1`] = `""`; + exports[`Infinite recursion 1`] = ` "function f() { return f(); diff --git a/src/stepper/__tests__/stepper.ts b/src/stepper/__tests__/stepper.ts index ca116b6d1..bb8e20f4c 100644 --- a/src/stepper/__tests__/stepper.ts +++ b/src/stepper/__tests__/stepper.ts @@ -1433,6 +1433,16 @@ describe(`#1342: Test the fix of #1341: Stepper limit off by one`, () => { }) }) +describe(`Evaluation of empty code and imports`, () => { + test('Evaluate empty program', () => { + const code = `` + const program = parse(code, mockContext())! + const steps = getEvaluationSteps(program, mockContext(), 1000) + expect(steps.map(x => codify(x[0])).join('\n')).toMatchSnapshot() + expect(getLastStepAsString(steps)).toEqual('') + }) +}) + // describe(`#1223: Stepper: Import statements cause errors`, () => { // test('import a module and invoke its functions', () => { // const code = ` diff --git a/src/stepper/stepper.ts b/src/stepper/stepper.ts index 5fe6023f4..c14d706e0 100644 --- a/src/stepper/stepper.ts +++ b/src/stepper/stepper.ts @@ -3383,9 +3383,12 @@ export function getEvaluationSteps( reducedWithPath = reduceMain(reducedWithPath[0], context) i += 2 } - if (!limitExceeded) { + if (!limitExceeded && steps.length > 0) { steps[steps.length - 1][2] = 'Evaluation complete' } + if (steps.length === 0) { + steps.push([reducedWithPath[0] as es.Program, [], 'Nothing to evaluate']) + } return steps } catch (error) { context.errors.push(error)