Skip to content

Commit 3523c44

Browse files
committed
tools: make cmd/tools/vretry_test.v independent from the presence of git (fix issue #23398)
1 parent 89d405e commit 3523c44

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

cmd/tools/check_retry.vsh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env -S v -raw-vsh-tmp-prefix tmp
2+
3+
// This script is used by cmd/tools/vretry_test.v, to check that the `v retry`
4+
// subcommand works as expected, without relying on external commands like
5+
// `git`, or on non portable ones like `true`/`false` or `echo`.
6+
7+
fn main() {
8+
args := arguments()#[1..]
9+
println(args)
10+
if args == ['too', 'many', 'arguments'] {
11+
exit(1)
12+
}
13+
}

cmd/tools/vretry_test.v

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,61 @@
1+
// This test uses the script cmd/tools/check_retry.vsh
12
import os
3+
import log
24

35
const vexe = @VEXE
6+
const vroot = os.dir(vexe)
47

5-
const is_ci = os.getenv('CI') == 'true'
8+
const is_ci = os.getenv('CI') != ''
69

710
fn dump_on_ci[T](x T) {
811
if is_ci {
912
dump(x)
1013
}
1114
}
1215

16+
fn run(cmd string) os.Result {
17+
log.info('>>> running cmd: ${cmd}')
18+
defer {
19+
log.info('>>> finished cmd: ${cmd}')
20+
}
21+
return os.execute(cmd)
22+
}
23+
1324
fn test_retry() {
25+
log.warn('start...')
26+
defer {
27+
log.warn('... done')
28+
}
1429
tpath := os.join_path(os.vtmp_dir(), 'vretry_test')
1530
os.rmdir_all(tpath) or {}
1631
os.mkdir_all(tpath)!
1732
defer {
1833
os.rmdir_all(tpath) or {}
1934
}
20-
21-
fail_cmd := 'git asdf'
35+
os.chdir(vroot)!
36+
fail_cmd := '${vexe} run cmd/tools/check_retry.vsh too many arguments'
2237
if is_ci {
2338
// Skip longer running test on local runs.
24-
res := os.execute('${vexe} retry ${fail_cmd}')
39+
res := run('${vexe} retry ${fail_cmd}')
2540
assert res.exit_code != 0
2641
assert res.output.contains('error: exceeded maximum number of retries')
2742
}
2843

29-
mut res := os.execute('${vexe} retry -d 0.2 -r 3 ${fail_cmd}')
44+
mut res := run('${vexe} retry -d 0.2 -r 3 ${fail_cmd}')
3045
dump_on_ci(res)
3146
assert res.exit_code != 0
3247
assert res.output.contains('error: exceeded maximum number of retries (3)!')
3348

34-
os.chdir(os.dir(vexe))!
35-
pass_cmd := 'git branch'
36-
res = os.execute('${vexe} retry ${pass_cmd}')
49+
pass_cmd := '${vexe} run cmd/tools/check_retry.vsh'
50+
res = run('${vexe} retry ${pass_cmd}')
3751
dump_on_ci(res)
3852
assert res.exit_code == 0
39-
assert res.output == os.execute(pass_cmd).output
53+
assert res.output == run(pass_cmd).output
4054

4155
// Include flags on the cmd as well.
42-
pass_cmd_with_flags := 'git branch --list'
43-
res = os.execute('${vexe} retry -r 3 -- ${pass_cmd_with_flags}')
56+
pass_cmd_with_flags := '${vexe} run cmd/tools/check_retry.vsh --list -x arguments'
57+
res = run('${vexe} retry -r 3 -- ${pass_cmd_with_flags}')
4458
dump_on_ci(res)
4559
assert res.exit_code == 0
46-
assert res.output == os.execute(pass_cmd_with_flags).output
60+
assert res.output == run(pass_cmd_with_flags).output
4761
}

0 commit comments

Comments
 (0)