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 0eb3668 commit d9626b2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
48 changes: 48 additions & 0 deletions cmd/tools/vpm/install_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,51 @@ 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', '')!
if os.getenv('CI') != '' {
os.execute_or_exit('git config --global user.email "v@vi.com"')
os.execute_or_exit('git config --global user.name "V CI"')
}
mut res := os.execute('git init')
assert res.exit_code == 0, res.str()
res = os.execute('git add .')
assert res.exit_code == 0, res.str()
res = os.execute('git commit -m "initial commit"')
assert res.exit_code == 0, res.str()
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.
res = os.execute('git tag v0.1.0')
assert res.exit_code == 0, res.str()
mod.is_installed = false
mod.get_installed()
assert mod.is_installed
assert mod.installed_version == ''

os.execute('git checkout v0.1.0')
assert res.exit_code == 0, res.str()
mod.is_installed = false
mod.get_installed()
assert mod.is_installed
assert mod.installed_version == ''

os.execute('git branch -D master')
assert res.exit_code == 0, res.str()
os.execute('git reset --hard v0.1.0')
assert res.exit_code == 0, res.str()
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 d9626b2

Please sign in to comment.