Skip to content

Commit afca235

Browse files
authored
tests: support v -silent in the remaining test runners as well; note it in AGENTS.md (#26590)
1 parent eef4d08 commit afca235

6 files changed

Lines changed: 117 additions & 63 deletions

File tree

‎AGENTS.md‎

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Get operational from the repo root in three steps:
4242
* Debug-friendly (recommended): `./v -g -keepc -o ./vnew cmd/v`
4343
3. Use `./vnew` for everything:
4444
* Run a file: `./vnew run examples/hello_world.v`
45-
* Run tests: `./vnew test vlib/v/`
45+
* Run tests: `./vnew -silent test vlib/v/`
4646
* Format: `./vnew fmt -w path/to/file.v`
4747

4848
Then read Top Rules and Agent Rules before making changes.
@@ -184,7 +184,7 @@ If you read only one section for tests, **read Testing**.
184184
| Change area | Rebuild? | Minimum tests to run |
185185
| --- | --- | --- |
186186
| Docs only (`.md`) | No | `check-md file.md` |
187-
| Compiler (`vlib/v/`, `cmd/v/`) | Yes | `vlib/v/compiler_errors_test.v`; `test vlib/v/` |
187+
| Compiler (`vlib/v/`, `cmd/v/`) | Yes | `-silent vlib/v/compiler_errors_test.v`; `test vlib/v/` |
188188
| Core modules (builtin/strings/os/strconv/time) | Yes | Smallest relevant tests |
189189
| Parser-only (`vlib/v/parser/`) | Yes | `test vlib/v/parser/` |
190190
| Checker-only (`vlib/v/checker/`) | Yes | `test vlib/v/checker/` |
@@ -462,7 +462,7 @@ Example: `$if field.typ is $int { ... }`
462462
### Comptime changes and testing
463463
Comptime logic lives in `vlib/v/comptime/` and is exercised by the
464464
checker, parser, and cgen stages. Changes here require a rebuild of
465-
`./vnew` and should be tested with `./vnew test vlib/v/tests/` plus
465+
`./vnew` and should be tested with `./vnew -silent test vlib/v/tests/` plus
466466
any comptime-specific tests. See the decision table and Testing.
467467

468468
## Run Programs
@@ -476,11 +476,11 @@ any comptime-specific tests. See the decision table and Testing.
476476
Run:
477477
* File (shows test output): `./vnew path/to/file_test.v`.
478478
* File (test runner report only): `./vnew test path/to/file_test.v`.
479-
* Dir: `./vnew test path/to/dir/`.
479+
* Dir: `./vnew -silent test path/to/dir/`.
480480
* Dir with statistics/metrics: `./vnew -stats test path/to/dir/`.
481-
* Compiler: `./vnew vlib/v/compiler_errors_test.v`.
481+
* Compiler: `./vnew -silent vlib/v/compiler_errors_test.v`.
482482
* Fix outputs (only when intended):
483-
`VAUTOFIX=1 ./vnew vlib/v/compiler_errors_test.v`.
483+
`VAUTOFIX=1 ./vnew -silent vlib/v/compiler_errors_test.v`.
484484
* All: `./vnew test-all`.
485485
Ask before running `./vnew test-all` unless explicitly requested.
486486

@@ -494,33 +494,33 @@ When:
494494
* Run all tests that apply. Start with the smallest targeted tests;
495495
add slow tests as needed. Order does not matter.
496496
* Compiler changes (`vlib/v/` or `cmd/v/`):
497-
Run `./vnew vlib/v/compiler_errors_test.v`,
498-
`./vnew test vlib/v/`.
497+
Run `./vnew -silent vlib/v/compiler_errors_test.v`,
498+
`./vnew -silent test vlib/v/`.
499499
* Parser-only changes (`vlib/v/parser/`):
500-
Run `./vnew test vlib/v/parser/`.
500+
Run `./vnew -silent test vlib/v/parser/`.
501501
* Checker-only changes (`vlib/v/checker`):
502-
Run `./vnew test vlib/v/checker/tests/`.
502+
Run `./vnew -silent test vlib/v/checker/`.
503503
* vlib changes: Run nearest `*_test.v` or
504-
`./vnew test vlib/path/`.
504+
`./vnew -silent test vlib/path/`.
505505
* Tool changes (`cmd/tools/`): Run tool-specific tests. If none exist,
506506
run the smallest relevant `*_test.v` that exercises the tool.
507507
Note: `cmd/v/` is compiler scope, not tools.
508-
Examples: `cmd/tools/vfmt` -> `vlib/v/fmt/fmt_test.v`,
509-
`cmd/tools/vdoc` -> `vlib/v/doc/doc_test.v`.
508+
Examples: `cmd/tools/vfmt` -> `vlib/v/fmt/fmt_test.v` .
509+
`cmd/tools/vdoc` -> `cmd/tools/vdoc/vdoc_test.v`.
510510
* Diagnostic/output changes:
511-
Run `./vnew vlib/v/slow_tests/inout/compiler_test.v`.
512-
* C codegen changes: Run `./vnew vlib/v/gen/c/coutput_test.v`.
511+
Run `./vnew -silent vlib/v/slow_tests/inout/compiler_test.v`.
512+
* C codegen changes: Run `./vnew -silent vlib/v/gen/c/coutput_test.v`.
513513
Consider a stricter validation pass:
514-
`./vnew -cstrict -cc clang test vlib/v/`.
515-
* REPL changes: Run `./vnew vlib/v/slow_tests/repl/repl_test.v`.
516-
* Broad refactors: Run `./vnew test-all`.
514+
`./vnew -cstrict -cc clang -silent test vlib/v/`.
515+
* REPL changes: Run `./vnew -silent vlib/v/slow_tests/repl/repl_test.v`.
516+
* Broad refactors: Run `./vnew -silent test-all`.
517517
* Backend-specific changes: run the smallest relevant tests for the
518518
affected backend. JS/native/WASM backends are incomplete, so avoid
519519
broad `-b <backend> test vlib/` runs. Prefer targeted `*_test.v`
520520
files or small test dirs with `-b js|native|wasm`.
521521

522522
If time-constrained, prioritize
523-
`./vnew vlib/v/compiler_errors_test.v` and the smallest targeted tests.
523+
`./vnew -silent vlib/v/compiler_errors_test.v` and the smallest targeted tests.
524524
Run `vlib/v/slow_tests/inout/compiler_test.v`
525525
and `vlib/v/gen/c/coutput_test.v` when output or codegen changes are
526526
likely.
@@ -538,9 +538,9 @@ Types:
538538
* Standard: `*_test.v` files with `test_` functions.
539539
* Output: `.vv` source + `.out` expected output in
540540
`vlib/v/slow_tests/inout/`.
541-
Example: `./vnew vlib/v/slow_tests/inout/compiler_test.v`.
541+
Example: `./vnew -silent vlib/v/slow_tests/inout/compiler_test.v`.
542542
* `vlib/v/tests/**` may use `.run.out` expectations; run with
543-
`./vnew test vlib/v/tests`.
543+
`./vnew -silent test vlib/v/tests`.
544544

545545
Docs-only guidance: see Reporting.
546546
If time-boxed, run at least the smallest relevant test and note
@@ -551,8 +551,7 @@ skipped coverage in the summary.
551551
Use only when a behavior change is intended.
552552
* `VTEST_ONLY=glob_pattern` - Run only tests matching pattern.
553553
* `VTEST_HIDE_OK=1` - Hide successful tests, show only failures.
554-
* `./vnew -progress test path/to/dir/` - Show only the currently
555-
running test.
554+
* `./vnew -silent test path/to/dir/` - Show only failed tests (if any), and a summary report.
556555
* `-cc tcc` can speed test builds when TCC is available.
557556
* Output expectations: update `.out` files only when behavior changes
558557
are intended; note the rationale in the summary.

‎vlib/v/compiler_errors_test.v‎

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ const turn_on_normal_test_runner = os.setenv('VTEST_RUNNER', 'normal', true)
4242

4343
const should_autofix = os.getenv('VAUTOFIX') != ''
4444

45+
const is_silent = $if silent ? { true } $else { false }
46+
4547
const github_job = os.getenv('GITHUB_JOB')
4648

49+
const should_show_details = !is_silent && github_job == ''
50+
4751
const v_ci_ubuntu_musl = os.getenv('V_CI_UBUNTU_MUSL').len > 0
4852

4953
const v_ci_musl = os.getenv('V_CI_MUSL').len > 0
@@ -104,24 +108,6 @@ fn test_all() {
104108
no_closures_tests := get_tests_in_dir(no_closures_dir, false)
105109
checker_with_check_option_tests := get_tests_in_dir(checker_with_check_option_dir,
106110
false)
107-
mut tasks := Tasks{
108-
vexe: vexe
109-
label: 'all tests'
110-
}
111-
tasks.add('', parser_dir, '', '.out', parser_tests, false)
112-
tasks.add('', checker_dir, '', '.out', checker_tests, false)
113-
tasks.add('', scanner_dir, '', '.out', scanner_tests, false)
114-
tasks.add('', checker_dir, '-enable-globals run', '.run.out', ['globals_error.vv'],
115-
false)
116-
tasks.add('', global_run_dir, '-enable-globals run', '.run.out', global_run_tests,
117-
false)
118-
tasks.add('', global_dir, '-enable-globals', '.out', global_tests, false)
119-
tasks.add('', module_dir, '-prod run', '.out', module_tests, true)
120-
tasks.add('', run_dir, 'run', '.run.out', run_tests, false)
121-
tasks.add('', checker_with_check_option_dir, '-check', '.out', checker_with_check_option_tests,
122-
false)
123-
tasks.add('', no_closures_dir, '-no-closures run', '.out', no_closures_tests, false)
124-
tasks.run()
125111

126112
if os.user_os() == 'linux' {
127113
mut su_tasks := Tasks{
@@ -179,6 +165,25 @@ fn test_all() {
179165
'custom_comptime_define_if_debug.vv',
180166
])
181167
ct_tasks.run()
168+
169+
mut tasks := Tasks{
170+
vexe: vexe
171+
label: 'all tests'
172+
}
173+
tasks.add('', parser_dir, '', '.out', parser_tests, false)
174+
tasks.add('', checker_dir, '', '.out', checker_tests, false)
175+
tasks.add('', scanner_dir, '', '.out', scanner_tests, false)
176+
tasks.add('', checker_dir, '-enable-globals run', '.run.out', ['globals_error.vv'],
177+
false)
178+
tasks.add('', global_run_dir, '-enable-globals run', '.run.out', global_run_tests,
179+
false)
180+
tasks.add('', global_dir, '-enable-globals', '.out', global_tests, false)
181+
tasks.add('', module_dir, '-prod run', '.out', module_tests, true)
182+
tasks.add('', run_dir, 'run', '.run.out', run_tests, false)
183+
tasks.add('', checker_with_check_option_dir, '-check', '.out', checker_with_check_option_tests,
184+
false)
185+
tasks.add('', no_closures_dir, '-no-closures run', '.out', no_closures_tests, false)
186+
tasks.run()
182187
}
183188

184189
fn (mut tasks Tasks) add_checked_run(voptions string, result_extension string, tests []string) {
@@ -267,7 +272,7 @@ fn (mut tasks Tasks) run() {
267272
for _ in 0 .. vjobs {
268273
spawn work_processor(work, results)
269274
}
270-
if github_job == '' {
275+
if should_show_details {
271276
println('')
272277
}
273278
mut line_can_be_erased := true
@@ -278,8 +283,10 @@ fn (mut tasks Tasks) run() {
278283
bench.step()
279284
if task.is_skipped {
280285
bench.skip()
281-
eprintln(bstep_message(mut bench, benchmark.b_skip, task.path, task.took))
282-
line_can_be_erased = false
286+
if should_show_details {
287+
eprintln(bstep_message(mut bench, benchmark.b_skip, task.path, task.took))
288+
line_can_be_erased = false
289+
}
283290
continue
284291
}
285292
if task.is_error {
@@ -303,20 +310,23 @@ fn (mut tasks Tasks) run() {
303310
assert true
304311
if tasks.show_cmd {
305312
eprintln(bstep_message(mut bench, benchmark.b_ok, '${task.cli_cmd}', task.took))
313+
line_can_be_erased = true
306314
} else {
307-
if github_job == '' {
315+
if should_show_details {
308316
// local mode:
309317
if line_can_be_erased {
310318
term.clear_previous_line()
311319
}
312320
println(bstep_message(mut bench, benchmark.b_ok, task.path, task.took))
321+
line_can_be_erased = true
313322
}
314323
}
315-
line_can_be_erased = true
316324
}
317325
}
318326
bench.stop()
319-
eprintln(term.h_divider('-'))
327+
if should_show_details {
328+
eprintln(term.h_divider('-'))
329+
}
320330
eprintln(bench.total_message(tasks.label))
321331
if total_errors != 0 {
322332
exit(1)

‎vlib/v/gen/c/coutput_test.v‎

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ const vexe = @VEXE
99

1010
const vroot = os.real_path(@VMODROOT)
1111

12-
const testdata_folder = os.join_path(vroot, 'vlib', 'v', 'gen', 'c', 'testdata')
12+
const local_tdata_path = 'vlib/v/gen/c/testdata'
13+
14+
const testdata_folder = os.real_path(os.join_path(vroot, local_tdata_path))
1315

1416
const show_compilation_output = os.getenv('VTEST_SHOW_COMPILATION_OUTPUT').int() == 1
1517

@@ -26,7 +28,6 @@ fn mj(input ...string) string {
2628
}
2729

2830
fn test_out_files() {
29-
println(term.colorize(term.green, '> testing whether .out files match:'))
3031
os.chdir(vroot) or {}
3132
output_path := os.join_path(os.vtmp_dir(), 'coutput_outs')
3233
os.mkdir_all(output_path)!
@@ -39,11 +40,16 @@ fn test_out_files() {
3940
eprintln('no `.out` tests found in ${testdata_folder}')
4041
return
4142
}
42-
paths := vtest.filter_vtest_only(tests, basepath: testdata_folder).sorted()
4343
mut total_errors := 0
44+
mut total_oks := 0
45+
mut total_oks_panic := 0
46+
mut total_skips := 0
47+
paths := vtest.filter_vtest_only(tests, basepath: testdata_folder).sorted()
48+
println(term.colorize(term.green, '> testing whether ${paths.len} .out files in ${local_tdata_path} match:'))
4449
for out_path in paths {
4550
basename, path, relpath, out_relpath := target2paths(out_path, '.out')
4651
if should_skip(relpath) {
52+
total_skips++
4753
continue
4854
}
4955
pexe := os.join_path(output_path, '${basename}.exe')
@@ -75,7 +81,8 @@ fn test_out_files() {
7581
n_expected := normalize_panic_message(expected, vroot)
7682
if found.contains('================ V panic ================') {
7783
if n_found.starts_with(n_expected) {
78-
println('${term.green('OK (panic)')} C:${compile_ms:6}ms, R:${run_ms:2}ms ${label}')
84+
vprintln('${term.green('OK (panic)')} C:${compile_ms:6}ms, R:${run_ms:2}ms ${label}')
85+
total_oks_panic++
7986
continue
8087
} else {
8188
// Both have panics, but there was a difference...
@@ -100,14 +107,15 @@ fn test_out_files() {
100107
println(term.h_divider('-'))
101108
total_errors++
102109
} else {
103-
println('${term.green('OK ')} C:${compile_ms:6}ms, R:${run_ms:2}ms ${label}')
110+
vprintln('${term.green('OK ')} C:${compile_ms:6}ms, R:${run_ms:2}ms ${label}')
111+
total_oks++
104112
}
105113
}
114+
println('>>> Summary for test_out_files: files: ${paths.len}, oks: ${total_oks}, ok panics: ${total_oks_panic}, skipped: ${total_skips}, error: ${total_errors} .')
106115
assert total_errors == 0
107116
}
108117

109118
fn test_c_must_have_files() {
110-
println(term.colorize(term.green, '> testing whether all line patterns in `.c.must_have` files match:'))
111119
os.chdir(vroot) or {}
112120
output_path := os.join_path(os.vtmp_dir(), 'coutput_c_must_haves')
113121
os.mkdir_all(output_path)!
@@ -122,10 +130,15 @@ fn test_c_must_have_files() {
122130
}
123131
paths := vtest.filter_vtest_only(tests, basepath: testdata_folder).sorted()
124132
mut total_errors := 0
133+
mut total_oks := 0
134+
mut total_oks_panic := 0
135+
mut total_skips := 0
125136
mut failed_descriptions := []string{cap: paths.len}
137+
println(term.colorize(term.green, '> testing whether all line patterns in ${paths.len} `.c.must_have` files in ${local_tdata_path} match:'))
126138
for must_have_path in paths {
127139
basename, path, relpath, must_have_relpath := target2paths(must_have_path, '.c.must_have')
128140
if should_skip(relpath) {
141+
total_skips++
129142
continue
130143
}
131144
file_options := get_file_options(path)
@@ -159,7 +172,8 @@ fn test_c_must_have_files() {
159172
}
160173
}
161174
if nmatches == expected_lines.len {
162-
println('${term.green('OK ')} C:${compile_ms:5}ms ${description}')
175+
vprintln('${term.green('OK ')} C:${compile_ms:5}ms ${description}')
176+
total_oks++
163177
} else {
164178
if show_compilation_output {
165179
eprintln('> ALL lines:')
@@ -179,6 +193,7 @@ fn test_c_must_have_files() {
179193
}
180194
eprintln('----------------------------------------------------------------------')
181195
}
196+
println('>>> Summary for test_c_must_have_files: files: ${paths.len}, oks: ${total_oks}, ok panics: ${total_oks_panic}, skipped: ${total_skips}, error: ${total_errors} .')
182197
assert total_errors == 0
183198
}
184199

@@ -292,3 +307,8 @@ fn should_skip(relpath string) bool {
292307
}
293308
return false
294309
}
310+
311+
@[if !silent ?]
312+
fn vprintln(msg string) {
313+
println(msg)
314+
}

‎vlib/v/pref/pref.v‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,8 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
426426
}
427427
'-silent' {
428428
res.output_mode = .silent
429+
res.compile_defines_all << 'silent' // enable `$if silent? {`
430+
res.compile_defines << 'silent'
429431
}
430432
'-skip-running' {
431433
res.skip_running = true

0 commit comments

Comments
 (0)