Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix evaluation error when no evaluation code is provided #1472

Merged
merged 4 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/stepper/__tests__/__snapshots__/stepper.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions src/stepper/__tests__/stepper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand Down
5 changes: 4 additions & 1 deletion src/stepper/stepper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading