Skip to content

Commit

Permalink
tools.vpm: refine is_outdated, add v outdated test (#20215)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm authored Dec 19, 2023
1 parent 57acf20 commit 3b0802d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
8 changes: 6 additions & 2 deletions cmd/tools/vpm/outdated.v
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,15 @@ fn is_outdated(path string) bool {
vpm_log(@FILE_LINE, @FN, 'cmd: ${cmd}')
res := os.execute(cmd)
vpm_log(@FILE_LINE, @FN, 'output: ${res.output}')
if res.exit_code != 0 {
return false
}
if vcs == .hg {
return res.exit_code == 0
// HG uses only one outdated step. If it has not failed, the module is outdated.
return true
}
outputs << res.output
}
// Compare the current and latest origin commit sha.
return vcs == .git && outputs[1] != outputs[2]
return outputs[1] != outputs[2]
}
21 changes: 20 additions & 1 deletion cmd/tools/vpm/outdated_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn testsuite_end() {
fn test_is_outdated_git_module() {
os.execute_or_exit('git clone https://github.com/vlang/libsodium.git')
assert !is_outdated('libsodium')
os.execute_or_exit('git -C libsodium reset --hard HEAD~1')
os.execute_or_exit('git -C libsodium reset --hard HEAD~')
assert is_outdated('libsodium')
os.execute_or_exit('git -C libsodium pull')
assert !is_outdated('libsodium')
Expand All @@ -42,3 +42,22 @@ fn test_is_outdated_hg_module() {
os.execute_or_exit('hg -R hello pull')
assert !is_outdated('hello')
}

fn test_outdated() {
for m in ['pcre', 'libsodium', 'https://github.com/spytheman/vtray', 'nedpals.args'] {
os.execute_or_exit('${vexe} install ${m}')
}
// "Outdate" previously installed. Leave out `libsodium`.
for m in ['pcre', 'vtray', os.join_path('nedpals', 'args')] {
os.execute_or_exit('git -C ${m} fetch --unshallow')
os.execute_or_exit('git -C ${m} reset --hard HEAD~')
assert is_outdated(m)
}
res := os.execute('${vexe} outdated')
assert res.exit_code == 0, res.str()
assert res.output.contains('Outdated modules:'), res.output
assert res.output.contains('pcre'), res.output
assert res.output.contains('vtray'), res.output
assert res.output.contains('nedpals.args'), res.output
assert !res.output.contains('libsodium'), res.output
}

0 comments on commit 3b0802d

Please sign in to comment.