refactored: rework weak unit tests to catch real regressions
Audit found 9 confirmed-weak unit tests plus several newly-found ones that
asserted things equivalent to themselves, returned vacuous truth, or had
assertions guarded behind conditionals that silently swallowed failure.
Changes by file:
- auth/accounts.rs: create_offline_account_fields now pins the uuid to
offline_uuid("TestPlayer") instead of !is_empty(); mutating the uuid
derivation would fail this now.
- cli/mod.rs: parses_instance_list_subcommand drills into the list
subcommand under instance rather than only verifying the instance
group exists.
- config/theme.rs: border_style_roundtrip is now an rstest covering all
four BorderStyle variants; mutating any non-Double arm is caught.
- instance/desktop.rs: removed desktop_path_returns_some (assertion was
gated behind if let Some so could pass when the function returned
None); build_content_linux* already covers the real behaviour.
- instance/launch/mod.rs: removed five predicate-only tests that
asserted serde defaulting on LaunchProfile rather than invoking the
migration predicate. Added two tests that actually call
migrate_legacy_meta_if_needed (rstest over modern/legacy arg shapes)
and migrate_legacy_loader_profile_if_needed (modern-with-inheritsFrom
early-return). Renamed build_game_args_renders_upstream_arguments,
dropping the misleading "and appends loader args" clause that the
test never covered.
- instance/loader/mod.rs: removed test_vanilla_install_noop (no
assertion at all) and test_vanilla_get_versions (asserted a hardcoded
Ok(vec!["vanilla"]) return). Replaced test_vanilla_factory with an
rstest covering all five ModLoader variants; a misordered match arm
in get_installer is caught.
- migrate.rs: removed cleanup_instance_leftovers_handles_missing_dir
(had no assertions and was redundant with
cleanup_instance_leftovers_removes_shim_and_log4j).
- net/mod.rs: removed detect_java_falls_back_to_java which asserted
!is_empty() against a function whose worst-case fallback is the
literal string "java"; structurally uncatchable.
- tui/error_buffer.rs: peek_all_returns_newest_first and
auto_assigned_ids_are_unique now tag their pushed events with a
unique substring and filter peek_all_errors to just those, so the
assertions actually fire instead of being silently skipped via
if all.len() >= 2 when shared static state interfered.
Total: net zero change in test count (deletions and parameterised
replacements roughly balance), but mutation coverage of the surviving
suite is materially stronger.
This commit is contained in:
1 parent
d2e08d818b
commit
7a9dfa850d
9 files changed
+121
-124
No files matched your search
@@ -201,15 +201,6 @@ mod tests {
|
||||
assert_eq!(sanitize("path/traversal"), "path_traversal");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn desktop_path_returns_some() {
|
||||
let path = desktop_path("TestPack");
|
||||
if let Some(p) = path {
|
||||
let name = p.file_name().unwrap().to_str().unwrap();
|
||||
assert!(name.contains("TestPack"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn build_content_linux() {
|
||||
|
||||
+63
-58
@@ -659,7 +659,7 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn build_game_args_renders_upstream_arguments_and_appends_loader_args() {
|
||||
fn build_game_args_renders_upstream_arguments() {
|
||||
use crate::launch_profile::model::{Argument, Arguments, LaunchProfile};
|
||||
use crate::launch_profile::rules::{FeatureSet, RuleContext};
|
||||
use TemplateContext;
|
||||
@@ -720,46 +720,39 @@ mod tests {
|
||||
assert_eq!(game_args, vec!["--username", "Player"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn migration_predicate_triggers_when_both_argument_fields_absent() {
|
||||
use LaunchProfile;
|
||||
let stripped = LaunchProfile {
|
||||
id: "1.20.1".into(),
|
||||
inherits_from: None,
|
||||
main_class: Some("net.test.Main".into()),
|
||||
libraries: Vec::new(),
|
||||
..Default::default()
|
||||
};
|
||||
assert!(stripped.arguments.is_none() && stripped.minecraft_arguments.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn migration_predicate_skips_when_modern_arguments_present() {
|
||||
// exercises the early-return branch of migrate_legacy_meta_if_needed.
|
||||
// a profile with either arguments or minecraftArguments is not legacy
|
||||
// and must produce Ok(None) without touching the network. covers both
|
||||
// shapes in one parameterised test so a regression that drops one of
|
||||
// the two predicate conditions is caught.
|
||||
#[rstest::rstest]
|
||||
#[case::modern_arguments(true, false)]
|
||||
#[case::legacy_minecraft_arguments(false, true)]
|
||||
#[tokio::test]
|
||||
async fn migrate_legacy_meta_skips_when_arguments_present(
|
||||
#[case] modern: bool,
|
||||
#[case] legacy: bool,
|
||||
) {
|
||||
use crate::launch_profile::model::{Arguments, LaunchProfile};
|
||||
let modern = LaunchProfile {
|
||||
id: "1.20.1".into(),
|
||||
inherits_from: None,
|
||||
main_class: Some("net.test.Main".into()),
|
||||
libraries: Vec::new(),
|
||||
arguments: Some(Arguments::default()),
|
||||
..Default::default()
|
||||
};
|
||||
assert!(modern.arguments.is_some());
|
||||
}
|
||||
use tempfile::TempDir;
|
||||
|
||||
#[test]
|
||||
fn migration_predicate_skips_when_legacy_minecraft_arguments_present() {
|
||||
use LaunchProfile;
|
||||
let legacy = LaunchProfile {
|
||||
id: "1.7.10".into(),
|
||||
inherits_from: None,
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let meta_path = tmp.path().join("meta.json");
|
||||
std::fs::write(&meta_path, b"{}").unwrap();
|
||||
|
||||
let profile = LaunchProfile {
|
||||
id: "1.20.1".into(),
|
||||
main_class: Some("net.test.Main".into()),
|
||||
libraries: Vec::new(),
|
||||
arguments: None,
|
||||
minecraft_arguments: Some("--username Player".into()),
|
||||
arguments: modern.then(Arguments::default),
|
||||
minecraft_arguments: legacy.then(|| "--username Player".into()),
|
||||
..Default::default()
|
||||
};
|
||||
assert!(legacy.minecraft_arguments.is_some());
|
||||
|
||||
let result = migrate_legacy_meta_if_needed(&meta_path, &profile, "1.20.1").await;
|
||||
assert!(
|
||||
matches!(result, Ok(None)),
|
||||
"expected Ok(None) for non-legacy profile, got {result:?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -785,36 +778,48 @@ mod tests {
|
||||
assert!(installer_version_dir_name(ModLoader::Quilt, "1.20.1", "0.20.0").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn loader_profile_legacy_predicate_triggers_when_all_three_absent() {
|
||||
// exercises the modern-profile early-return in
|
||||
// migrate_legacy_loader_profile_if_needed. any of inheritsFrom,
|
||||
// arguments, minecraftArguments present (or game_arguments absent)
|
||||
// means "not legacy" and the function must return Ok(None) without
|
||||
// touching the installer JSON path.
|
||||
#[tokio::test]
|
||||
async fn migrate_legacy_loader_profile_skips_modern_with_inherits_from() {
|
||||
use LaunchProfile;
|
||||
let legacy = LaunchProfile {
|
||||
id: "1.20.1-forge-47.2.0".into(),
|
||||
inherits_from: None,
|
||||
main_class: Some("cpw.mods.bootstraplauncher.BootstrapLauncher".into()),
|
||||
libraries: Vec::new(),
|
||||
..Default::default()
|
||||
};
|
||||
let is_legacy = legacy.inherits_from.is_none()
|
||||
&& legacy.arguments.is_none()
|
||||
&& legacy.minecraft_arguments.is_none();
|
||||
assert!(is_legacy);
|
||||
}
|
||||
use chrono::Utc;
|
||||
use tempfile::TempDir;
|
||||
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let instance_dir = tmp.path().join("instance");
|
||||
std::fs::create_dir_all(&instance_dir).unwrap();
|
||||
let profile_path = tmp.path().join("forge-1.20.1-47.2.0.json");
|
||||
std::fs::write(&profile_path, b"{}").unwrap();
|
||||
|
||||
#[test]
|
||||
fn loader_profile_legacy_predicate_skips_modern_profile_with_inherits_from() {
|
||||
use LaunchProfile;
|
||||
let modern = LaunchProfile {
|
||||
id: "1.20.1-forge-47.2.0".into(),
|
||||
inherits_from: Some("1.20.1".into()),
|
||||
main_class: Some("cpw.mods.bootstraplauncher.BootstrapLauncher".into()),
|
||||
libraries: Vec::new(),
|
||||
..Default::default()
|
||||
};
|
||||
let is_legacy = modern.inherits_from.is_none()
|
||||
&& modern.arguments.is_none()
|
||||
&& modern.minecraft_arguments.is_none();
|
||||
assert!(!is_legacy);
|
||||
|
||||
let config = InstanceConfig {
|
||||
name: "test".into(),
|
||||
game_version: "1.20.1".into(),
|
||||
loader: ModLoader::Forge,
|
||||
loader_version: Some("47.2.0".into()),
|
||||
created: Utc::now(),
|
||||
last_played: None,
|
||||
java_path: None,
|
||||
memory_max: None,
|
||||
memory_min: None,
|
||||
jvm_args: Vec::new(),
|
||||
resolution: None,
|
||||
};
|
||||
|
||||
let result =
|
||||
migrate_legacy_loader_profile_if_needed(&profile_path, &modern, &config, &instance_dir)
|
||||
.await;
|
||||
assert!(matches!(result, Ok(None)), "expected Ok(None), got {result:?}");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
+12
-25
@@ -108,31 +108,18 @@ pub fn get_installer(loader: ModLoader) -> Box<dyn ModLoaderInstaller + Send + S
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_vanilla_factory() {
|
||||
let installer = get_installer(ModLoader::Vanilla);
|
||||
assert_eq!(installer.loader_type(), ModLoader::Vanilla);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_vanilla_get_versions() {
|
||||
let client = HttpClient::new();
|
||||
let installer = VanillaInstaller;
|
||||
let versions = installer.get_versions(&client, "1.20.1").await.unwrap();
|
||||
assert!(!versions.is_empty());
|
||||
assert_eq!(versions[0], "vanilla");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_vanilla_install_noop() {
|
||||
let client = HttpClient::new();
|
||||
let installer = VanillaInstaller;
|
||||
let tmp = std::env::temp_dir().join("rmcl_test_vanilla_install");
|
||||
let meta = std::env::temp_dir().join("rmcl_test_meta");
|
||||
installer
|
||||
.install(&client, "1.20.1", "vanilla", &tmp, &meta)
|
||||
.await
|
||||
.unwrap();
|
||||
// the factory maps every ModLoader variant to its concrete installer.
|
||||
// covering all five arms catches a misordered match or a copy-paste typo
|
||||
// that would route, say, NeoForge to the Forge installer.
|
||||
#[rstest::rstest]
|
||||
#[case::vanilla(ModLoader::Vanilla)]
|
||||
#[case::forge(ModLoader::Forge)]
|
||||
#[case::neoforge(ModLoader::NeoForge)]
|
||||
#[case::fabric(ModLoader::Fabric)]
|
||||
#[case::quilt(ModLoader::Quilt)]
|
||||
fn get_installer_returns_matching_loader_type(#[case] loader: ModLoader) {
|
||||
let installer = get_installer(loader);
|
||||
assert_eq!(installer.loader_type(), loader);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
Reference in new issue
Block a user