Debian Codegraph @

tests/cache.rs

raw symbols SCIP
1 mod cacherust-analyzer cargo rust-apt 0.8.0 cache/ {
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#;
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write# as _;
4
5 use cxxrust-analyzer cargo cxx 1.0.199 crate/::{CxxVectorrust-analyzer cargo cxx 1.0.199 cxx_vector/CxxVector#, UniquePtrrust-analyzer cargo cxx 1.0.199 unique_ptr/UniquePtr#};
6 use rust_aptrust-analyzer cargo rust-apt 0.8.0 crate/::cacherust-analyzer cargo rust-apt 0.8.0 cache/::*;
7 use rust_aptrust-analyzer cargo rust-apt 0.8.0 crate/::rawrust-analyzer cargo rust-apt 0.8.0 raw/::{create_acquirerust-analyzer cargo rust-apt 0.8.0 acquire/raw/create_acquire()., IntoRawIterrust-analyzer cargo rust-apt 0.8.0 raw/IntoRawIter#, ItemDescrust-analyzer cargo rust-apt 0.8.0 acquire/raw/ItemDesc#};
8 use rust_aptrust-analyzer cargo rust-apt 0.8.0 crate/::utilrust-analyzer cargo rust-apt 0.8.0 util/::*;
9 use rust_aptrust-analyzer cargo rust-apt 0.8.0 crate/::{new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!, DepTyperust-analyzer cargo rust-apt 0.8.0 iterators/dependency/DepType#};
10
11 // This is a manual test. I don't know a good way to dynamically test this
12 // Maybe by installing a test-deb with certain depends and checking the
13 // packages?
14 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
15 fn auto_removeablerust-analyzer cargo rust-apt 0.8.0 cache/auto_removeable().() {
16 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
17
18 let sort = PackageSortrust-analyzer cargo rust-apt 0.8.0 cache/PackageSort#::defaultrust-analyzer cargo rust-apt 0.8.0 cache/impl#[PackageSort][Default]default().().auto_removablerust-analyzer cargo rust-apt 0.8.0 cache/impl#[PackageSort]auto_removable().().namesrust-analyzer cargo rust-apt 0.8.0 cache/impl#[PackageSort]names().();
19
20 for pkg in cache.packagesrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]packages().(&sort) {
21 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{}", pkg.namerust-analyzer cargo rust-apt 0.8.0 iterators/package/raw/impl#[PkgIterator]name().())
22 }
23 }
24
25 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
26 fn time_cache_iterrust-analyzer cargo rust-apt 0.8.0 cache/time_cache_iter().() {
27 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
28
29 let sort = PackageSortrust-analyzer cargo rust-apt 0.8.0 cache/PackageSort#::defaultrust-analyzer cargo rust-apt 0.8.0 cache/impl#[PackageSort][Default]default().().include_virtualrust-analyzer cargo rust-apt 0.8.0 cache/impl#[PackageSort]include_virtual().();
30
31 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#;
32
33 let now = Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#::nowrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]now().();
34 dbgrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/dbg!!(cache.packagesrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]packages().(&sort).countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().());
35 let elapsed = now.elapsedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]elapsed().();
36 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Elapsed: {:.2?}", elapsed);
37
38 let now = Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#::nowrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]now().();
39 dbgrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/dbg!!(cache.iterrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]iter().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().());
40 let elapsed = now.elapsedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]elapsed().();
41 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Elapsed: {:.2?}", elapsed);
42
43 let now = Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#::nowrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]now().();
44 dbgrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/dbg!!(unsafe { cache.beginrust-analyzer cargo rust-apt 0.8.0 cache/raw/impl#[PkgCacheFile]begin().().raw_iterrust-analyzer cargo rust-apt 0.8.0 raw/impl#[`UniquePtr<PkgIterator>`][IntoRawIter]raw_iter().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().() });
45 let elapsed = now.elapsedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]elapsed().();
46 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Elapsed: {:.2?}", elapsed);
47 }
48
49 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
50 fn with_debsrust-analyzer cargo rust-apt 0.8.0 cache/with_debs().() {
51 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!(&[
52 "tests/files/cache/apt.deb",
53 "tests/files/cache/dep-pkg1_0.0.1.deb",
54 ])
55 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
56
57 cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("apt").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().get_versionrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]get_version().("5000:1.0.0").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
58 cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("dep-pkg1").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
59
60 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!(&["tests/files/this-file-doesnt-exist.deb"]).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
61
62 // Check if it errors on a garbage empty file as well
63 // signal: 11, SIGSEGV: invalid memory reference
64 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!(&["tests/files/cache/pkg.deb"]).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
65 }
66
67 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
68 fn with_packagesrust-analyzer cargo rust-apt 0.8.0 cache/with_packages().() {
69 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!(&["tests/files/cache/Packages",]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
70
71 cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("apt").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().get_versionrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]get_version().("5000:1.0.0").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
72 cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("broken-or-dep").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
73 cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("dep-pkg1").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().get_versionrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]get_version().("0.0.1").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
74 cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("dep-pkg1").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().get_versionrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]get_version().("0.0.2").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
75 cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("dep-pkg2").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
76 cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("no-description").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
77
78 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!(&["tests/files/cache/Packages.gz"]).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
79 }
80
81 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
82 fn empty_depsrust-analyzer cargo rust-apt 0.8.0 cache/empty_deps().() {
83 // This would fail before https://gitlab.com/volian/rust-apt/-/merge_requests/29
84 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
85 let sort = PackageSortrust-analyzer cargo rust-apt 0.8.0 cache/PackageSort#::defaultrust-analyzer cargo rust-apt 0.8.0 cache/impl#[PackageSort][Default]default().();
86
87 // Iterate through all of the package and versions
88 for pkg in cache.packagesrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]packages().(&sort) {
89 for version in pkg.versionsrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]versions().() {
90 // Call depends_map to check for panic on null dependencies.
91 version.depends_maprust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]depends_map().();
92 }
93 }
94 }
95
96 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
97 fn parent_pkgrust-analyzer cargo rust-apt 0.8.0 cache/parent_pkg().() {
98 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
99 let pkg = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("apt").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
100 let version = pkg.versionsrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]versions().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/map/impl#[`Map<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
101 let parent = version.parentrust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]parent().();
102 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(pkg.indexrust-analyzer cargo rust-apt 0.8.0 iterators/package/raw/impl#[PkgIterator]index().(), parent.indexrust-analyzer cargo rust-apt 0.8.0 iterators/package/raw/impl#[PkgIterator]index().())
103 }
104
105 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
106 fn get_versionrust-analyzer cargo rust-apt 0.8.0 cache/get_version().() {
107 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
108 let pkg = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("apt").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
109
110 // The candidate for apt surely exists.
111 let cand = pkg.candidaterust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]candidate().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
112 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(pkg.get_versionrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]get_version().(cand.versionrust-analyzer cargo rust-apt 0.8.0 iterators/version/raw/impl#[VerIterator]version().()).is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
113
114 // I sure hope this doesn't exist.
115 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(pkg.get_versionrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]get_version().("9.0.0.1").is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().());
116 }
117
118 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
119 fn all_packagesrust-analyzer cargo rust-apt 0.8.0 cache/all_packages().() {
120 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
121 let sort = PackageSortrust-analyzer cargo rust-apt 0.8.0 cache/PackageSort#::defaultrust-analyzer cargo rust-apt 0.8.0 cache/impl#[PackageSort][Default]default().();
122
123 // All real packages should not be empty.
124 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(cache.packagesrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]packages().(&sort).nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/map/impl#[`Map<I, F>`][Iterator]next().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
125 for pkg in cache.packagesrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]packages().(&sort) {
126 // impl display??
127 // println!("{pkg}")
128 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{}:{}", pkg.namerust-analyzer cargo rust-apt 0.8.0 iterators/package/raw/impl#[PkgIterator]name().(), pkg.archrust-analyzer cargo rust-apt 0.8.0 iterators/package/raw/impl#[PkgIterator]arch().())
129 }
130 }
131
132 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
133 fn descriptionsrust-analyzer cargo rust-apt 0.8.0 cache/descriptions().() {
134 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
135
136 // Apt should exist
137 let pkg = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("apt").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
138 // Apt should have a candidate
139 let cand = pkg.candidaterust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]candidate().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
140 // Apt should be installed
141 let inst = pkg.installedrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]installed().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
142
143 // Assign installed descriptions
144 let inst_sum = inst.summaryrust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]summary().();
145 let inst_desc = inst.descriptionrust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]description().();
146
147 // Assign candidate descriptions
148 let cand_sum = cand.summaryrust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]summary().();
149 let cand_desc = cand.descriptionrust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]description().();
150
151 // If the lookup fails for whatever reason
152 // The summary and description are the same
153 assert_nerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_ne!!(inst_sum, inst_desc);
154 assert_nerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_ne!!(cand_sum, cand_desc);
155 dbgrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/dbg!!(inst_desc);
156 dbgrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/dbg!!(cand_desc);
157 }
158
159 // This should not segfault, but has in the past.
160 // See https://gitlab.com/volian/rust-apt/-/issues/28
161 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
162 fn no_descriptionrust-analyzer cargo rust-apt 0.8.0 cache/no_description().() {
163 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!(&["tests/files/cache/no-description_0.0.1.deb"]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
164
165 let pkg = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("no-description").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
166 let cand = pkg.candidaterust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]candidate().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
167 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(desc) = cand.descriptionrust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]description().() {
168 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{desc}");
169 }
170 }
171
172 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
173 fn version_urisrust-analyzer cargo rust-apt 0.8.0 cache/version_uris().() {
174 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
175 let pkg = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("apt").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
176 // Only test the candidate.
177 // It's possible for the installed version to have no uris
178 let cand = pkg.candidaterust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]candidate().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
179 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(cand.urisrust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]uris().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
180 dbgrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/dbg!!(cand.urisrust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]uris().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>());
181 }
182
183 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
184 fn depcache_markedrust-analyzer cargo rust-apt 0.8.0 cache/depcache_marked().() {
185 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
186 let pkg = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("apt").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
187 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().pkg.marked_installrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]marked_install().());
188 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().pkg.marked_upgraderust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]marked_upgrade().());
189 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().pkg.marked_deleterust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]marked_delete().());
190 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(pkg.marked_keeprust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]marked_keep().());
191 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().pkg.marked_downgraderust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]marked_downgrade().());
192 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().pkg.marked_reinstallrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]marked_reinstall().());
193 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().pkg.is_now_brokenrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]is_now_broken().());
194 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().pkg.is_inst_brokenrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]is_inst_broken().());
195 }
196
197 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
198 fn hashesrust-analyzer cargo rust-apt 0.8.0 cache/hashes().() {
199 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
200 let pkg = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("apt").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
201 // Apt could be installed, and the package no longer exists
202 // In the cache. For this case we grab the candidate so it won't fail.
203 let version = pkg.candidaterust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]candidate().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
204 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(version.sha256rust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]sha256().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
205 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(version.hashrust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]hash().("sha256").is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
206 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(version.sha512rust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]sha512().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().());
207 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(version.hashrust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]hash().("md5sum").is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
208 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(version.hashrust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]hash().("sha1").is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().())
209 }
210
211 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
212 fn shortnamerust-analyzer cargo rust-apt 0.8.0 cache/shortname().() {
213 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
214 let sort = PackageSortrust-analyzer cargo rust-apt 0.8.0 cache/PackageSort#::defaultrust-analyzer cargo rust-apt 0.8.0 cache/impl#[PackageSort][Default]default().();
215 for pkg in cache.packagesrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]packages().(&sort) {
216 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().pkg.namerust-analyzer cargo rust-apt 0.8.0 iterators/package/raw/impl#[PkgIterator]name().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().(':'))
217 }
218 }
219
220 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
221 fn dependsrust-analyzer cargo rust-apt 0.8.0 cache/depends().() {
222 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
223
224 let pkg = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("apt").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
225 let cand = pkg.candidaterust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]candidate().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
226 // Apt candidate should have dependencies
227 for deps in cand.dependenciesrust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]dependencies().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() {
228 for dep in deps.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() {
229 // Apt Dependencies should have targets
230 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(dep.all_targetsrust-analyzer cargo rust-apt 0.8.0 iterators/dependency/impl#[`BaseDep<'a>`]all_targets().().firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]first().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
231 }
232 }
233 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(cand.recommendsrust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]recommends().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
234 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(cand.suggestsrust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]suggests().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
235 // TODO: Add these as methods
236 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(cand.get_dependsrust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]get_depends().(&DepTyperust-analyzer cargo rust-apt 0.8.0 iterators/dependency/DepType#::Replacesrust-analyzer cargo rust-apt 0.8.0 iterators/dependency/DepType#Replaces#).is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
237 // This test seems to work on Debian Sid desktop systems, but not in a Debian
238 // Sid Docker container (and potentially other distros too). Leaving this
239 // commented out until a solution is found.
240 // assert!(cand.get_depends("Conflicts").is_some());
241 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(cand.get_dependsrust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]get_depends().(&DepTyperust-analyzer cargo rust-apt 0.8.0 iterators/dependency/DepType#::DpkgBreaksrust-analyzer cargo rust-apt 0.8.0 iterators/dependency/DepType#DpkgBreaks#).is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
242
243 // This part is basically just formatting an apt depends String
244 // Like you would see in `apt show`
245 let mut dep_str = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
246 dep_str.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().("Depends: ");
247 dbgrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/dbg!!(cand.depends_maprust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]depends_map().().getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&DepTyperust-analyzer cargo rust-apt 0.8.0 iterators/dependency/DepType#::Dependsrust-analyzer cargo rust-apt 0.8.0 iterators/dependency/DepType#Depends#).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().());
248 for dep in cand.depends_maprust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]depends_map().().getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&DepTyperust-analyzer cargo rust-apt 0.8.0 iterators/dependency/DepType#::Dependsrust-analyzer cargo rust-apt 0.8.0 iterators/dependency/DepType#Depends#).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() {
249 if dep.is_orrust-analyzer cargo rust-apt 0.8.0 iterators/dependency/impl#[`Dependency<'a>`]is_or().() {
250 let mut or_str = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
251 let total = dep.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1;
252 for (num, base_dep) in dep.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
253 or_str.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(base_dep.namerust-analyzer cargo rust-apt 0.8.0 iterators/dependency/impl#[`BaseDep<'a>`]name().());
254 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(comp) = base_dep.comp_typerust-analyzer cargo rust-apt 0.8.0 iterators/dependency/impl#[`BaseDep<'a>`]comp_type().() {
255 let _ = writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(or_str, "({} {})", comp, base_dep.versionrust-analyzer cargo rust-apt 0.8.0 iterators/dependency/impl#[`BaseDep<'a>`]version().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().());
256 }
257 if num rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().total {
258 or_str.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(" | ");
259 } else {
260 or_str.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(", ");
261 }
262 }
263 dep_str.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&or_str)
264 } else {
265 let lone_dep = dep.firstrust-analyzer cargo rust-apt 0.8.0 iterators/dependency/impl#[`Dependency<'a>`]first().();
266 dep_str.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(lone_dep.namerust-analyzer cargo rust-apt 0.8.0 iterators/dependency/impl#[`BaseDep<'a>`]name().());
267
268 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(comp) = lone_dep.comp_typerust-analyzer cargo rust-apt 0.8.0 iterators/dependency/impl#[`BaseDep<'a>`]comp_type().() {
269 let _ = writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(dep_str, " ({} {})", comp, lone_dep.versionrust-analyzer cargo rust-apt 0.8.0 iterators/dependency/impl#[`BaseDep<'a>`]version().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().());
270 }
271 dep_str.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(", ");
272 }
273 }
274 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{dep_str}");
275 }
276
277 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
278 fn test_hashmaprust-analyzer cargo rust-apt 0.8.0 cache/test_hashmap().() {
279 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
280
281 // clippy thinks that the package is mutable
282 // But it only hashes the ID and you can't really mutate a version
283 #[allow(clippy::mutable_key_type)]
284 let mut pkg_map = HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().();
285
286 // clippy thinks that the version is mutable
287 // But it only hashes the ID and you can't really mutate a version
288 #[allow(clippy::mutable_key_type)]
289 let mut ver_map = HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().();
290
291 let sort = PackageSortrust-analyzer cargo rust-apt 0.8.0 cache/PackageSort#::defaultrust-analyzer cargo rust-apt 0.8.0 cache/impl#[PackageSort][Default]default().();
292
293 // Iterate the package cache and add them to a hashmap
294 for pkg in cache.packagesrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]packages().(&sort) {
295 let value = pkg.archrust-analyzer cargo rust-apt 0.8.0 iterators/package/raw/impl#[PkgIterator]arch().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
296 pkg_map.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(pkg, value);
297 }
298
299 // Iterate the package map and add all the candidates into a hashmap
300 for (pkg, _arch) in pkg_map.iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]iter().() {
301 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cand) = pkg.candidaterust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]candidate().() {
302 let value = cand.archrust-analyzer cargo rust-apt 0.8.0 iterators/version/raw/impl#[VerIterator]arch().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
303 ver_map.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(cand, value);
304 }
305 }
306 // Doesn't need an assert. It won't compile
307 // if the structs can't go into a hashmap
308 }
309
310 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
311 fn debug_interfacesrust-analyzer cargo rust-apt 0.8.0 cache/debug_interfaces().() {
312 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
313 let pkg = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("apt").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
314 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{pkg:?}");
315 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{pkg:#?}");
316
317 let cand = pkg.candidaterust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]candidate().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
318 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{cand:?}");
319 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{cand:#?}");
320
321 for dep_vec in cand.depends_maprust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]depends_map().().valuesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]values().() {
322 for dep in dep_vec {
323 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{dep:#?}");
324 }
325 }
326
327 let pkg = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("python3:any").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
328 for provider in pkg.providesrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]provides().() {
329 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{provider:#?}")
330 }
331 }
332
333 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
334 fn display_interfacesrust-analyzer cargo rust-apt 0.8.0 cache/display_interfaces().() {
335 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
336 let pkg = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("apt").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
337
338 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{pkg}");
339
340 let cand = pkg.candidaterust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]candidate().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
341 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{cand}");
342
343 for dep_vec in cand.depends_maprust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]depends_map().().valuesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]values().() {
344 for dep in dep_vec {
345 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{dep}");
346 }
347 }
348
349 let pkg = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("python3:any").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
350 for provider in pkg.providesrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]provides().() {
351 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{provider}")
352 }
353 }
354
355 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
356 fn parent_deprust-analyzer cargo rust-apt 0.8.0 cache/parent_dep().() {
357 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
358 let sort = PackageSortrust-analyzer cargo rust-apt 0.8.0 cache/PackageSort#::defaultrust-analyzer cargo rust-apt 0.8.0 cache/impl#[PackageSort][Default]default().();
359
360 for pkg in cache.packagesrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]packages().(&sort) {
361 // Iterate over the reverse depends
362 // Iterating rdepends could segfault.
363 // See: https://gitlab.com/volian/rust-apt/-/merge_requests/36
364 for deps in pkg.rdependsrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]rdepends().().valuesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]values().() {
365 for dep in deps {
366 let base_dep = dep.firstrust-analyzer cargo rust-apt 0.8.0 iterators/dependency/impl#[`Dependency<'a>`]first().();
367 // Reverse Dependencies always have a version
368 base_dep.versionrust-analyzer cargo rust-apt 0.8.0 iterators/dependency/impl#[`BaseDep<'a>`]version().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
369 }
370 }
371
372 // There should be a candidate to iterate its regular deps
373 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cand) = pkg.candidaterust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]candidate().() {
374 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(deps) = cand.dependenciesrust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]dependencies().() {
375 for dep in &deps {
376 let base_dep = dep.firstrust-analyzer cargo rust-apt 0.8.0 iterators/dependency/impl#[`Dependency<'a>`]first().();
377 // Regular deps do not always have a version
378 base_dep.versionrust-analyzer cargo rust-apt 0.8.0 iterators/dependency/impl#[`BaseDep<'a>`]version().();
379 }
380 }
381 }
382 }
383 }
384
385 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
386 fn provides_listrust-analyzer cargo rust-apt 0.8.0 cache/provides_list().() {
387 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
388 let pkg = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("apt").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
389 let cand = pkg.candidaterust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]candidate().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
390 let provides_list: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = cand.providesrust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]provides().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
391
392 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(provides_list.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() == 1);
393 // 'apt' seems to always provide for 'apt-transport-https' at APT's version.
394 // If it ever doesn't, this test will break.
395 let provide = provides_list.firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]first().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
396 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(provide.namerust-analyzer cargo rust-apt 0.8.0 iterators/provider/raw/impl#[PrvIterator]name().() == "apt-transport-https");
397 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(provide.version_strrust-analyzer cargo rust-apt 0.8.0 iterators/provider/raw/impl#[PrvIterator]version_str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() == cand.versionrust-analyzer cargo rust-apt 0.8.0 iterators/version/raw/impl#[VerIterator]version().());
398 }
399
400 // This Test is for https://gitlab.com/volian/rust-apt/-/issues/24
401 // TODO: refactor and enable this test so it can run in the CI to make sure we
402 // don't regress. We need to get the lists dir from the apt config, and then
403 // maybe pick a random InRelease file Back that up, do the editing and then
404 // restore it at the end of the test. cache.packages should be an error and not
405 // segfault.
406 //
407 // #[test]
408 // fn test_segfault() {
409 // use std::io::Write;
410
411 // let mut f = std::fs::OpenOptions::new()
412 // .write(true)
413 // .append(true)
414 // .open("/var/lib/apt/lists/deb.debian.org_debian_dists_sid_InRelease")
415 // .unwrap();
416
417 // f.write_all(b"\ndsadasdasdas\n").unwrap();
418 // f.flush().unwrap();
419
420 // drop(f);
421
422 // let cache = new_cache!().unwrap();
423
424 // let sort = PackageSort::default();
425
426 // assert!(cache.packages(&sort).is_err())
427
428 /// This test is tied pretty closely to the currently available versions in
429 /// the Ubuntu/Debian repos. Feel free to adjust if you can verify its
430 /// needed.
431 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
432 fn rev_provides_listrust-analyzer cargo rust-apt 0.8.0 cache/rev_provides_list().() {
433 // Test concrete packages with provides.
434 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
435 let apt = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("apt").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
436 let ver = apt.candidaterust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]candidate().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
437 let pkg = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("apt-transport-https").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
438
439 {
440 let mut rev_provides_list = pkg.providesrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]provides().();
441 let provides_pkg = rev_provides_list.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/map/impl#[`Map<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
442
443 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(rev_provides_list.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/map/impl#[`Map<I, F>`][Iterator]next().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().());
444
445 let parent = unsafe { provides_pkg.target_pkgrust-analyzer cargo rust-apt 0.8.0 iterators/provider/raw/impl#[PrvIterator]target_pkg().() };
446 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parent.namerust-analyzer cargo rust-apt 0.8.0 iterators/package/raw/impl#[PkgIterator]name().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("apt"));
447 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(provides_pkg.version_strrust-analyzer cargo rust-apt 0.8.0 iterators/provider/raw/impl#[PrvIterator]version_str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), ver.versionrust-analyzer cargo rust-apt 0.8.0 iterators/version/raw/impl#[VerIterator]version().());
448 }
449
450 {
451 let mut rev_provides_list = pkg.providesrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]provides().().filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|p| match p.version_strrust-analyzer cargo rust-apt 0.8.0 iterators/provider/raw/impl#[PrvIterator]version_str().() {
452 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => false,
453 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(version) => version rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().ver.versionrust-analyzer cargo rust-apt 0.8.0 iterators/version/raw/impl#[VerIterator]version().(),
454 });
455
456 let provides_pkg = rev_provides_list.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
457 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(rev_provides_list.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]next().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().());
458
459 let parent = unsafe { provides_pkg.target_pkgrust-analyzer cargo rust-apt 0.8.0 iterators/provider/raw/impl#[PrvIterator]target_pkg().() };
460 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parent.namerust-analyzer cargo rust-apt 0.8.0 iterators/package/raw/impl#[PkgIterator]name().(), "apt");
461
462 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(provides_pkg.version_strrust-analyzer cargo rust-apt 0.8.0 iterators/provider/raw/impl#[PrvIterator]version_str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), ver.versionrust-analyzer cargo rust-apt 0.8.0 iterators/version/raw/impl#[VerIterator]version().());
463 }
464
465 {
466 let mut rev_provides_list = pkg.providesrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]provides().().filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|p| match p.version_strrust-analyzer cargo rust-apt 0.8.0 iterators/provider/raw/impl#[PrvIterator]version_str().() {
467 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => false,
468 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(version) => version rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."50000000000.0.0",
469 });
470 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(rev_provides_list.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]next().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().());
471 }
472
473 // Test a virtual package with provides.
474 {
475 let pkg = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("www-browser").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
476 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(pkg.providesrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]provides().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/map/impl#[`Map<I, F>`][Iterator]next().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
477 }
478 }
479
480 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
481 fn sourcesrust-analyzer cargo rust-apt 0.8.0 cache/sources().() {
482 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
483
484 let uris: UniquePtrrust-analyzer cargo cxx 1.0.199 unique_ptr/UniquePtr#<CxxVectorrust-analyzer cargo cxx 1.0.199 cxx_vector/CxxVector#<ItemDescrust-analyzer cargo rust-apt 0.8.0 acquire/raw/ItemDesc#>>;
485
486 let acquire = unsafe { create_acquirerust-analyzer cargo rust-apt 0.8.0 acquire/raw/create_acquire().() };
487 cache.get_indexesrust-analyzer cargo rust-apt 0.8.0 cache/raw/impl#[PkgCacheFile]get_indexes().(&acquire);
488
489 // If the source lists don't exists there is problems.
490 uris = unsafe { acquire.urisrust-analyzer cargo rust-apt 0.8.0 acquire/raw/impl#[PkgAcquire]uris().() };
491 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().uris.is_emptyrust-analyzer cargo cxx 1.0.199 cxx_vector/impl#[`CxxVector<T>`]is_empty().());
492 // This is an example of why the uri function is unsafe.
493 // uncommenting drop will cause it to SIBABRT
494 // drop(acquire);
495
496 for item in uris.iterrust-analyzer cargo cxx 1.0.199 cxx_vector/impl#[`CxxVector<T>`]iter().() {
497 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{} = {}", item.urirust-analyzer cargo rust-apt 0.8.0 acquire/raw/impl#[ItemDesc]uri().(), item.ownerrust-analyzer cargo rust-apt 0.8.0 acquire/raw/impl#[ItemDesc]owner().().dest_filerust-analyzer cargo rust-apt 0.8.0 acquire/raw/impl#[Item]dest_file().())
498 }
499 }
500
501 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
502 fn cache_countrust-analyzer cargo rust-apt 0.8.0 cache/cache_count().() {
503 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
504 match cache.depcacherust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]depcache().().disk_sizerust-analyzer cargo rust-apt 0.8.0 depcache/impl#[DepCache]disk_size().() {
505 DiskSpacerust-analyzer cargo rust-apt 0.8.0 util/DiskSpace#::Requirerust-analyzer cargo rust-apt 0.8.0 util/DiskSpace#Require#(num) => {
506 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(num, 0);
507 },
508 DiskSpacerust-analyzer cargo rust-apt 0.8.0 util/DiskSpace#::Freerust-analyzer cargo rust-apt 0.8.0 util/DiskSpace#Free#(num) => {
509 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Whoops it should be 0, not {num}.");
510 },
511 }
512 }
513
514 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
515 fn test_unit_strrust-analyzer cargo rust-apt 0.8.0 cache/test_unit_str().() {
516 let testcase = [
517 (1649267441664_u64, "1.50 TiB", "1.65 TB"),
518 (1610612736_u64, "1.50 GiB", "1.61 GB"),
519 (1572864_u64, "1.50 MiB", "1.57 MB"),
520 (1536_u64, "1.50 KiB", "1.54 KB"),
521 (1024_u64, "1024 B", "1.02 KB"),
522 (1_u64, "1 B", "1 B"),
523 ];
524
525 for (num, binary, decimal) in testcase {
526 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(binary, unit_strrust-analyzer cargo rust-apt 0.8.0 util/unit_str().(num, NumSysrust-analyzer cargo rust-apt 0.8.0 util/NumSys#::Binaryrust-analyzer cargo rust-apt 0.8.0 util/NumSys#Binary#));
527 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(decimal, unit_strrust-analyzer cargo rust-apt 0.8.0 util/unit_str().(num, NumSysrust-analyzer cargo rust-apt 0.8.0 util/NumSys#::Decimalrust-analyzer cargo rust-apt 0.8.0 util/NumSys#Decimal#));
528 }
529 }
530
531 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
532 // This test relies on the version of 'apt' being higher than 'dpkg'.
533 fn version_comparisonsrust-analyzer cargo rust-apt 0.8.0 cache/version_comparisons().() {
534 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
535 let apt = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("apt").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
536 let dpkg = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("dpkg").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
537
538 let apt_ver = apt.candidaterust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]candidate().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
539 let dpkg_ver = dpkg.candidaterust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]candidate().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
540
541 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(apt_ver >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt(). dpkg_ver);
542 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(dpkg_ver <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt(). apt_ver);
543 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(apt_ver != dpkg_ver);
544 }
545
546 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
547 // This test relies on 'neofetch' and 'gsasl-common' not being installed.
548 fn good_resolutionrust-analyzer cargo rust-apt 0.8.0 cache/good_resolution().() {
549 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
550 let pkg = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("neofetch").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
551
552 pkg.mark_installrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]mark_install().(true, true);
553 pkg.protectrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]protect().();
554 cache.resolverust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]resolve().(false).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
555
556 let pkg2 = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("gsasl-common").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
557 pkg2.mark_installrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]mark_install().(true, true);
558 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(pkg2.marked_installrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]marked_install().())
559 }
560
561 // For now `zeek` has broken dependencies so the resolver errors.
562 // If this test fails, potentially find a reason.
563 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
564 fn bad_resolutionrust-analyzer cargo rust-apt 0.8.0 cache/bad_resolution().() {
565 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
566
567 let pkg = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("zeek").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
568
569 pkg.mark_installrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]mark_install().(false, true);
570 pkg.protectrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]protect().();
571
572 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(cache.resolverust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]resolve().(false).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
573 }
574
575 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
576 fn depcache_clearrust-analyzer cargo rust-apt 0.8.0 cache/depcache_clear().() {
577 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
578 let pkg = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("apt").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
579
580 pkg.mark_deleterust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]mark_delete().(true);
581
582 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(pkg.marked_deleterust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]marked_delete().());
583
584 cache.depcacherust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]depcache().().clear_markedrust-analyzer cargo rust-apt 0.8.0 depcache/impl#[DepCache]clear_marked().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
585 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().pkg.marked_deleterust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]marked_delete().());
586 }
587
588 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
589 fn originsrust-analyzer cargo rust-apt 0.8.0 cache/origins().() {
590 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
591 let apt = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("apt").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
592 let apt_ver = apt.candidaterust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]candidate().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
593 let pkg_files = apt_ver.package_filesrust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]package_files().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>();
594
595 // Package files should not be empty if we got a candidate from `apt`.
596 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().pkg_files.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().());
597
598 for pkg_file in pkg_files {
599 // Apt should have all of these blocks in the package file.
600 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(pkg_file.filenamerust-analyzer cargo rust-apt 0.8.0 iterators/files/impl#[`PackageFile<'a>`]filename().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
601 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(pkg_file.archiverust-analyzer cargo rust-apt 0.8.0 iterators/files/impl#[`PackageFile<'a>`]archive().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
602
603 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{}", pkg_file.filenamerust-analyzer cargo rust-apt 0.8.0 iterators/files/impl#[`PackageFile<'a>`]filename().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().());
604
605 if pkg_file.is_downloadablerust-analyzer cargo rust-apt 0.8.0 iterators/files/raw/impl#[PkgFileIterator]is_downloadable().() {
606 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(pkg_file.originrust-analyzer cargo rust-apt 0.8.0 iterators/files/impl#[`PackageFile<'a>`]origin().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
607 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(pkg_file.codenamerust-analyzer cargo rust-apt 0.8.0 iterators/files/impl#[`PackageFile<'a>`]codename().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
608 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(pkg_file.labelrust-analyzer cargo rust-apt 0.8.0 iterators/files/impl#[`PackageFile<'a>`]label().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
609 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(pkg_file.siterust-analyzer cargo rust-apt 0.8.0 iterators/files/impl#[`PackageFile<'a>`]site().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
610 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(pkg_file.archrust-analyzer cargo rust-apt 0.8.0 iterators/files/impl#[`PackageFile<'a>`]arch().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
611 }
612
613 // These should be okay regardless.
614 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(pkg_file.componentrust-analyzer cargo rust-apt 0.8.0 iterators/files/impl#[`PackageFile<'a>`]component().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
615 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(pkg_file.index_typerust-analyzer cargo rust-apt 0.8.0 iterators/files/impl#[`PackageFile<'a>`]index_type().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
616
617 // Index should not be 0.
618 assert_nerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_ne!!(pkg_file.indexrust-analyzer cargo rust-apt 0.8.0 iterators/files/raw/impl#[PkgFileIterator]index().(), 0);
619
620 // Apt should likely be from a trusted repository.
621 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(pkg_file.index_filerust-analyzer cargo rust-apt 0.8.0 iterators/files/impl#[`PackageFile<'a>`]index_file().().is_trustedrust-analyzer cargo rust-apt 0.8.0 records/raw/impl#[IndexFile]is_trusted().());
622 // Print it in case I want to see.
623 // println!("{pkg_file}");
624 }
625 }
626
627 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
628 fn depcache_install_verrust-analyzer cargo rust-apt 0.8.0 cache/depcache_install_ver().() {
629 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!(&[
630 "tests/files/cache/dep-pkg1_0.0.1.deb",
631 "tests/files/cache/dep-pkg1_0.0.2.deb",
632 ])
633 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
634
635 let pkg = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("dep-pkg1").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
636 pkg.mark_installrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]mark_install().(false, false);
637
638 // This package is not installed, only marked
639 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(pkg.installedrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]installed().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().());
640
641 // This package is not installed
642 // but this will return the version to be installed
643 let install_ver = pkg.install_versionrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]install_version().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
644
645 // The version should match the latest because it's the default candidate.
646 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(install_ver.versionrust-analyzer cargo rust-apt 0.8.0 iterators/version/raw/impl#[VerIterator]version().() == "0.0.2");
647
648 let old_ver = pkg.get_versionrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]get_version().("0.0.1").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
649 old_ver.set_candidaterust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]set_candidate().();
650 pkg.mark_installrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]mark_install().(false, false);
651
652 let install_ver = pkg.install_versionrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]install_version().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
653
654 // Now it should match the old version we just marked.
655 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(install_ver.versionrust-analyzer cargo rust-apt 0.8.0 iterators/version/raw/impl#[VerIterator]version().() == "0.0.1");
656 }
657
658 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
659 fn broken_pkgsrust-analyzer cargo rust-apt 0.8.0 cache/broken_pkgs().() {
660 let cache = new_cacherust-analyzer cargo rust-apt 0.8.0 macros/new_cache!!(&["tests/files/cache/broken-or-dep_0.0.1.deb"]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
661
662 let pkg = cache.getrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]get().("broken-or-dep").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
663
664 // let config = Config::new();
665 // config.set("Debug::pkgProblemResolver", "1");
666
667 pkg.protectrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]protect().();
668 pkg.mark_installrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]mark_install().(false, true);
669
670 let expected = concatrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/concat!!(
671 " broken-or-dep : Depends: not-exist (>= 3.6.1) but it is not installable or\n",
672 " really-not-exist but it is not installable\n",
673 " Depends: python3-not-exist but it is not installable\n",
674 );
675
676 let err = cache.resolverust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]resolve().(false).unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().();
677
678 for pkg in cache.iterrust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]iter().() {
679 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(broken) = show_broken_pkgrust-analyzer cargo rust-apt 0.8.0 util/show_broken_pkg().(&cache, &pkg, false) {
680 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(broken, expected);
681 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{broken}");
682 }
683 }
684 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{err}");
685 }
686 }