From 3523c44f42845ceae841530c94d9816938813513 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 13 Jan 2025 08:10:13 +0200 Subject: [PATCH] tools: make cmd/tools/vretry_test.v independent from the presence of git (fix issue #23398) --- cmd/tools/check_retry.vsh | 13 +++++++++++++ cmd/tools/vretry_test.v | 38 ++++++++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 cmd/tools/check_retry.vsh diff --git a/cmd/tools/check_retry.vsh b/cmd/tools/check_retry.vsh new file mode 100644 index 000000000..f48ac86a3 --- /dev/null +++ b/cmd/tools/check_retry.vsh @@ -0,0 +1,13 @@ +#!/usr/bin/env -S v -raw-vsh-tmp-prefix tmp + +// This script is used by cmd/tools/vretry_test.v, to check that the `v retry` +// subcommand works as expected, without relying on external commands like +// `git`, or on non portable ones like `true`/`false` or `echo`. + +fn main() { + args := arguments()#[1..] + println(args) + if args == ['too', 'many', 'arguments'] { + exit(1) + } +} diff --git a/cmd/tools/vretry_test.v b/cmd/tools/vretry_test.v index 0f3a3fb07..193b03fd1 100644 --- a/cmd/tools/vretry_test.v +++ b/cmd/tools/vretry_test.v @@ -1,8 +1,11 @@ +// This test uses the script cmd/tools/check_retry.vsh import os +import log const vexe = @VEXE +const vroot = os.dir(vexe) -const is_ci = os.getenv('CI') == 'true' +const is_ci = os.getenv('CI') != '' fn dump_on_ci[T](x T) { if is_ci { @@ -10,38 +13,49 @@ fn dump_on_ci[T](x T) { } } +fn run(cmd string) os.Result { + log.info('>>> running cmd: ${cmd}') + defer { + log.info('>>> finished cmd: ${cmd}') + } + return os.execute(cmd) +} + fn test_retry() { + log.warn('start...') + defer { + log.warn('... done') + } tpath := os.join_path(os.vtmp_dir(), 'vretry_test') os.rmdir_all(tpath) or {} os.mkdir_all(tpath)! defer { os.rmdir_all(tpath) or {} } - - fail_cmd := 'git asdf' + os.chdir(vroot)! + fail_cmd := '${vexe} run cmd/tools/check_retry.vsh too many arguments' if is_ci { // Skip longer running test on local runs. - res := os.execute('${vexe} retry ${fail_cmd}') + res := run('${vexe} retry ${fail_cmd}') assert res.exit_code != 0 assert res.output.contains('error: exceeded maximum number of retries') } - mut res := os.execute('${vexe} retry -d 0.2 -r 3 ${fail_cmd}') + mut res := run('${vexe} retry -d 0.2 -r 3 ${fail_cmd}') dump_on_ci(res) assert res.exit_code != 0 assert res.output.contains('error: exceeded maximum number of retries (3)!') - os.chdir(os.dir(vexe))! - pass_cmd := 'git branch' - res = os.execute('${vexe} retry ${pass_cmd}') + pass_cmd := '${vexe} run cmd/tools/check_retry.vsh' + res = run('${vexe} retry ${pass_cmd}') dump_on_ci(res) assert res.exit_code == 0 - assert res.output == os.execute(pass_cmd).output + assert res.output == run(pass_cmd).output // Include flags on the cmd as well. - pass_cmd_with_flags := 'git branch --list' - res = os.execute('${vexe} retry -r 3 -- ${pass_cmd_with_flags}') + pass_cmd_with_flags := '${vexe} run cmd/tools/check_retry.vsh --list -x arguments' + res = run('${vexe} retry -r 3 -- ${pass_cmd_with_flags}') dump_on_ci(res) assert res.exit_code == 0 - assert res.output == os.execute(pass_cmd_with_flags).output + assert res.output == run(pass_cmd_with_flags).output } -- 2.39.5