ci,tools: implement silent mode in `./v test-parser -S examples/cli.v`
parent
8a59ffb4b7
commit
ef6839286e
|
@ -825,14 +825,14 @@ jobs:
|
||||||
run: make -j4
|
run: make -j4
|
||||||
- name: Run test-parser
|
- name: Run test-parser
|
||||||
run: |
|
run: |
|
||||||
./v test-parser examples/hello_world.v
|
./v test-parser -S examples/hello_world.v
|
||||||
./v test-parser examples/hanoi.v
|
./v test-parser -S examples/hanoi.v
|
||||||
./v test-parser examples/fibonacci.v
|
./v test-parser -S examples/fibonacci.v
|
||||||
./v test-parser examples/cli.v
|
./v test-parser -S examples/cli.v
|
||||||
./v test-parser examples/json.v
|
./v test-parser -S examples/json.v
|
||||||
./v test-parser examples/vmod.v
|
./v test-parser -S examples/vmod.v
|
||||||
./v test-parser examples/regex_example.v
|
./v test-parser -S examples/regex_example.v
|
||||||
./v test-parser examples/2048/2048.v
|
./v test-parser -S examples/2048/2048.v
|
||||||
|
|
||||||
parser-silent-fuzzing:
|
parser-silent-fuzzing:
|
||||||
name: Parser silent mode fuzzing
|
name: Parser silent mode fuzzing
|
||||||
|
@ -856,11 +856,11 @@ jobs:
|
||||||
zzuf -R '\x00-\x20\x7f-\xff' -r0.01 < examples/vmod.v > examples/vmod_fuzz.v
|
zzuf -R '\x00-\x20\x7f-\xff' -r0.01 < examples/vmod.v > examples/vmod_fuzz.v
|
||||||
zzuf -R '\x00-\x20\x7f-\xff' -r0.01 < examples/regex_example.v > examples/regex_example_fuzz.v
|
zzuf -R '\x00-\x20\x7f-\xff' -r0.01 < examples/regex_example.v > examples/regex_example_fuzz.v
|
||||||
zzuf -R '\x00-\x20\x7f-\xff' -r0.01 < examples/2048/2048.v > examples/2048/2048_fuzz.v
|
zzuf -R '\x00-\x20\x7f-\xff' -r0.01 < examples/2048/2048.v > examples/2048/2048_fuzz.v
|
||||||
./v test-parser examples/hello_world_fuzz.v
|
./v test-parser -S examples/hello_world_fuzz.v
|
||||||
./v test-parser examples/hanoi_fuzz.v
|
./v test-parser -S examples/hanoi_fuzz.v
|
||||||
./v test-parser examples/cli_fuzz.v
|
./v test-parser -S examples/cli_fuzz.v
|
||||||
./v test-parser examples/regex_example_fuzz.v
|
./v test-parser -S examples/regex_example_fuzz.v
|
||||||
./v test-parser examples/2048/2048_fuzz.v
|
./v test-parser -S examples/2048/2048_fuzz.v
|
||||||
|
|
||||||
v-up-works-on-ubuntu:
|
v-up-works-on-ubuntu:
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
|
|
|
@ -26,17 +26,19 @@ mut:
|
||||||
is_help bool
|
is_help bool
|
||||||
is_worker bool
|
is_worker bool
|
||||||
is_verbose bool
|
is_verbose bool
|
||||||
|
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
|
||||||
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
|
||||||
path string // the current path, given to a worker process
|
path string // the current path, given to a worker process
|
||||||
cut_index int // the cut position in the source from context.path
|
cut_index int // the cut position in the source from context.path
|
||||||
max_index int // the maximum index (equivalent to the file content length)
|
max_index int // the maximum index (equivalent to the file content length)
|
||||||
// parser context in the worker processes:
|
// parser context in the worker processes:
|
||||||
table table.Table
|
table table.Table
|
||||||
scope ast.Scope
|
scope ast.Scope
|
||||||
pref pref.Preferences
|
pref pref.Preferences
|
||||||
period_ms int // print periodic progress
|
period_ms int // print periodic progress
|
||||||
stop_print bool // stop printing the periodic progress
|
stop_print bool // stop printing the periodic progress
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +58,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
mut source := os.read_file(context.path) ?
|
mut source := os.read_file(context.path) ?
|
||||||
source = source[..context.cut_index]
|
source = source[..context.cut_index]
|
||||||
|
|
||||||
go fn (ms int) {
|
go fn (ms int) {
|
||||||
time.sleep_ms(ms)
|
time.sleep_ms(ms)
|
||||||
exit(ecode_timeout)
|
exit(ecode_timeout)
|
||||||
|
@ -106,6 +109,8 @@ fn process_cli_args() &Context {
|
||||||
fp.skip_executable()
|
fp.skip_executable()
|
||||||
context.is_help = fp.bool('help', `h`, false, 'Show help/usage screen.')
|
context.is_help = fp.bool('help', `h`, false, 'Show help/usage screen.')
|
||||||
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_linear = fp.bool('linear', `L`, false, 'Print linear progress log. Suitable for CI.')
|
||||||
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.')
|
||||||
|
@ -226,7 +231,11 @@ fn (mut context Context) process_whole_file_in_worker(path string) (int, int) {
|
||||||
line := part.count('\n') + 1
|
line := part.count('\n') + 1
|
||||||
last_line := part.all_after_last('\n')
|
last_line := part.all_after_last('\n')
|
||||||
col := last_line.len
|
col := last_line.len
|
||||||
err := if is_panic { red('parser failure: panic') } else { red('parser failure: crash, ${ecode_details[res.exit_code.str()]}') }
|
err := if is_panic {
|
||||||
|
red('parser failure: panic')
|
||||||
|
} else {
|
||||||
|
red('parser failure: crash, ${ecode_details[res.exit_code.str()]}')
|
||||||
|
}
|
||||||
path_to_line := bold('$path:$line:$col:')
|
path_to_line := bold('$path:$line:$col:')
|
||||||
err_line := last_line.trim_left('\t')
|
err_line := last_line.trim_left('\t')
|
||||||
println('$path_to_line $err')
|
println('$path_to_line $err')
|
||||||
|
@ -240,7 +249,9 @@ fn (mut context Context) process_whole_file_in_worker(path string) (int, int) {
|
||||||
|
|
||||||
fn (mut context Context) start_printing() {
|
fn (mut context Context) start_printing() {
|
||||||
context.stop_print = false
|
context.stop_print = false
|
||||||
println('\n')
|
if !context.is_linear && !context.is_silent {
|
||||||
|
println('\n')
|
||||||
|
}
|
||||||
go context.print_periodic_status()
|
go context.print_periodic_status()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,15 +261,32 @@ fn (mut context Context) stop_printing() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut context Context) print_status() {
|
fn (mut context Context) print_status() {
|
||||||
|
if context.is_silent {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (context.cut_index == 1) && (context.max_index == 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
msg := '> ${context.path:-30} | index: ${context.cut_index:5}/${context.max_index - 1:5}'
|
||||||
|
if context.is_linear {
|
||||||
|
eprintln(msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
term.cursor_up(1)
|
term.cursor_up(1)
|
||||||
eprint('\r > ${context.path:-30} | index: ${context.cut_index:5}/${context.max_index - 1:5}\n')
|
eprint('\r $msg\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut context Context) print_periodic_status() {
|
fn (mut context Context) print_periodic_status() {
|
||||||
|
context.print_status()
|
||||||
|
mut printed_at_least_once := false
|
||||||
for !context.stop_print {
|
for !context.stop_print {
|
||||||
context.print_status()
|
context.print_status()
|
||||||
for i := 0; i < 10 && !context.stop_print; i++ {
|
for i := 0; i < 10 && !context.stop_print; i++ {
|
||||||
time.sleep_ms(context.period_ms / 10)
|
time.sleep_ms(context.period_ms / 10)
|
||||||
|
if context.cut_index > 50 && !printed_at_least_once {
|
||||||
|
context.print_status()
|
||||||
|
printed_at_least_once = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
context.print_status()
|
context.print_status()
|
||||||
|
|
Loading…
Reference in New Issue