| 1 | module main |
| 2 | |
| 3 | import nspkg |
| 4 | import os |
| 5 | |
| 6 | fn test_unsatisfied_deps() ! { |
| 7 | tmp := os.join_path(os.vtmp_dir(), 'vpac_test_deptest_${os.getpid()}') |
| 8 | local := os.join_path(tmp, 'db', 'local') |
| 9 | os.mkdir_all(os.join_path(tmp, 'root'))! |
| 10 | os.mkdir_all(local)! |
| 11 | defer { os.rmdir_all(tmp) or {} } |
| 12 | os.write_file(os.join_path(local, 'ALPM_DB_VERSION'), '9\n')! |
| 13 | for name, extra in { |
| 14 | 'zsh': '' |
| 15 | 'impl': '%PROVIDES%\nlibfoo.so=1-64\nvirtual\n\n' |
| 16 | } { |
| 17 | dir := os.join_path(local, '${name}-5.9-1') |
| 18 | os.mkdir_all(dir)! |
| 19 | os.write_file(os.join_path(dir, 'desc'), '%NAME%\n${name}\n\n%VERSION%\n5.9-1\n\n${extra}')! |
| 20 | } |
| 21 | handle := nspkg.initialize(os.join_path(tmp, 'root') + '/', os.join_path(tmp, 'db') + '/')! |
| 22 | defer { handle.release() or {} } |
| 23 | pkgcache := handle.get_localdb()!.get_pkgcache() or { return error('empty db') } |
| 24 | |
| 25 | // names, versions and provisions, kept in the order and spelling given |
| 26 | assert unsatisfied_deps(pkgcache, ['zsh', 'zsh>=5', 'zsh=5.9-1', 'virtual', 'libfoo.so=1-64']) == [] |
| 27 | assert unsatisfied_deps(pkgcache, ['zsh<5', 'gone', 'zsh', 'zsh>6', 'libfoo.so=2']) == [ |
| 28 | 'zsh<5', |
| 29 | 'gone', |
| 30 | 'zsh>6', |
| 31 | 'libfoo.so=2', |
| 32 | ] |
| 33 | assert unsatisfied_deps(pkgcache, []) == [] |
| 34 | } |
| 35 | |
| 36 | // no dependency, no run: pacman's -T speaks up as well |
| 37 | fn test_deptest_needs_a_query() ! { |
| 38 | if _ := deptest(ConfigDeptest{}) { |
| 39 | assert false, 'an empty query ran' |
| 40 | } else { |
| 41 | assert err.msg().contains('no dependency'), err.msg() |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | // deptest itself, against a db on disk: what it answers is what is missing, |
| 46 | // in the order asked, and the db is only read |
| 47 | fn test_deptest_reads_the_configured_db() ! { |
| 48 | tmp := os.join_path(os.vtmp_dir(), 'vpac_test_deptest_run_${os.getpid()}') |
| 49 | local := os.join_path(tmp, 'db', 'local') |
| 50 | os.mkdir_all(os.join_path(tmp, 'root'))! |
| 51 | os.mkdir_all(local)! |
| 52 | saved_root, saved_db := root_path, db_path |
| 53 | defer { |
| 54 | root_path, db_path = saved_root, saved_db |
| 55 | os.rmdir_all(tmp) or {} |
| 56 | } |
| 57 | root_path = os.join_path(tmp, 'root') + '/' |
| 58 | db_path = os.join_path(tmp, 'db') + '/' |
| 59 | os.write_file(os.join_path(local, 'ALPM_DB_VERSION'), '9\n')! |
| 60 | // nothing installed: every dependency is missing, and that is an |
| 61 | // answer, not an error |
| 62 | assert deptest(ConfigDeptest{ query: ['zsh', 'sh'] })! == ['zsh', 'sh'] |
| 63 | dir := os.join_path(local, 'zsh-5.9-1') |
| 64 | os.mkdir_all(dir)! |
| 65 | os.write_file(os.join_path(dir, 'desc'), '%NAME%\nzsh\n\n%VERSION%\n5.9-1\n\n%PROVIDES%\nsh\n\n')! |
| 66 | assert deptest(ConfigDeptest{ query: ['zsh', 'sh'] })! == [] |
| 67 | assert deptest(ConfigDeptest{ query: ['zsh>=6', 'sh', 'zsh=5.9-1', 'bash'] })! == [ |
| 68 | 'zsh>=6', |
| 69 | 'bash', |
| 70 | ] |
| 71 | // the same dependency asked twice is answered twice |
| 72 | assert deptest(ConfigDeptest{ query: ['bash', 'bash'] })! == ['bash', 'bash'] |
| 73 | // the run took no lock and left the db as it was |
| 74 | assert !os.exists(os.join_path(tmp, 'db', 'db.lck')) |
| 75 | assert os.ls(local)!.len == 2 |
| 76 | // a db that is not there is an error, not 'everything is missing' |
| 77 | db_path = os.join_path(tmp, 'nowhere') + '/' |
| 78 | if got := deptest(ConfigDeptest{ query: ['zsh'] }) { |
| 79 | assert false, 'a missing db answered ${got}' |
| 80 | } |
| 81 | } |
| 82 | |