From 7b723262e44cca8e2c07ef11d5a278f7c2f44b17 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 15 Nov 2021 11:44:54 +0200 Subject: [PATCH] tools: support `VJOBS=1 VTEST_FAIL_FAST=1 ./v test .` --- cmd/tools/modules/testing/common.v | 17 +++++++++++++---- cmd/tools/vtest.v | 19 ++++++++++++++++--- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/cmd/tools/modules/testing/common.v b/cmd/tools/modules/testing/common.v index cfca10a94c..69bf0f8387 100644 --- a/cmd/tools/modules/testing/common.v +++ b/cmd/tools/modules/testing/common.v @@ -9,13 +9,15 @@ import v.pref import v.util.vtest import runtime -const github_job = os.getenv('GITHUB_JOB') +pub const github_job = os.getenv('GITHUB_JOB') -const show_start = os.getenv('VTEST_SHOW_START') == '1' +pub const show_start = os.getenv('VTEST_SHOW_START') == '1' -const hide_skips = os.getenv('VTEST_HIDE_SKIP') == '1' +pub const hide_skips = os.getenv('VTEST_HIDE_SKIP') == '1' -const hide_oks = os.getenv('VTEST_HIDE_OK') == '1' +pub const hide_oks = os.getenv('VTEST_HIDE_OK') == '1' + +pub const fail_fast = os.getenv('VTEST_FAIL_FAST') == '1' pub struct TestSession { pub mut: @@ -26,6 +28,7 @@ pub mut: vtmp_dir string vargs string failed bool + fail_fast bool benchmark benchmark.Benchmark rm_binaries bool = true silent_mode bool @@ -186,6 +189,7 @@ pub fn new_test_session(_vargs string, will_compile bool) TestSession { vexe: vexe vroot: vroot skip_files: skip_files + fail_fast: testing.fail_fast vargs: vargs vtmp_dir: new_vtmp_dir silent_mode: _vargs.contains('-silent') @@ -258,6 +262,11 @@ pub fn (mut ts TestSession) test() { fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr { mut ts := &TestSession(p.get_shared_context()) + if ts.fail_fast { + if ts.failed { + return pool.no_result + } + } tmpd := ts.vtmp_dir show_stats := '-stats' in ts.vargs.split(' ') // tls_bench is used to format the step messages/timings diff --git a/cmd/tools/vtest.v b/cmd/tools/vtest.v index d116d297dd..be551a2457 100644 --- a/cmd/tools/vtest.v +++ b/cmd/tools/vtest.v @@ -12,9 +12,10 @@ fn main() { return } args_to_executable := args[1..] - args_before := cmdline.options_before(args_to_executable, ['test']) - args_after := cmdline.options_after(args_to_executable, ['test']) - if args_after.join(' ') == 'v' { + mut args_before := cmdline.options_before(args_to_executable, ['test']) + mut args_after := cmdline.options_after(args_to_executable, ['test']) + fail_fast := extract_flag('-fail-fast', mut args_after, testing.fail_fast) + if args_after == ['v'] { eprintln('`v test v` has been deprecated.') eprintln('Use `v test-all` instead.') exit(1) @@ -23,6 +24,7 @@ fn main() { backend := if backend_pos == -1 { '.c' } else { args_before[backend_pos + 1] } // this giant mess because closures are not implemented mut ts := testing.new_test_session(args_before.join(' '), true) + ts.fail_fast = fail_fast for targ in args_after { if os.is_dir(targ) { // Fetch all tests from the directory @@ -133,3 +135,14 @@ fn should_test(path string, backend string) ShouldTestStatus { } return .ignore } + +fn extract_flag(flag_name string, mut after []string, flag_default bool) bool { + mut res := flag_default + orig_after := after.clone() // workaround for after.filter() codegen bug, when `mut after []string` + matches_after := orig_after.filter(it != flag_name) + if matches_after.len < after.len { + after = matches_after.clone() + res = true + } + return res +}