diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-11 02:36:42 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-11 02:36:42 +0900 |
| commit | 4e99773a3d203e73b8bf6464490d05649a269fa7 (patch) | |
| tree | 7a6f1a7f773a14ea72dc2f9ff4124badd345833d /crates/mozart/src/commands/validate.rs | |
| parent | 4df5f8491320e5795718cf0222e80fa27e57c8ad (diff) | |
| download | php-mozart-4e99773a3d203e73b8bf6464490d05649a269fa7.tar.gz php-mozart-4e99773a3d203e73b8bf6464490d05649a269fa7.tar.zst php-mozart-4e99773a3d203e73b8bf6464490d05649a269fa7.zip | |
test(commands): remove per-command tests
Diffstat (limited to 'crates/mozart/src/commands/validate.rs')
| -rw-r--r-- | crates/mozart/src/commands/validate.rs | 197 |
1 files changed, 0 insertions, 197 deletions
diff --git a/crates/mozart/src/commands/validate.rs b/crates/mozart/src/commands/validate.rs index 23925c5..f6275d9 100644 --- a/crates/mozart/src/commands/validate.rs +++ b/crates/mozart/src/commands/validate.rs @@ -487,200 +487,3 @@ fn compute_exit_code( 0 } - -#[cfg(test)] -mod tests { - use super::*; - - fn make_args() -> ValidateArgs { - ValidateArgs { - file: None, - no_check_all: false, - check_lock: false, - no_check_lock: false, - no_check_publish: false, - no_check_version: false, - with_dependencies: false, - strict: false, - } - } - - #[test] - fn test_compute_exit_code_no_issues() { - let result = ValidationResult::new(); - assert_eq!(compute_exit_code(&result, &[], true, true, false), 0); - } - - #[test] - fn test_compute_exit_code_errors() { - let mut result = ValidationResult::new(); - result.errors.push("some error".to_string()); - assert_eq!(compute_exit_code(&result, &[], true, true, false), 2); - } - - #[test] - fn test_compute_exit_code_publish_errors_counted() { - let mut result = ValidationResult::new(); - result.publish_errors.push("publish error".to_string()); - assert_eq!(compute_exit_code(&result, &[], true, true, false), 2); - } - - #[test] - fn test_compute_exit_code_publish_errors_not_checked() { - let mut result = ValidationResult::new(); - result.publish_errors.push("publish error".to_string()); - // check_publish = false → publish errors don't count - assert_eq!(compute_exit_code(&result, &[], false, true, false), 0); - } - - #[test] - fn test_compute_exit_code_lock_errors_counted() { - let result = ValidationResult::new(); - let lock_errors = vec!["lock stale".to_string()]; - assert_eq!( - compute_exit_code(&result, &lock_errors, true, true, false), - 2 - ); - } - - #[test] - fn test_compute_exit_code_lock_errors_not_checked() { - let result = ValidationResult::new(); - let lock_errors = vec!["lock stale".to_string()]; - // check_lock = false → lock errors become warnings, not counted unless strict - assert_eq!( - compute_exit_code(&result, &lock_errors, true, false, false), - 0 - ); - } - - #[test] - fn test_compute_exit_code_strict_warnings() { - let mut result = ValidationResult::new(); - result.warnings.push("some warning".to_string()); - assert_eq!(compute_exit_code(&result, &[], true, true, true), 1); - } - - #[test] - fn test_compute_exit_code_warnings_not_strict() { - let mut result = ValidationResult::new(); - result.warnings.push("some warning".to_string()); - assert_eq!(compute_exit_code(&result, &[], true, true, false), 0); - } - - #[test] - fn test_check_lock_freshness_no_lock_file() { - use tempfile::tempdir; - let dir = tempdir().unwrap(); - let composer_json_path = dir.path().join("composer.json"); - let content = r#"{"name": "vendor/pkg", "require": {}}"#; - std::fs::write(&composer_json_path, content).unwrap(); - - let mut lock_errors: Vec<String> = Vec::new(); - check_lock_freshness(content, &composer_json_path, None, &mut lock_errors); - // No lock file → no errors - assert!(lock_errors.is_empty()); - } - - #[test] - fn test_check_lock_freshness_fresh_lock() { - use mozart_core::repository::lockfile::LockFile; - use tempfile::tempdir; - - let dir = tempdir().unwrap(); - let composer_json_path = dir.path().join("composer.json"); - let content = r#"{"name": "vendor/pkg", "require": {"php": ">=8.1"}}"#; - std::fs::write(&composer_json_path, content).unwrap(); - - let hash = LockFile::compute_content_hash(content).unwrap(); - let lock = LockFile { - readme: LockFile::default_readme(), - content_hash: hash, - packages: vec![], - packages_dev: Some(vec![]), - aliases: vec![], - minimum_stability: "stable".to_string(), - stability_flags: serde_json::json!({}), - prefer_stable: false, - prefer_lowest: false, - platform: serde_json::json!({}), - platform_dev: serde_json::json!({}), - plugin_api_version: None, - }; - let lock_path = dir.path().join("composer.lock"); - lock.write_to_file(&lock_path).unwrap(); - - let mut lock_errors: Vec<String> = Vec::new(); - check_lock_freshness(content, &composer_json_path, None, &mut lock_errors); - assert!( - lock_errors.is_empty(), - "fresh lock should produce no errors" - ); - } - - #[test] - fn test_check_lock_freshness_stale_lock() { - use mozart_core::repository::lockfile::LockFile; - use tempfile::tempdir; - - let dir = tempdir().unwrap(); - let composer_json_path = dir.path().join("composer.json"); - let original_content = r#"{"name": "vendor/pkg", "require": {"php": ">=8.1"}}"#; - let modified_content = r#"{"name": "vendor/pkg", "require": {"php": ">=8.2"}}"#; - - // Write original content - std::fs::write(&composer_json_path, original_content).unwrap(); - - // Create lock file based on original content - let hash = LockFile::compute_content_hash(original_content).unwrap(); - let lock = LockFile { - readme: LockFile::default_readme(), - content_hash: hash, - packages: vec![], - packages_dev: Some(vec![]), - aliases: vec![], - minimum_stability: "stable".to_string(), - stability_flags: serde_json::json!({}), - prefer_stable: false, - prefer_lowest: false, - platform: serde_json::json!({}), - platform_dev: serde_json::json!({}), - plugin_api_version: None, - }; - let lock_path = dir.path().join("composer.lock"); - lock.write_to_file(&lock_path).unwrap(); - - // Now check against modified content (lock is stale) - let mut lock_errors: Vec<String> = Vec::new(); - check_lock_freshness( - modified_content, - &composer_json_path, - None, - &mut lock_errors, - ); - assert!( - !lock_errors.is_empty(), - "stale lock should produce a lock error" - ); - assert!(lock_errors[0].contains("not up to date")); - } - - #[test] - fn test_should_check_lock_config_false_disables() { - let args = make_args(); - assert!(!should_check_lock(&args, false)); - } - - #[test] - fn test_should_check_lock_config_false_overridden_by_flag() { - let mut args = make_args(); - args.check_lock = true; - assert!(should_check_lock(&args, false)); - } - - #[test] - fn test_should_check_lock_defaults_to_true() { - let args = make_args(); - assert!(should_check_lock(&args, true)); - } -} |
