Skip to content

Commit

Permalink
add get_installed test
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Nov 28, 2023
1 parent 191a80f commit b40475b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
46 changes: 46 additions & 0 deletions cmd/tools/vpm/install_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,49 @@ fn test_install_potentially_conflicting() {
manifest = get_vmod('iui')
assert manifest.name == 'iui'
}

fn test_get_installed_version() {
test_project_path := os.join_path(test_path, 'test_project')
os.mkdir_all(test_project_path)!
os.chdir(test_project_path)!
os.write_file('v.mod', '')!
os.execute_opt('git init && git add . && git commit -m "initial commit"') or {
assert false, err.msg()
return
}
mut mod := Module{
install_path: test_project_path
}
mod.get_installed()
assert mod.is_installed
assert mod.installed_version == ''

// Create a tag -> latests commit and tag are at the same state,
// but it should not be treated as a version installation, when there is another head branch.
os.execute_opt('git tag v0.1.0') or {
assert false, err.msg()
return
}
mod.is_installed = false
mod.get_installed()
assert mod.is_installed
assert mod.installed_version == ''

os.execute_opt('git checkout v0.1.0') or {
assert false, err.msg()
return
}
mod.is_installed = false
mod.get_installed()
assert mod.is_installed
assert mod.installed_version == ''

os.execute_opt('git branch -D master && git reset --hard v0.1.0') or {
assert false, err.msg()
return
}
mod.is_installed = false
mod.get_installed()
assert mod.is_installed
assert mod.installed_version == 'v0.1.0'
}
2 changes: 1 addition & 1 deletion cmd/tools/vpm/parse.v
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ fn (mut p Parser) parse_module(m string) {
}
}

// TODO: add unit test
fn (mut m Module) get_installed() {
refs := os.execute_opt('git ls-remote --refs ${m.install_path}') or { return }
vpm_log(@FILE_LINE, @FN, 'refs: ${refs}')
m.is_installed = true
// In case the head just temporarily matches a tag, make sure that there
// really is a version installation before adding it as `installed_version`.
Expand Down

0 comments on commit b40475b

Please sign in to comment.