mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
tools: make cmd/tools/vretry_test.v independent from the presence of git (fix issue #23398)
This commit is contained in:
parent
89d405ec52
commit
3523c44f42
2 changed files with 39 additions and 12 deletions
13
cmd/tools/check_retry.vsh
Normal file
13
cmd/tools/check_retry.vsh
Normal file
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue