Skip to content

Commit 8d879e4

Browse files
committed
fix tests
1 parent 5e0f9b4 commit 8d879e4

12 files changed

Lines changed: 45 additions & 41 deletions

File tree

ck3-tiger/benches/criterion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ fn bench_multiple(c: &mut Criterion) {
5555
BenchmarkId::new("mods", format!("{}. {}", index + 1, modfile_path.display())),
5656
modfile_path,
5757
|b, modfile_path| {
58-
b.iter(|| bench_mod(&vanilla_dir, modfile_path));
58+
b.iter(|| bench_mod(&vanilla_dir, modfile_path.clone()));
5959
},
6060
);
6161
}
6262

6363
group.finish();
6464
}
6565

66-
fn bench_mod(vanilla_dir: &Path, modfile_path: &PathBuf) {
66+
fn bench_mod(vanilla_dir: &Path, modfile_path: PathBuf) {
6767
let fileset = Fileset::builder(Some(vanilla_dir)).with_modfile(modfile_path).unwrap();
6868
let mut everything = Everything::new(fileset, None, None, None).unwrap();
6969
everything.load_all();

ck3-tiger/src/bin/scan-mod-ck3-tiger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn main() -> Result<()> {
3434
if args.modpath.is_dir() {
3535
args.modpath.push("descriptor.mod");
3636
}
37-
let fileset = Fileset::builder(None).with_modfile(&args.modpath)?;
37+
let fileset = Fileset::builder(None).with_modfile(args.modpath)?;
3838
let mut everything = Everything::new(fileset, None, None, None)?;
3939

4040
everything.load_all();

src/everything.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,8 +1345,9 @@ mod benchmark {
13451345
fn load_provinces_ck3(bencher: Bencher, (vanilla_dir, modpath): (&str, &PathBuf)) {
13461346
bencher
13471347
.with_inputs(|| {
1348-
let fileset =
1349-
Fileset::builder(Some(Path::new(vanilla_dir))).with_modfile(modpath).unwrap();
1348+
let fileset = Fileset::builder(Some(Path::new(vanilla_dir)))
1349+
.with_modfile(modpath.clone())
1350+
.unwrap();
13501351
Everything::new(fileset, None, None, None).unwrap()
13511352
})
13521353
.bench_local_refs(|everything| {
@@ -1359,8 +1360,9 @@ mod benchmark {
13591360
fn load_provinces_vic3(bencher: Bencher, (vanilla_dir, modpath): (&str, &PathBuf)) {
13601361
bencher
13611362
.with_inputs(|| {
1362-
let fileset =
1363-
Fileset::builder(Some(Path::new(vanilla_dir))).with_metadata(modpath).unwrap();
1363+
let fileset = Fileset::builder(Some(Path::new(vanilla_dir)))
1364+
.with_metadata(modpath.clone())
1365+
.unwrap();
13641366
Everything::new(fileset, None, None, None).unwrap()
13651367
})
13661368
.bench_local_refs(|everything| {
@@ -1375,13 +1377,13 @@ mod benchmark {
13751377
let fileset = Fileset::builder(Some(Path::new(vanilla_dir)));
13761378
let fileset = match Game::game() {
13771379
#[cfg(feature = "ck3")]
1378-
Game::Ck3 => fileset.with_modfile(modpath),
1380+
Game::Ck3 => fileset.with_modfile(modpath.clone()),
13791381
#[cfg(feature = "vic3")]
1380-
Game::Vic3 => fileset.with_metadata(modpath),
1382+
Game::Vic3 => fileset.with_metadata(modpath.clone()),
13811383
#[cfg(feature = "imperator")]
1382-
Game::Imperator => fileset.with_modfile(modpath),
1384+
Game::Imperator => fileset.with_modfile(modpath.clone()),
13831385
#[cfg(feature = "hoi4")]
1384-
Game::Hoi4 => fileset.with_modfile(modpath),
1386+
Game::Hoi4 => fileset.with_modfile(modpath.clone()),
13851387
}
13861388
.unwrap();
13871389
Everything::new(fileset, None, None, None).unwrap()

src/files/fileset.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ impl FileEntry {
9898
}
9999
}
100100

101-
/// Creates a new file entry which will not have errors loged.
102-
/// Files that are being analized should use [`Fileset::get_or_create_entry`]
101+
/// Creates a new file entry which will not have errors logged.
103102
pub fn new_untracked(path: PathBuf, kind: FileKind, fullpath: PathBuf) -> Self {
104103
debug_assert!(path.file_name().is_some());
105104
Self {

src/files/fileset_builder.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,11 @@ impl FilesetBuilder {
5656
}
5757

5858
#[cfg(any(feature = "ck3", feature = "imperator", feature = "hoi4"))]
59-
pub fn with_modfile(mut self, modfile: &Path) -> Result<FilesetBuilderWithMod> {
60-
let modfile_entry = self.db.get_or_create_entry(
61-
modfile.to_path_buf(),
62-
FileKind::Mod,
63-
modfile.to_path_buf(),
64-
);
59+
pub fn with_modfile(mut self, mut modpath: PathBuf) -> Result<FilesetBuilderWithMod> {
60+
if modpath.is_dir() {
61+
modpath.push("descriptor.mod");
62+
}
63+
let modfile_entry = self.db.get_or_create_entry(modpath.clone(), FileKind::Mod, modpath);
6564
let modfile = ModFile::read(modfile_entry)?;
6665

6766
let modpath = modfile.modpath();
@@ -82,7 +81,7 @@ impl FilesetBuilder {
8281
}
8382

8483
#[cfg(feature = "vic3")]
85-
pub fn with_metadata(mut self, mod_root: &Path) -> Result<FilesetBuilderWithMod> {
84+
pub fn with_metadata(mut self, mod_root: PathBuf) -> Result<FilesetBuilderWithMod> {
8685
let metadata = ModMetadata::read(&mut self.db, mod_root)?;
8786

8887
eprintln!("Using mod directory: {}", metadata.modpath().display());
@@ -162,7 +161,7 @@ impl FilesetBuilderWithMod {
162161
} else if Game::is_vic3() {
163162
#[cfg(feature = "vic3")]
164163
if let Some(pathdir) = get_mod(&label, config_path, block, workshop_dir) {
165-
match ModMetadata::read(&mut self.db, &pathdir) {
164+
match ModMetadata::read(&mut self.db, pathdir.clone()) {
166165
Ok(metadata) => {
167166
eprintln!(
168167
"Loading secondary mod {label} from: {}{}",

src/mod_metadata.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ pub struct ModMetadata {
2222

2323
impl ModMetadata {
2424
/// Read and parse the metadata file for the given mod dir
25-
pub fn read(filedb: &mut FileDb, mod_dir: &Path) -> Result<Self> {
25+
pub fn read(filedb: &mut FileDb, mod_dir: PathBuf) -> Result<Self> {
2626
let in_mod_path = PathBuf::from(".metadata/metadata.json");
2727
let pathname = fix_slashes_for_target_platform(mod_dir.join(&in_mod_path));
2828
let entry = filedb.get_or_create_entry(in_mod_path, FileKind::Mod, pathname.clone());
2929
let block = parse_json_file(entry)
3030
.with_context(|| format!("could not read metadata file {}", pathname.display()))?;
31-
Ok(Self { modpath: mod_dir.to_path_buf(), block })
31+
Ok(Self { modpath: mod_dir, block })
3232
}
3333

3434
/// Return the full path to the mod root.

tests/files/mod1/descriptor.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version="1.0"
2+
name="Test mod"
3+
supported_version="1.9.2.1"

tests/files/mod2/descriptor.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version="1.0"
2+
name="Test mod"
3+
supported_version="1.9.2.1"

tests/files/mod3/descriptor.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version="1.0"
2+
name="Test mod"
3+
supported_version="1.9.2.1"

tests/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ fn check_mod_helper(
1616
let vanilla_dir = PathBuf::from("tests/files/ck3");
1717
let mod_root = PathBuf::from(format!("tests/files/{}", modname));
1818

19-
let fileset = Fileset::builder(Some(&vanilla_dir), mod_root.clone());
20-
let mut everything = Everything::new(fileset, None, None, None, &mod_root).unwrap();
19+
let fileset = Fileset::builder(Some(&vanilla_dir)).with_modfile(mod_root).unwrap();
20+
let mut everything = Everything::new(fileset, None, None, None).unwrap();
2121
everything.load_all();
2222
everything.validate_all();
2323

0 commit comments

Comments
 (0)