tools: add -E flag to v test-parser, that will show the partial source that caused the parser to fail with -no-builtin -check-syntax file.v

This commit is contained in:
Delyan Angelov 2023-09-16 15:53:38 +03:00
parent f3dbf19cb4
commit cf0856cea9
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED
2 changed files with 11 additions and 0 deletions

View file

@ -155,6 +155,7 @@ const (
'-autofree', '-autofree',
'-compress', '-compress',
'-freestanding', '-freestanding',
'-no-builtin',
'-no-parallel', '-no-parallel',
'-no-preludes', '-no-preludes',
'-prof', '-prof',

View file

@ -26,6 +26,7 @@ mut:
is_verbose bool is_verbose bool
is_silent bool // do not print any status/progress during processing, just failures. is_silent bool // do not print any status/progress during processing, just failures.
is_linear bool // print linear progress log, without trying to do term cursor up + \r msg. Easier to use in a CI job is_linear bool // print linear progress log, without trying to do term cursor up + \r msg. Easier to use in a CI job
show_src bool // show the partial source, that cause the parser to panic/fault, when it happens.
timeout_ms int timeout_ms int
myself string // path to this executable, so the supervisor can launch worker processes myself string // path to this executable, so the supervisor can launch worker processes
all_paths []string // all files given to the supervisor process all_paths []string // all files given to the supervisor process
@ -110,6 +111,7 @@ fn process_cli_args() &Context {
context.is_verbose = fp.bool('verbose', `v`, false, 'Be more verbose.') context.is_verbose = fp.bool('verbose', `v`, false, 'Be more verbose.')
context.is_silent = fp.bool('silent', `S`, false, 'Do not print progress at all.') context.is_silent = fp.bool('silent', `S`, false, 'Do not print progress at all.')
context.is_linear = fp.bool('linear', `L`, false, 'Print linear progress log. Suitable for CI.') context.is_linear = fp.bool('linear', `L`, false, 'Print linear progress log. Suitable for CI.')
context.show_src = fp.bool('show_source', `E`, false, 'Print the partial source code that caused a fault/panic in the parser.')
context.period_ms = fp.int('progress_ms', `s`, 500, 'print a status report periodically, the period is given in milliseconds.') context.period_ms = fp.int('progress_ms', `s`, 500, 'print a status report periodically, the period is given in milliseconds.')
context.is_worker = fp.bool('worker', `w`, false, 'worker specific flag - is this a worker process, that can crash/panic.') context.is_worker = fp.bool('worker', `w`, false, 'worker specific flag - is this a worker process, that can crash/panic.')
context.cut_index = fp.int('cut_index', `c`, 1, 'worker specific flag - cut index in the source file, everything before that will be parsed, the rest - ignored.') context.cut_index = fp.int('cut_index', `c`, 1, 'worker specific flag - cut index in the source file, everything before that will be parsed, the rest - ignored.')
@ -238,6 +240,14 @@ fn (mut context Context) process_whole_file_in_worker(path string) (int, int) {
println('\t${line} | ${err_line}') println('\t${line} | ${err_line}')
println('') println('')
eprintln(res.output) eprintln(res.output)
eprintln('>>> failed command: ${cmd}')
if context.show_src {
eprintln('>>> source so far:')
eprintln('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
partial_source := source[..context.cut_index]
eprintln(partial_source)
eprintln('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
}
} }
} }
return fails, panics return fails, panics