1 Commits

Author SHA1 Message Date
ea4d8e706b add mockrepo tests
All checks were successful
Gentoo Utils / build-oci-image (pull_request) Successful in 4s
Gentoo Utils / build (pull_request) Successful in 52s
2025-12-13 03:27:55 +00:00
10 changed files with 57 additions and 43 deletions

View File

@@ -0,0 +1 @@
base

View File

@@ -1 +0,0 @@
../../base

View File

@@ -0,0 +1,2 @@
USE="selinux"
SELINUX_TYPE="sys.subj.portage"

View File

@@ -0,0 +1 @@
*sec-policy/selinux-base

View File

@@ -0,0 +1 @@
caps

View File

@@ -0,0 +1 @@
jit

View File

@@ -0,0 +1 @@
app-editors/emacs -default

View File

@@ -0,0 +1,3 @@
../base
../features/selinux
../features/emacs/gui

View File

@@ -0,0 +1 @@
-jit

View File

@@ -1,42 +1,46 @@
use std::env; use std::env::args;
use gentoo_utils::{atom::Atom, repo::Repo, useflag::UseFlag}; use gentoo_utils::{atom::Atom, repo::Repo, useflag::UseFlag};
use itertools::Itertools; use itertools::Itertools;
fn main() { fn main() {
let repo_path = env::args().nth(1).expect("expected path to mock repo"); let repo_path = args()
let repo = Repo::new(&repo_path).expect("failed to open repo"); .nth(1)
.expect("expected path to mockrepo as first argument");
let repo = Repo::new(&repo_path).expect("failed to read repo");
let profile = repo let profile = repo
.evaluate_profile("features/emacs/gui") .evaluate_profile("gentoo-desktop")
.expect("failed to evaluate profile"); .expect("failed to evaluate profile");
assert_eq!( let r#use = profile.make_defaults()["USE"]
profile.make_defaults()["USE"] .split_ascii_whitespace()
.split_ascii_whitespace() .sorted()
.sorted() .collect::<Vec<_>>();
.collect::<Vec<_>>(),
vec!["base", "emacs"] assert_eq!(r#use, vec!["base", "emacs", "selinux",]);
);
let packages = profile
.packages()
.iter()
.map(Atom::to_string)
.sorted()
.collect::<Vec<_>>();
assert_eq!( assert_eq!(
profile packages,
.packages() vec!["app-editors/emacs", "sec-policy/selinux-base"]
.iter()
.map(Atom::to_string)
.collect::<Vec<_>>(),
vec!["app-editors/emacs"]
); );
assert_eq!( let packages_mask = profile
profile .package_mask()
.package_mask() .iter()
.iter() .map(Atom::to_string)
.map(Atom::to_string) .sorted()
.collect::<Vec<_>>(), .collect::<Vec<_>>();
vec!["app-editors/vim"]
);
let emacs_package_use = profile assert_eq!(packages_mask, vec!["app-editors/vim"]);
let emacs_use = profile
.package_use() .package_use()
.iter() .iter()
.find_map(|(atom, flags)| { .find_map(|(atom, flags)| {
@@ -46,22 +50,22 @@ fn main() {
None None
} }
}) })
.expect("failed to read package.use settings for app-editors/emacs"); .unwrap()
.iter()
.map(UseFlag::to_string)
.sorted()
.collect::<Vec<_>>();
assert_eq!( assert_eq!(emacs_use, vec!["gui"]);
emacs_package_use
.iter()
.map(UseFlag::to_string)
.collect::<Vec<_>>(),
vec!["default", "gui"]
);
assert_eq!( let use_force = profile
profile .use_force()
.use_force() .iter()
.iter() .map(UseFlag::to_string)
.map(UseFlag::to_string) .sorted()
.collect::<Vec<_>>(), .collect::<Vec<_>>();
vec!["default", "gui"]
); assert_eq!(use_force, vec!["base", "caps", "default", "gui"]);
assert!(profile.use_mask().is_empty());
} }