v2 / cmd / tools / vpm / outdated_test.v
68 lines · 61 sloc · 1.92 KB · 37964c84366ba432f99ae2dab0e806be373dd6c9
Raw
1// vtest retry: 3
2// vtest build: !windows
3module main
4
5import os
6import rand
7import test_utils { cmd_ok }
8
9const test_path = os.join_path(os.vtmp_dir(), 'vpm_outdated_test_${rand.ulid()}')
10
11fn testsuite_begin() {
12 $if !network ? {
13 eprintln('> skipping ${@FILE}, when `-d network` is missing')
14 exit(0)
15 }
16 dump(test_path)
17 test_utils.set_test_env(test_path)
18 os.mkdir_all(test_path)!
19 os.chdir(test_path)!
20}
21
22fn testsuite_end() {
23 os.rmdir_all(test_path) or {}
24}
25
26fn test_is_outdated_git_module() {
27 cmd_ok(@LOCATION, 'git clone https://github.com/vlang/libsodium.git')
28 assert !is_outdated('libsodium')
29 cmd_ok(@LOCATION, 'git -C libsodium reset --hard HEAD~')
30 assert is_outdated('libsodium')
31 cmd_ok(@LOCATION, 'git -C libsodium pull')
32 assert !is_outdated('libsodium')
33}
34
35fn test_is_outdated_hg_module() {
36 $if !check_mercurial_works ? {
37 return
38 }
39 os.find_abs_path_of_executable('hg') or {
40 eprintln('skipping test, since `hg` is not executable.')
41 return
42 }
43 cmd_ok(@LOCATION, 'hg clone https://www.mercurial-scm.org/repo/hello')
44 assert !is_outdated('hello')
45 cmd_ok(@LOCATION, 'hg --config extensions.strip= -R hello strip -r tip')
46 assert is_outdated('hello')
47 cmd_ok(@LOCATION, 'hg -R hello pull')
48 assert !is_outdated('hello')
49}
50
51fn test_outdated() {
52 for m in ['pcre', 'libsodium', 'https://github.com/spytheman/vtray', 'nedpals.args'] {
53 cmd_ok(@LOCATION, '${vexe} install ${m}')
54 }
55 // "Outdate" previously installed. Leave out `libsodium`.
56 for m in ['pcre', 'vtray', os.join_path('nedpals', 'args')] {
57 cmd_ok(@LOCATION, 'git -C ${m} fetch --all')
58 cmd_ok(@LOCATION, 'git -C ${m} reset --hard HEAD~')
59 assert is_outdated(m)
60 }
61 res := cmd_ok(@LOCATION, '${vexe} outdated')
62 output := res.output.all_after('Outdated modules:')
63 assert output.len > 0, output
64 assert output.contains('pcre'), output
65 assert output.contains('vtray'), output
66 assert output.contains('nedpals.args'), output
67 assert !output.contains('libsodium'), output
68}
69