Debian Codegraph @

tests/config.rs

raw symbols SCIP
1 mod configrust-analyzer cargo rust-apt 0.8.0 config/ {
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/::VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#;
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#;
4
5 use rust_aptrust-analyzer cargo rust-apt 0.8.0 crate/::configrust-analyzer cargo rust-apt 0.8.0 config/::Configrust-analyzer cargo rust-apt 0.8.0 config/Config#;
6
7 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
8 fn clearrust-analyzer cargo rust-apt 0.8.0 config/clear().() {
9 // Test to make sure that the config populates properly.
10 // Config will be empty if it hasn't been initialized.
11 let config = Configrust-analyzer cargo rust-apt 0.8.0 config/Config#::new_clearrust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]new_clear().();
12 config.clear_allrust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]clear_all().();
13
14 let empty_config = config.findrust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]find().("APT::Architecture", "");
15 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().config.containsrust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]contains().("APT::Architecture"));
16 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(empty_config.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().());
17
18 // Reset the configuration which will clear and reinit.
19 config.resetrust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]reset().();
20
21 // Now it should NOT be empty.
22 let config_dump = config.findrust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]find().("APT::Architecture", "");
23 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(config.containsrust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]contains().("APT::Architecture"));
24 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().config_dump.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().());
25 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{}", config.dumprust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]dump().());
26 }
27
28 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
29 fn find_and_setrust-analyzer cargo rust-apt 0.8.0 config/find_and_set().() {
30 let config = Configrust-analyzer cargo rust-apt 0.8.0 config/Config#::new_clearrust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]new_clear().();
31 let key = "rust_apt::NotExist";
32
33 // Find our key. It should not exist.
34 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(config.findrust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]find().(key, "None"), "None");
35
36 // Set the key to something.
37 config.setrust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]set().(key, "Exists!");
38
39 // Find again and it should be there.
40 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(config.findrust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]find().(key, "None"), "Exists!");
41
42 // Test other find functions on known defaults.
43 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().config.boolrust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]bool().("APT::Install-Suggests", true));
44 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(config.intrust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]int().("APT::Install-Suggests", 20), 0);
45
46 // Directory is different in CI. Just check for the name
47 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
48 config
49 .filerust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]file().("Dir::Cache::pkgcache", "")
50 .splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().('/')
51 .anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|x| x == "pkgcache.bin")
52 );
53 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
54 config.dirrust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]dir().("Dir::Etc::sourceparts", ""),
55 "/etc/apt/sources.list.d/"
56 );
57
58 // Check if we can set a configuration list and retrieve it.
59 // Make sure that the target vector is empty.
60 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(config.find_vectorrust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]find_vector().("rust_apt::aptlist").is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().());
61
62 // Now fill our configuration vector and set it.
63 let apt_list = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["this", "is", "my", "apt", "list"];
64 config.set_vectorrust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]set_vector().("rust_apt::aptlist", &apt_list);
65
66 // Retrieve a new vector from the configuration.
67 let apt_vector = config.find_vectorrust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]find_vector().("rust_apt::aptlist");
68
69 // If everything went smooth, our original vector should match the new one
70 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(apt_list, apt_vector);
71
72 // Now test if we can remove a single value from the list.
73 config.clear_valuerust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]clear_value().("rust_apt::aptlist", "my");
74
75 // This will let us know if it worked!
76 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
77 config.find_vectorrust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]find_vector().("rust_apt::aptlist"),
78 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["this", "is", "apt", "list"]
79 );
80
81 // Finally test and see if we can clear the entire list.
82 config.clearrust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]clear().("rust_apt::aptlist");
83 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(config.find_vectorrust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]find_vector().("rust_apt::aptlist").is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().());
84 }
85
86 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
87 fn get_architecturesrust-analyzer cargo rust-apt 0.8.0 config/get_architectures().() {
88 let config = Configrust-analyzer cargo rust-apt 0.8.0 config/Config#::newrust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]new().();
89
90 let output = dbgrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/dbg!!(
91 Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8().(
92 Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]new().("dpkg")
93 .argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().("--print-architecture")
94 .outputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]output().()
95 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
96 .stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#stdout.,
97 )
98 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
99 );
100
101 let arches = dbgrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/dbg!!(config.get_architecturesrust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]get_architectures().());
102
103 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(arches.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&output.strip_suffixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_suffix().('\n').unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
104 }
105
106 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
107 fn config_treerust-analyzer cargo rust-apt 0.8.0 config/config_tree().() {
108 // An example of how you might walk the entire config tree.
109 let config = Configrust-analyzer cargo rust-apt 0.8.0 config/Config#::newrust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]new().();
110
111 let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(tree) = config.root_treerust-analyzer cargo rust-apt 0.8.0 config/impl#[Config]root_tree().() else {
112 return;
113 };
114
115 let mut stack = VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T>`]new().();
116 stack.push_backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]push_back().((tree, 0));
117
118 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((node, indent)) = stack.pop_backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]pop_back().() {
119 let indent_str = " ".repeatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]repeat().(indent);
120
121 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(item) = node.siblingrust-analyzer cargo rust-apt 0.8.0 config/impl#[ConfigTree]sibling().() {
122 stack.push_backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]push_back().((item, indent));
123 }
124
125 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(item) = node.childrust-analyzer cargo rust-apt 0.8.0 config/impl#[ConfigTree]child().() {
126 stack.push_backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]push_back().((item, indent rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().2));
127 }
128
129 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(tag) = node.tagrust-analyzer cargo rust-apt 0.8.0 config/impl#[ConfigTree]tag().() {
130 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().tag.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() {
131 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{}Tag: {}", indent_str, tag);
132 }
133 }
134
135 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = node.valuerust-analyzer cargo rust-apt 0.8.0 config/impl#[ConfigTree]value().() {
136 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().value.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() {
137 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{}Value: {}", indent_str, value);
138 }
139 }
140 }
141 }
142 }