module main import alpm import os fn test_unsatisfied_deps() ! { tmp := os.join_path(os.vtmp_dir(), 'vpac_test_deptest_${os.getpid()}') local := os.join_path(tmp, 'db', 'local') os.mkdir_all(os.join_path(tmp, 'root'))! os.mkdir_all(local)! defer { os.rmdir_all(tmp) or {} } os.write_file(os.join_path(local, 'ALPM_DB_VERSION'), '9\n')! for name, extra in { 'zsh': '' 'impl': '%PROVIDES%\nlibfoo.so=1-64\nvirtual\n\n' } { dir := os.join_path(local, '${name}-5.9-1') os.mkdir_all(dir)! os.write_file(os.join_path(dir, 'desc'), '%NAME%\n${name}\n\n%VERSION%\n5.9-1\n\n${extra}')! } handle := alpm.initialize(os.join_path(tmp, 'root') + '/', os.join_path(tmp, 'db') + '/')! defer { handle.release() or {} } pkgcache := handle.get_localdb()!.get_pkgcache() or { return error('empty db') } // names, versions and provisions, kept in the order and spelling given assert unsatisfied_deps(pkgcache, ['zsh', 'zsh>=5', 'zsh=5.9-1', 'virtual', 'libfoo.so=1-64']) == [] assert unsatisfied_deps(pkgcache, ['zsh<5', 'gone', 'zsh', 'zsh>6', 'libfoo.so=2']) == [ 'zsh<5', 'gone', 'zsh>6', 'libfoo.so=2', ] assert unsatisfied_deps(pkgcache, []) == [] } // no dependency, no run: pacman's -T speaks up as well fn test_deptest_needs_a_query() ! { if _ := deptest(ConfigDeptest{}) { assert false, 'an empty query ran' } else { assert err.msg().contains('no dependency'), err.msg() } } // deptest itself, against a db on disk: what it answers is what is missing, // in the order asked, and the db is only read fn test_deptest_reads_the_configured_db() ! { tmp := os.join_path(os.vtmp_dir(), 'vpac_test_deptest_run_${os.getpid()}') local := os.join_path(tmp, 'db', 'local') os.mkdir_all(os.join_path(tmp, 'root'))! os.mkdir_all(local)! saved_root, saved_db := root_path, db_path defer { root_path, db_path = saved_root, saved_db os.rmdir_all(tmp) or {} } root_path = os.join_path(tmp, 'root') + '/' db_path = os.join_path(tmp, 'db') + '/' os.write_file(os.join_path(local, 'ALPM_DB_VERSION'), '9\n')! // nothing installed: every dependency is missing, and that is an // answer, not an error assert deptest(ConfigDeptest{ query: ['zsh', 'sh'] })! == ['zsh', 'sh'] dir := os.join_path(local, 'zsh-5.9-1') os.mkdir_all(dir)! os.write_file(os.join_path(dir, 'desc'), '%NAME%\nzsh\n\n%VERSION%\n5.9-1\n\n%PROVIDES%\nsh\n\n')! assert deptest(ConfigDeptest{ query: ['zsh', 'sh'] })! == [] assert deptest(ConfigDeptest{ query: ['zsh>=6', 'sh', 'zsh=5.9-1', 'bash'] })! == [ 'zsh>=6', 'bash', ] // the same dependency asked twice is answered twice assert deptest(ConfigDeptest{ query: ['bash', 'bash'] })! == ['bash', 'bash'] // the run took no lock and left the db as it was assert !os.exists(os.join_path(tmp, 'db', 'db.lck')) assert os.ls(local)!.len == 2 // a db that is not there is an error, not 'everything is missing' db_path = os.join_path(tmp, 'nowhere') + '/' if got := deptest(ConfigDeptest{ query: ['zsh'] }) { assert false, 'a missing db answered ${got}' } }