| 1 | module coracle |
| 2 | |
| 3 | import nspkg as facade |
| 4 | import nspkg.engine |
| 5 | import os |
| 6 | |
| 7 | fn test_option_patterns_preserve_errno_and_match_c() ! { |
| 8 | root := os.join_path(os.vtmp_dir(), 'alpm-option-patterns-${os.getpid()}') |
| 9 | os.mkdir_all(root)! |
| 10 | defer { os.rmdir_all(root) or { eprintln(err) } } |
| 11 | old := initialize('/', root)! |
| 12 | defer { old.release() or { eprintln(err) } } |
| 13 | public := facade.initialize('/', root)! |
| 14 | defer { public.release() or { eprintln(err) } } |
| 15 | mut native := engine.initialize('/', root)! |
| 16 | defer { native.release() or { eprintln(err) } } |
| 17 | sets := [ |
| 18 | []string{}, |
| 19 | ['usr/*'], |
| 20 | ['usr/*', '!usr/keep'], |
| 21 | ['!usr/keep', 'usr/*'], |
| 22 | [r'\!literal', r'file\?.txt', r'\leading'], |
| 23 | ['file[ab]', '!fileb', 'file?'], |
| 24 | ['usr/*\x00ignored'], |
| 25 | ] |
| 26 | paths := ['usr/file', 'usr/keep', 'usr/dir/file', 'other', '!literal', 'file?.txt', 'file1.txt', |
| 27 | 'leading', 'filea', 'fileb', 'usr/file\x00other'] |
| 28 | mut mismatches := []string{} |
| 29 | for option in [engine.StringListOption.no_upgrade, .no_extract] { |
| 30 | for patterns in sets { |
| 31 | mut input := &facade.List(unsafe { nil }) |
| 32 | for value in patterns { |
| 33 | assert (&input).append_strdup(value) != unsafe { nil } |
| 34 | } |
| 35 | defer { |
| 36 | input.free_inner(C.free) |
| 37 | input.free() |
| 38 | } |
| 39 | if option == .no_upgrade { |
| 40 | old.option_set_noupgrades(unsafe { &List(input) })! |
| 41 | public.option_set_noupgrades(input)! |
| 42 | } else { |
| 43 | old.option_set_no_extracts(unsafe { &List(input) })! |
| 44 | public.option_set_no_extracts(input)! |
| 45 | } |
| 46 | native.set_string_list(option, patterns)! |
| 47 | for path in paths { |
| 48 | for prior in [false, true] { |
| 49 | old.option_get_root() |
| 50 | public.option_get_root() |
| 51 | native.validate_handle()! |
| 52 | if prior { |
| 53 | if _ := old.register_syncdb('', 0) { |
| 54 | assert false |
| 55 | } |
| 56 | if _ := public.register_syncdb('', 0) { |
| 57 | assert false |
| 58 | } |
| 59 | if _ := native.register_syncdb('', 0) { |
| 60 | assert false |
| 61 | } |
| 62 | } |
| 63 | // handle.c's matchers bypass CHECK_HANDLE, so an earlier error survives. |
| 64 | expected := if option == .no_upgrade { |
| 65 | C.oracle_alpm_option_match_noupgrade(old, path.str) |
| 66 | } else { |
| 67 | C.oracle_alpm_option_match_noextract(old, path.str) |
| 68 | } |
| 69 | code := int(old.errno()) |
| 70 | assert code == if prior { 6 } else { 0 } |
| 71 | actual := native.match_option(option, path)! |
| 72 | answer := if option == .no_upgrade { |
| 73 | public.option_match_no_upgrade(path) |
| 74 | } else { |
| 75 | public.option_match_no_extract(path) |
| 76 | } |
| 77 | if actual != expected || int(native.errno()) != code { |
| 78 | mismatches << '${option}/${patterns}/${path}/${prior}/core: ${actual}:${int(native.errno())} != ${expected}:${code}' |
| 79 | } |
| 80 | if answer != (expected == 0) || int(public.errno()) != code { |
| 81 | mismatches << '${option}/${patterns}/${path}/${prior}/public: ${answer}:${int(public.errno())} != ${expected == 0}:${code}' |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | assert mismatches.len == 0, mismatches[..int_min(8, mismatches.len)].join('\n') |
| 88 | } |
| 89 | |