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/exec.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/exec.rs')
| -rw-r--r-- | crates/mozart/src/commands/exec.rs | 197 |
1 files changed, 0 insertions, 197 deletions
diff --git a/crates/mozart/src/commands/exec.rs b/crates/mozart/src/commands/exec.rs index 1078158..cd07dc3 100644 --- a/crates/mozart/src/commands/exec.rs +++ b/crates/mozart/src/commands/exec.rs @@ -146,200 +146,3 @@ fn get_binaries(composer: &Composer, bin_dir: &Path) -> Vec<(String, bool)> { binaries } - -#[cfg(test)] -mod tests { - use super::*; - use mozart_core::console::Console; - use std::fs; - use std::sync::{Arc, Mutex}; - - fn io() -> Arc<Mutex<Box<dyn IoInterface>>> { - Arc::new(Mutex::new( - Box::new(Console::new(0, true, false, true, true)) as Box<dyn IoInterface>, - )) - } - - #[test] - fn test_resolve_bin_dir_default() { - let dir = tempfile::tempdir().unwrap(); - let composer_json = dir.path().join("composer.json"); - fs::write(&composer_json, r#"{"name": "test/pkg", "require": {}}"#).unwrap(); - - let composer = Composer::require(io(), dir.path()).unwrap(); - let result = resolve_bin_dir(dir.path(), &composer); - assert_eq!(result, dir.path().join("vendor/bin")); - } - - #[test] - fn test_resolve_bin_dir_custom_vendor_dir() { - let dir = tempfile::tempdir().unwrap(); - let composer_json = dir.path().join("composer.json"); - fs::write( - &composer_json, - r#"{"name": "test/pkg", "require": {}, "config": {"vendor-dir": "libs"}}"#, - ) - .unwrap(); - - let composer = Composer::require(io(), dir.path()).unwrap(); - let result = resolve_bin_dir(dir.path(), &composer); - assert_eq!(result, dir.path().join("libs/bin")); - } - - #[test] - fn test_resolve_bin_dir_custom_bin_dir() { - let dir = tempfile::tempdir().unwrap(); - let composer_json = dir.path().join("composer.json"); - fs::write( - &composer_json, - r#"{"name": "test/pkg", "require": {}, "config": {"bin-dir": "scripts"}}"#, - ) - .unwrap(); - - let composer = Composer::require(io(), dir.path()).unwrap(); - let result = resolve_bin_dir(dir.path(), &composer); - assert_eq!(result, dir.path().join("scripts")); - } - - #[test] - fn test_resolve_bin_dir_with_placeholder() { - let dir = tempfile::tempdir().unwrap(); - let composer_json = dir.path().join("composer.json"); - fs::write( - &composer_json, - r#"{"name": "test/pkg", "require": {}, "config": {"vendor-dir": "packages", "bin-dir": "{$vendor-dir}/commands"}}"#, - ) - .unwrap(); - - let composer = Composer::require(io(), dir.path()).unwrap(); - let result = resolve_bin_dir(dir.path(), &composer); - assert_eq!(result, dir.path().join("packages/commands")); - } - - #[test] - fn test_get_binaries_from_bin_dir() { - let dir = tempfile::tempdir().unwrap(); - let bin_dir = dir.path().join("vendor/bin"); - fs::create_dir_all(&bin_dir).unwrap(); - - fs::write(bin_dir.join("phpunit"), "#!/bin/sh").unwrap(); - fs::write(bin_dir.join("phpstan"), "#!/bin/sh").unwrap(); - - fs::write( - dir.path().join("composer.json"), - r#"{"name": "test/pkg", "require": {}}"#, - ) - .unwrap(); - - let composer = Composer::require(io(), dir.path()).unwrap(); - let binaries = get_binaries(&composer, &bin_dir); - let names: Vec<&str> = binaries.iter().map(|(n, _)| n.as_str()).collect(); - assert!(names.contains(&"phpunit")); - assert!(names.contains(&"phpstan")); - // All should be non-local - for (_, is_local) in &binaries { - assert!(!is_local); - } - } - - #[test] - fn test_get_binaries_skips_bat_files() { - let dir = tempfile::tempdir().unwrap(); - let bin_dir = dir.path().join("vendor/bin"); - fs::create_dir_all(&bin_dir).unwrap(); - - fs::write(bin_dir.join("phpunit"), "#!/bin/sh").unwrap(); - fs::write(bin_dir.join("phpunit.bat"), "@echo off").unwrap(); - - fs::write( - dir.path().join("composer.json"), - r#"{"name": "test/pkg", "require": {}}"#, - ) - .unwrap(); - - let composer = Composer::require(io(), dir.path()).unwrap(); - let binaries = get_binaries(&composer, &bin_dir); - let names: Vec<&str> = binaries.iter().map(|(n, _)| n.as_str()).collect(); - assert!(names.contains(&"phpunit")); - assert!(!names.contains(&"phpunit.bat")); - } - - #[test] - fn test_get_binaries_from_root_composer_json() { - let dir = tempfile::tempdir().unwrap(); - let bin_dir = dir.path().join("vendor/bin"); - // Don't create bin_dir — no vendor binaries - - fs::write( - dir.path().join("composer.json"), - r#"{"name": "test/pkg", "require": {}, "bin": ["bin/my-tool", "bin/helper"]}"#, - ) - .unwrap(); - - let composer = Composer::require(io(), dir.path()).unwrap(); - let binaries = get_binaries(&composer, &bin_dir); - let names: Vec<&str> = binaries.iter().map(|(n, _)| n.as_str()).collect(); - assert!(names.contains(&"my-tool")); - assert!(names.contains(&"helper")); - // All should be local - for (_, is_local) in &binaries { - assert!(is_local); - } - } - - #[test] - fn test_get_binaries_empty_bin_dir() { - let dir = tempfile::tempdir().unwrap(); - let bin_dir = dir.path().join("vendor/bin"); - // bin_dir doesn't exist - - fs::write( - dir.path().join("composer.json"), - r#"{"name": "test/pkg", "require": {}}"#, - ) - .unwrap(); - - let composer = Composer::require(io(), dir.path()).unwrap(); - let binaries = get_binaries(&composer, &bin_dir); - assert!(binaries.is_empty()); - } - - #[test] - fn test_list_mode_no_binaries_errors() { - let dir = tempfile::tempdir().unwrap(); - fs::write( - dir.path().join("composer.json"), - r#"{"name": "test/pkg", "require": {}}"#, - ) - .unwrap(); - - let bin_dir = dir.path().join("vendor/bin"); - let composer = Composer::require(io(), dir.path()).unwrap(); - let binaries = get_binaries(&composer, &bin_dir); - assert!( - binaries.is_empty(), - "Expected no binaries to trigger error path" - ); - } - - #[test] - fn test_execute_binary_not_found() { - let dir = tempfile::tempdir().unwrap(); - fs::write( - dir.path().join("composer.json"), - r#"{"name": "test/pkg", "require": {}}"#, - ) - .unwrap(); - - let composer = Composer::require(io(), dir.path()).unwrap(); - let bin_dir = resolve_bin_dir(dir.path(), &composer); - - // No binaries exist — looking up a name should find nothing - let candidate = bin_dir.join("nonexistent-binary"); - assert!(!candidate.exists()); - - // Confirm root bin entries are also empty - let root = mozart_core::package::read_from_file(&dir.path().join("composer.json")).unwrap(); - assert!(root.bin.is_empty()); - } -} |
