module coracle import nspkg as facade import nspkg.engine import os fn test_option_patterns_preserve_errno_and_match_c() ! { root := os.join_path(os.vtmp_dir(), 'alpm-option-patterns-${os.getpid()}') os.mkdir_all(root)! defer { os.rmdir_all(root) or { eprintln(err) } } old := initialize('/', root)! defer { old.release() or { eprintln(err) } } public := facade.initialize('/', root)! defer { public.release() or { eprintln(err) } } mut native := engine.initialize('/', root)! defer { native.release() or { eprintln(err) } } sets := [ []string{}, ['usr/*'], ['usr/*', '!usr/keep'], ['!usr/keep', 'usr/*'], [r'\!literal', r'file\?.txt', r'\leading'], ['file[ab]', '!fileb', 'file?'], ['usr/*\x00ignored'], ] paths := ['usr/file', 'usr/keep', 'usr/dir/file', 'other', '!literal', 'file?.txt', 'file1.txt', 'leading', 'filea', 'fileb', 'usr/file\x00other'] mut mismatches := []string{} for option in [engine.StringListOption.no_upgrade, .no_extract] { for patterns in sets { mut input := &facade.List(unsafe { nil }) for value in patterns { assert (&input).append_strdup(value) != unsafe { nil } } defer { input.free_inner(C.free) input.free() } if option == .no_upgrade { old.option_set_noupgrades(unsafe { &List(input) })! public.option_set_noupgrades(input)! } else { old.option_set_no_extracts(unsafe { &List(input) })! public.option_set_no_extracts(input)! } native.set_string_list(option, patterns)! for path in paths { for prior in [false, true] { old.option_get_root() public.option_get_root() native.validate_handle()! if prior { if _ := old.register_syncdb('', 0) { assert false } if _ := public.register_syncdb('', 0) { assert false } if _ := native.register_syncdb('', 0) { assert false } } // handle.c's matchers bypass CHECK_HANDLE, so an earlier error survives. expected := if option == .no_upgrade { C.oracle_alpm_option_match_noupgrade(old, path.str) } else { C.oracle_alpm_option_match_noextract(old, path.str) } code := int(old.errno()) assert code == if prior { 6 } else { 0 } actual := native.match_option(option, path)! answer := if option == .no_upgrade { public.option_match_no_upgrade(path) } else { public.option_match_no_extract(path) } if actual != expected || int(native.errno()) != code { mismatches << '${option}/${patterns}/${path}/${prior}/core: ${actual}:${int(native.errno())} != ${expected}:${code}' } if answer != (expected == 0) || int(public.errno()) != code { mismatches << '${option}/${patterns}/${path}/${prior}/public: ${answer}:${int(public.errno())} != ${expected == 0}:${code}' } } } } } assert mismatches.len == 0, mismatches[..int_min(8, mismatches.len)].join('\n') }