Skip to content

Commit

Permalink
Add integration tests for simple mod lints
Browse files Browse the repository at this point in the history
  • Loading branch information
jieyouxu committed Aug 13, 2023
1 parent a01aff9 commit bc59f07
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test_mod_batches/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Test Mod Batches

Each test mod batch can consist of one or more test mods. Each batch is intended to serve as the
mods within a profile, so we can test various aspects of integration and linting.
Binary file added test_mod_batches/simple_lints/A.pak
Binary file not shown.
Empty file.
Empty file.
Empty file.
Empty file.
Binary file added test_mod_batches/simple_lints/B.pak
Binary file not shown.
Empty file.
Empty file.
90 changes: 90 additions & 0 deletions tests/lint/conflicting.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use std::path::PathBuf;
use std::str::FromStr;

use drg_mod_integration::mod_lint::ModLintReport;
use drg_mod_integration::providers::ModSpecification;

#[test]
pub fn test_lint_conflicting_files() {
let base_path = PathBuf::from_str("test_mod_batches/simple_lints/").unwrap();
assert!(base_path.exists());
let a_path = base_path.clone().join("A.pak");
assert!(a_path.exists());
let b_path = base_path.clone().join("B.pak");
assert!(b_path.exists());
let a_spec = ModSpecification {
url: "A".to_string(),
};
let b_spec = ModSpecification {
url: "B".to_string(),
};
let mods = vec![(a_spec.clone(), a_path), (b_spec.clone(), b_path)];

let ModLintReport {
conflicting_mods, ..
} = drg_mod_integration::mod_lint::lint(&mods).unwrap();

println!("{:#?}", conflicting_mods);

assert_eq!(
conflicting_mods.get("fsd/content/a.uexp"),
Some(&[a_spec, b_spec].into())
);
}

#[test]
pub fn test_lint_shader() {
let base_path = PathBuf::from_str("test_mod_batches/simple_lints/").unwrap();
assert!(base_path.exists());
let a_path = base_path.clone().join("A.pak");
assert!(a_path.exists());
let b_path = base_path.clone().join("B.pak");
assert!(b_path.exists());
let a_spec = ModSpecification {
url: "A".to_string(),
};
let b_spec = ModSpecification {
url: "B".to_string(),
};
let mods = vec![(a_spec.clone(), a_path), (b_spec.clone(), b_path)];

let ModLintReport {
shader_file_mods, ..
} = drg_mod_integration::mod_lint::lint(&mods).unwrap();

println!("{:#?}", shader_file_mods);

assert_eq!(
shader_file_mods.get(&a_spec),
Some(&["fsd/content/c.ushaderbytecode".to_string()].into())
);
}

#[test]
pub fn test_lint_asset_registry_bin() {
let base_path = PathBuf::from_str("test_mod_batches/simple_lints/").unwrap();
assert!(base_path.exists());
let a_path = base_path.clone().join("A.pak");
assert!(a_path.exists());
let b_path = base_path.clone().join("B.pak");
assert!(b_path.exists());
let a_spec = ModSpecification {
url: "A".to_string(),
};
let b_spec = ModSpecification {
url: "B".to_string(),
};
let mods = vec![(a_spec.clone(), a_path), (b_spec.clone(), b_path)];

let ModLintReport {
asset_register_bin_mods,
..
} = drg_mod_integration::mod_lint::lint(&mods).unwrap();

println!("{:#?}", asset_register_bin_mods);

assert_eq!(
asset_register_bin_mods.get(&a_spec),
Some(&["fsd/content/assetregistry.bin".to_string()].into())
);
}
1 change: 1 addition & 0 deletions tests/lint/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod conflicting;
1 change: 1 addition & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod lint;

0 comments on commit bc59f07

Please sign in to comment.