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

Output the execution stack on undefined values in REPL #1056

Merged
merged 4 commits into from
Jul 18, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## UNRELEASED

### Added

- `quint repl` produces an evaluation trace on errors too (#1056)

### Changed

- `quint run` produces a friendlier message when it meets a `const` (#1050)
Expand Down
1 change: 1 addition & 0 deletions quint/io-cli-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ exit $exit_code


Use --verbosity=3 to show executions.
HOME/failingTestCounters.qnt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is HOME here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a placeholder for a path, so we do not have to use a real path in the test output

```

### test counters produces no execution
Expand Down
3 changes: 2 additions & 1 deletion quint/src/cliCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ export async function runTests(prev: TypecheckedStage): Promise<CLIProcedure<Tes
}

if (failed.length > 0 && verbosity.hasHints(options.verbosity) && !verbosity.hasActionTracking(options.verbosity)) {
out(chalk.gray('\n Use --verbosity=3 to show executions.'))
out(chalk.gray(`\n Use --verbosity=3 to show executions.`))
out(chalk.gray(` Further debug with: quint --verbosity=3 ${prev.args.input}`))
}
}

Expand Down
28 changes: 15 additions & 13 deletions quint/src/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ function countBraces(str: string): [number, number, number] {
function evalExpr(state: ReplState, out: writer): Either<string, QuintEx> {
const computable = contextNameLookup(state.evaluationState.context, 'q::input', 'callable')
const columns = terminalWidth()
return computable
const result = computable
.mapRight(comp => {
return comp
.eval()
Expand All @@ -708,18 +708,6 @@ function evalExpr(state: ReplState, out: writer): Either<string, QuintEx> {
out(format(columns, 0, prettyQuintEx(ex)))
out('\n')

if (verbosity.hasUserOpTracking(state.verbosity)) {
const trace = state.recorder.getBestTrace()
if (trace.subframes.length > 0) {
out('\n')
trace.subframes.forEach((f, i) => {
out(`[Frame ${i}]\n`)
printExecutionFrameRec({ width: columns, out }, f, [])
out('\n')
})
}
}

if (ex.kind === 'bool' && ex.value) {
// A Boolean expression may be an action or a run.
// Save the state, if there were any updates to variables.
Expand All @@ -735,6 +723,20 @@ function evalExpr(state: ReplState, out: writer): Either<string, QuintEx> {
.unwrap()
})
.join()

if (verbosity.hasUserOpTracking(state.verbosity)) {
const trace = state.recorder.getBestTrace()
if (trace.subframes.length > 0) {
out('\n')
trace.subframes.forEach((f, i) => {
out(`[Frame ${i}]\n`)
printExecutionFrameRec({ width: columns, out }, f, [])
out('\n')
})
}
}

return result
}

function getMainModuleAnnotation(moduleHist: string): string | undefined {
Expand Down
28 changes: 28 additions & 0 deletions quint/test/repl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,34 @@ describe('repl ok', () => {
await assertRepl(input, output)
})

it('change verbosity and show execution on failure', async () => {
const input = dedent(
`pure def div(x, y) = x / y
|.verbosity=4
|div(2, 0)
|`
)
const output = dedent(
`>>> pure def div(x, y) = x / y
|
|>>> .verbosity=4
|.verbosity=4
|>>> div(2, 0)
|
|[Frame 0]
|q::input() => none
|└─ div(2, 0) => none
|
|runtime error: error: Division by zero
|div(2, 0)
| ^^^^^
|
|<undefined value>
|>>> `
)
await assertRepl(input, output)
})

it('caching nullary definitions', async () => {
const input = dedent(
`var x: int
Expand Down
Loading