Skip to content

Commit 756b463

Browse files
authored
vrepeat: implement verbose command output (#28221)
1 parent 0c351f1 commit 756b463

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

cmd/tools/vrepeat.v

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,22 @@ fn flushed_print(s string) {
149149
flush_stdout()
150150
}
151151

152+
fn (context &Context) verbose_command(cmd string) {
153+
if context.verbose {
154+
println('\n> ${cmd}')
155+
}
156+
}
157+
158+
fn (context &Context) verbose_result(result os.Result) {
159+
if !context.verbose {
160+
return
161+
}
162+
println(' exit code: ${result.exit_code}')
163+
if result.output != '' {
164+
println(result.output.trim_right('\r\n'))
165+
}
166+
}
167+
152168
fn (mut context Context) clear_line() {
153169
if context.is_silent {
154170
return
@@ -207,9 +223,11 @@ fn (mut context Context) run() {
207223
if context.warmup > 0 {
208224
for i in 0 .. context.warmup {
209225
context.flushed_print('${line_prefix}, warm up run: ${i + 1:4}/${context.warmup:-4}, took: ${f64(duration) / 1000:6.1f}ms ...')
226+
context.verbose_command(cmd)
210227
mut sw := time.new_stopwatch()
211228
res := os.execute(cmd)
212229
duration = i64(sw.elapsed().microseconds())
230+
context.verbose_result(res)
213231
mut should_show_fail_output := false
214232
if res.exit_code != 0 && !context.ignore_failed {
215233
if context.fail_count[cmd] == 0 {
@@ -226,9 +244,11 @@ fn (mut context Context) run() {
226244
}
227245
}
228246
for i in 0 .. context.run_count {
247+
context.verbose_command(cmd)
229248
mut sw := time.new_stopwatch()
230249
res := os.execute(cmd)
231250
duration = i64(sw.elapsed().microseconds())
251+
context.verbose_result(res)
232252
//
233253
mut should_show_fail_output := false
234254
if res.exit_code != 0 && !context.ignore_failed {
@@ -443,7 +463,8 @@ fn (mut context Context) parse_options() ! {
443463
}
444464
context.show_output = fp.bool('output', `O`, false,
445465
'Show command stdout/stderr in the progress indicator for each command. Note: slower, for verbose commands.')
446-
context.verbose = fp.bool('verbose', `v`, false, 'Be more verbose.')
466+
context.verbose = fp.bool('verbose', `v`, false,
467+
'Print each command, its exit code, and its output.')
447468
context.fail_on_maxtime = fp.int('max_time', `m`, max_time,
448469
'Fail with exit code 2, when first cmd takes above M milliseconds (regression). Default: ${max_time}')
449470
context.fail_on_regress_percent = fp.int('fail_percent', `f`, max_fail_percent,

cmd/tools/vrepeat_test.v

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import os
2+
3+
const vexe = @VEXE
4+
5+
fn test_verbose_prints_command_result() {
6+
command := 'echo vrepeat_verbose_output'
7+
for option in ['-v', '--verbose'] {
8+
result :=
9+
os.execute('${os.quoted_path(vexe)} repeat -S -r 1 -w 0 ${option} ${os.quoted_path(command)}')
10+
assert result.exit_code == 0, result.output
11+
assert result.output.contains('exit code: 0'), result.output
12+
assert result.output.split_into_lines().any(it.trim_right('\r') == 'vrepeat_verbose_output'), result.output
13+
}
14+
}

vlib/v/help/other/repeat.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Options:
1818
By default, VEXE will be set to "", to allow for measuring different V executables. Use this option to override it
1919
-n, --newline Use \n, do not overwrite the last line. Produces more output, but easier to diagnose.
2020
-O, --output Show command stdout/stderr in the progress indicator for each command. Note: slower, for verbose commands.
21-
-v, --verbose Be more verbose.
21+
-v, --verbose Print each command, its exit code, and its output.
2222
-m, --max_time <int> Fail with exit code 2, when first cmd takes above M milliseconds (regression). Default: 60000
2323
-f, --fail_percent <int> Fail with exit code 3, when first cmd is X% slower than the rest (regression). Default: 100000
2424
-t, --template <string> Command template. {T} will be substituted with the current command. Default: {T}.

0 commit comments

Comments
 (0)