aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/repository/vcs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-21 12:40:10 +0900
committernsfisis <nsfisis@gmail.com>2026-06-21 12:40:10 +0900
commit2b2ca914cc5f2f7fde3b6e75faabbe4913fd7264 (patch)
treeff8bbb00238526c376f521647adc9ea9f486b84c /crates/shirabe/tests/repository/vcs
parent4b92ecafd7634ad99aa432d58fbc1958d1f01270 (diff)
downloadphp-shirabe-2b2ca914cc5f2f7fde3b6e75faabbe4913fd7264.tar.gz
php-shirabe-2b2ca914cc5f2f7fde3b6e75faabbe4913fd7264.tar.zst
php-shirabe-2b2ca914cc5f2f7fde3b6e75faabbe4913fd7264.zip
test(tests): port setUp/tearDown as set_up/tear_down with TearDown
Port PHP setUp/tearDown across the ported integration tests using same-named set_up()/tear_down() functions and a TearDown struct whose Drop runs tear_down(). Fixture-init setUp returns its fixtures; tmpdir-style setUp/tearDown carry state in TearDown fields. Parts that depend on unported infrastructure (PHPUnit mocks, Config::merge, the PHP error handler) stay todo!() and are only wired into ignored stubs to avoid breaking live tests. Also fix shirabe-php-shim putenv to handle the no-'=' form (PHP unsets the variable), which Platform::clear_env relies on for the env-clearing tearDowns. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/repository/vcs')
-rw-r--r--crates/shirabe/tests/repository/vcs/forgejo_driver_test.rs92
-rw-r--r--crates/shirabe/tests/repository/vcs/fossil_driver_test.rs45
-rw-r--r--crates/shirabe/tests/repository/vcs/git_bitbucket_driver_test.rs94
-rw-r--r--crates/shirabe/tests/repository/vcs/git_driver_test.rs65
-rw-r--r--crates/shirabe/tests/repository/vcs/github_driver_test.rs66
-rw-r--r--crates/shirabe/tests/repository/vcs/hg_driver_test.rs57
-rw-r--r--crates/shirabe/tests/repository/vcs/perforce_driver_test.rs190
-rw-r--r--crates/shirabe/tests/repository/vcs/svn_driver_test.rs48
8 files changed, 657 insertions, 0 deletions
diff --git a/crates/shirabe/tests/repository/vcs/forgejo_driver_test.rs b/crates/shirabe/tests/repository/vcs/forgejo_driver_test.rs
index f488182..a67bce3 100644
--- a/crates/shirabe/tests/repository/vcs/forgejo_driver_test.rs
+++ b/crates/shirabe/tests/repository/vcs/forgejo_driver_test.rs
@@ -3,10 +3,70 @@
use std::cell::RefCell;
use std::rc::Rc;
+use indexmap::IndexMap;
use shirabe::config::Config;
use shirabe::io::IOInterface;
use shirabe::io::null_io::NullIO;
use shirabe::repository::vcs::ForgejoDriver;
+use shirabe::util::filesystem::Filesystem;
+use shirabe_php_shim::PhpMixed;
+use tempfile::TempDir;
+
+struct SetUp {
+ home: TempDir,
+ config: Config,
+ // The IOInterface and HttpDownloader mocks are not ported.
+ io: (),
+ http_downloader: (),
+}
+
+fn set_up() -> SetUp {
+ let home = TempDir::new().unwrap();
+ let mut config = Config::new(true, None);
+ let mut top: IndexMap<String, PhpMixed> = IndexMap::new();
+ let mut config_section: IndexMap<String, PhpMixed> = IndexMap::new();
+ config_section.insert(
+ "home".to_string(),
+ PhpMixed::String(home.path().to_string_lossy().into_owned()),
+ );
+ config_section.insert(
+ "forgejo-domains".to_string(),
+ PhpMixed::List(vec![PhpMixed::String("codeberg.org".to_string())]),
+ );
+ top.insert("config".to_string(), PhpMixed::Array(config_section));
+ config.merge(&top, Config::SOURCE_UNKNOWN);
+
+ let io = ();
+ let http_downloader = ();
+
+ SetUp {
+ home,
+ config,
+ io,
+ http_downloader,
+ }
+}
+
+fn tear_down(home: &std::path::Path) {
+ let mut fs = Filesystem::new(None);
+ fs.remove_directory(home).unwrap();
+}
+
+struct TearDown {
+ home: std::path::PathBuf,
+}
+
+impl TearDown {
+ fn new(home: std::path::PathBuf) -> Self {
+ TearDown { home }
+ }
+}
+
+impl Drop for TearDown {
+ fn drop(&mut self) {
+ tear_down(&self.home);
+ }
+}
fn supports_provider() -> Vec<(bool, &'static str)> {
vec![
@@ -35,23 +95,55 @@ fn test_supports() {
#[test]
#[ignore = "constructs a ForgejoDriver and mocks the HttpDownloader (curl_multi_init todo!())"]
fn test_public_repository() {
+ let SetUp {
+ home,
+ config,
+ io,
+ http_downloader,
+ } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf());
+ let _ = (&config, &io, &http_downloader);
todo!()
}
#[test]
#[ignore = "constructs a ForgejoDriver and mocks the HttpDownloader (curl_multi_init todo!())"]
fn test_get_branches() {
+ let SetUp {
+ home,
+ config,
+ io,
+ http_downloader,
+ } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf());
+ let _ = (&config, &io, &http_downloader);
todo!()
}
#[test]
#[ignore = "constructs a ForgejoDriver and mocks the HttpDownloader (curl_multi_init todo!())"]
fn test_get_tags() {
+ let SetUp {
+ home,
+ config,
+ io,
+ http_downloader,
+ } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf());
+ let _ = (&config, &io, &http_downloader);
todo!()
}
#[test]
#[ignore = "constructs a ForgejoDriver and mocks the HttpDownloader (curl_multi_init todo!())"]
fn test_get_empty_file_content() {
+ let SetUp {
+ home,
+ config,
+ io,
+ http_downloader,
+ } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf());
+ let _ = (&config, &io, &http_downloader);
todo!()
}
diff --git a/crates/shirabe/tests/repository/vcs/fossil_driver_test.rs b/crates/shirabe/tests/repository/vcs/fossil_driver_test.rs
index e677b3d..a3986c2 100644
--- a/crates/shirabe/tests/repository/vcs/fossil_driver_test.rs
+++ b/crates/shirabe/tests/repository/vcs/fossil_driver_test.rs
@@ -3,10 +3,55 @@
use std::cell::RefCell;
use std::rc::Rc;
+use indexmap::IndexMap;
use shirabe::config::Config;
use shirabe::io::IOInterface;
use shirabe::io::null_io::NullIO;
use shirabe::repository::vcs::FossilDriver;
+use shirabe::util::filesystem::Filesystem;
+use shirabe_php_shim::PhpMixed;
+use tempfile::TempDir;
+
+struct SetUp {
+ home: TempDir,
+ config: Config,
+}
+
+fn set_up() -> SetUp {
+ let home = TempDir::new().unwrap();
+ let mut config = Config::new(true, None);
+ let mut top: IndexMap<String, PhpMixed> = IndexMap::new();
+ let mut config_section: IndexMap<String, PhpMixed> = IndexMap::new();
+ config_section.insert(
+ "home".to_string(),
+ PhpMixed::String(home.path().to_string_lossy().into_owned()),
+ );
+ top.insert("config".to_string(), PhpMixed::Array(config_section));
+ config.merge(&top, Config::SOURCE_UNKNOWN);
+
+ SetUp { home, config }
+}
+
+fn tear_down(home: &std::path::Path) {
+ let mut fs = Filesystem::new(None);
+ fs.remove_directory(home).unwrap();
+}
+
+struct TearDown {
+ home: std::path::PathBuf,
+}
+
+impl TearDown {
+ fn new(home: std::path::PathBuf) -> Self {
+ TearDown { home }
+ }
+}
+
+impl Drop for TearDown {
+ fn drop(&mut self) {
+ tear_down(&self.home);
+ }
+}
fn support_provider() -> Vec<(&'static str, bool)> {
vec![
diff --git a/crates/shirabe/tests/repository/vcs/git_bitbucket_driver_test.rs b/crates/shirabe/tests/repository/vcs/git_bitbucket_driver_test.rs
index e48c609..b6759b5 100644
--- a/crates/shirabe/tests/repository/vcs/git_bitbucket_driver_test.rs
+++ b/crates/shirabe/tests/repository/vcs/git_bitbucket_driver_test.rs
@@ -3,10 +3,69 @@
use std::cell::RefCell;
use std::rc::Rc;
+use indexmap::IndexMap;
use shirabe::config::Config;
use shirabe::io::IOInterface;
use shirabe::io::null_io::NullIO;
use shirabe::repository::vcs::GitBitbucketDriver;
+use shirabe::util::filesystem::Filesystem;
+use shirabe_php_shim::PhpMixed;
+use tempfile::TempDir;
+
+struct SetUp {
+ home: TempDir,
+ config: Config,
+ // The IOInterface mock and the HttpDownloaderMock are not ported.
+ io: (),
+ http_downloader: (),
+}
+
+fn set_up() -> SetUp {
+ // The IOInterface mock is created via PHPUnit's getMockBuilder, which is not ported.
+ let io: () = todo!();
+
+ let home = TempDir::new().unwrap();
+ let mut config = Config::new(true, None);
+ let mut top: IndexMap<String, PhpMixed> = IndexMap::new();
+ let mut config_section: IndexMap<String, PhpMixed> = IndexMap::new();
+ config_section.insert(
+ "home".to_string(),
+ PhpMixed::String(home.path().to_string_lossy().into_owned()),
+ );
+ top.insert("config".to_string(), PhpMixed::Array(config_section));
+ config.merge(&top, Config::SOURCE_UNKNOWN);
+
+ // The HttpDownloaderMock is created via getHttpDownloaderMock, which is not ported.
+ let http_downloader: () = todo!();
+
+ SetUp {
+ home,
+ config,
+ io,
+ http_downloader,
+ }
+}
+
+fn tear_down(home: &std::path::Path) {
+ let mut fs = Filesystem::new(None);
+ fs.remove_directory(home).unwrap();
+}
+
+struct TearDown {
+ home: std::path::PathBuf,
+}
+
+impl TearDown {
+ fn new(home: std::path::PathBuf) -> Self {
+ TearDown { home }
+ }
+}
+
+impl Drop for TearDown {
+ fn drop(&mut self) {
+ tear_down(&self.home);
+ }
+}
#[test]
fn test_supports() {
@@ -46,29 +105,64 @@ fn test_supports() {
#[test]
#[ignore = "constructs a GitBitbucketDriver and mocks the HttpDownloader (curl_multi_init todo!())"]
fn test_get_root_identifier_wrong_scm_type() {
+ let SetUp {
+ home,
+ config: _,
+ io: _,
+ http_downloader: _,
+ } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf());
todo!()
}
#[test]
#[ignore = "constructs a GitBitbucketDriver and mocks the HttpDownloader (curl_multi_init todo!())"]
fn test_driver() {
+ let SetUp {
+ home,
+ config: _,
+ io: _,
+ http_downloader: _,
+ } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf());
todo!()
}
#[test]
#[ignore = "constructs a GitBitbucketDriver and mocks the HttpDownloader (curl_multi_init todo!())"]
fn test_get_params() {
+ let SetUp {
+ home,
+ config: _,
+ io: _,
+ http_downloader: _,
+ } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf());
todo!()
}
#[test]
#[ignore = "constructs a GitBitbucketDriver and mocks the HttpDownloader (curl_multi_init todo!())"]
fn test_initialize_invalid_repository_url() {
+ let SetUp {
+ home,
+ config: _,
+ io: _,
+ http_downloader: _,
+ } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf());
todo!()
}
#[test]
#[ignore = "constructs a GitBitbucketDriver and mocks the HttpDownloader (curl_multi_init todo!())"]
fn test_invalid_support_data() {
+ let SetUp {
+ home,
+ config: _,
+ io: _,
+ http_downloader: _,
+ } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf());
todo!()
}
diff --git a/crates/shirabe/tests/repository/vcs/git_driver_test.rs b/crates/shirabe/tests/repository/vcs/git_driver_test.rs
index 85c9f0b..c36470c 100644
--- a/crates/shirabe/tests/repository/vcs/git_driver_test.rs
+++ b/crates/shirabe/tests/repository/vcs/git_driver_test.rs
@@ -4,11 +4,76 @@
// that reaches curl_multi_init, todo!()) to feed git command output; mocking is not
// available here.
+use indexmap::IndexMap;
+use shirabe::config::Config;
+use shirabe::util::filesystem::Filesystem;
+use shirabe::util::platform::Platform;
+use shirabe_php_shim::PhpMixed;
+use tempfile::TempDir;
+
+struct SetUp {
+ home: TempDir,
+ config: Config,
+ network_env: Option<String>,
+}
+
+fn set_up() -> SetUp {
+ let home = TempDir::new().unwrap();
+ let mut config = Config::new(true, None);
+ let mut top: IndexMap<String, PhpMixed> = IndexMap::new();
+ let mut config_section: IndexMap<String, PhpMixed> = IndexMap::new();
+ config_section.insert(
+ "home".to_string(),
+ PhpMixed::String(home.path().to_string_lossy().into_owned()),
+ );
+ top.insert("config".to_string(), PhpMixed::Array(config_section));
+ config.merge(&top, Config::SOURCE_UNKNOWN);
+ let network_env = Platform::get_env("COMPOSER_DISABLE_NETWORK");
+
+ SetUp {
+ home,
+ config,
+ network_env,
+ }
+}
+
+fn tear_down(home: &std::path::Path, network_env: &Option<String>) {
+ let mut fs = Filesystem::new(None);
+ fs.remove_directory(home).unwrap();
+ match network_env {
+ None => Platform::clear_env("COMPOSER_DISABLE_NETWORK"),
+ Some(network_env) => Platform::put_env("COMPOSER_DISABLE_NETWORK", network_env),
+ }
+}
+
+struct TearDown {
+ home: std::path::PathBuf,
+ network_env: Option<String>,
+}
+
+impl TearDown {
+ fn new(home: std::path::PathBuf, network_env: Option<String>) -> Self {
+ TearDown { home, network_env }
+ }
+}
+
+impl Drop for TearDown {
+ fn drop(&mut self) {
+ tear_down(&self.home, &self.network_env);
+ }
+}
+
macro_rules! git_stub {
($name:ident) => {
#[test]
#[ignore = "constructs a GitDriver and mocks a ProcessExecutor/HttpDownloader (curl_multi_init todo!())"]
fn $name() {
+ let SetUp {
+ home,
+ config: _,
+ network_env,
+ } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf(), network_env);
todo!()
}
};
diff --git a/crates/shirabe/tests/repository/vcs/github_driver_test.rs b/crates/shirabe/tests/repository/vcs/github_driver_test.rs
index d0067d5..3e97599 100644
--- a/crates/shirabe/tests/repository/vcs/github_driver_test.rs
+++ b/crates/shirabe/tests/repository/vcs/github_driver_test.rs
@@ -3,10 +3,55 @@
use std::cell::RefCell;
use std::rc::Rc;
+use indexmap::IndexMap;
use shirabe::config::Config;
use shirabe::io::IOInterface;
use shirabe::io::null_io::NullIO;
use shirabe::repository::vcs::GitHubDriver;
+use shirabe::util::filesystem::Filesystem;
+use shirabe_php_shim::PhpMixed;
+use tempfile::TempDir;
+
+struct SetUp {
+ home: TempDir,
+ config: Config,
+}
+
+fn set_up() -> SetUp {
+ let home = TempDir::new().unwrap();
+ let mut config = Config::new(true, None);
+ let mut top: IndexMap<String, PhpMixed> = IndexMap::new();
+ let mut config_section: IndexMap<String, PhpMixed> = IndexMap::new();
+ config_section.insert(
+ "home".to_string(),
+ PhpMixed::String(home.path().to_string_lossy().into_owned()),
+ );
+ top.insert("config".to_string(), PhpMixed::Array(config_section));
+ config.merge(&top, Config::SOURCE_UNKNOWN);
+
+ SetUp { home, config }
+}
+
+fn tear_down(home: &std::path::Path) {
+ let mut fs = Filesystem::new(None);
+ fs.remove_directory(home).unwrap();
+}
+
+struct TearDown {
+ home: std::path::PathBuf,
+}
+
+impl TearDown {
+ fn new(home: std::path::PathBuf) -> Self {
+ TearDown { home }
+ }
+}
+
+impl Drop for TearDown {
+ fn drop(&mut self) {
+ tear_down(&self.home);
+ }
+}
fn supports_provider() -> Vec<(bool, &'static str)> {
vec![
@@ -21,6 +66,9 @@ fn supports_provider() -> Vec<(bool, &'static str)> {
#[test]
#[ignore = "GitHubDriver::supports reaches non-strict in_array, which is todo!() in the php-shim"]
fn test_supports() {
+ let SetUp { home, config: _ } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf());
+
for (expected, repo_url) in supports_provider() {
let io: Rc<RefCell<dyn IOInterface>> = Rc::new(RefCell::new(NullIO::new()));
let config = Rc::new(RefCell::new(Config::new(true, None)));
@@ -38,53 +86,71 @@ fn test_supports() {
#[test]
#[ignore = "constructs a GitHubDriver and mocks the HttpDownloader/IO (curl_multi_init todo!())"]
fn test_private_repository() {
+ let SetUp { home, config: _ } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf());
todo!()
}
#[test]
#[ignore = "constructs a GitHubDriver and mocks the HttpDownloader/IO (curl_multi_init todo!())"]
fn test_public_repository() {
+ let SetUp { home, config: _ } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf());
todo!()
}
#[test]
#[ignore = "constructs a GitHubDriver and mocks the HttpDownloader/IO (curl_multi_init todo!())"]
fn test_public_repository2() {
+ let SetUp { home, config: _ } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf());
todo!()
}
#[test]
#[ignore = "constructs a GitHubDriver and mocks the HttpDownloader/IO (curl_multi_init todo!())"]
fn test_invalid_support_data() {
+ let SetUp { home, config: _ } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf());
todo!()
}
#[test]
#[ignore = "constructs a GitHubDriver and mocks the HttpDownloader/IO (curl_multi_init todo!())"]
fn test_funding_format() {
+ let SetUp { home, config: _ } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf());
todo!()
}
#[test]
#[ignore = "constructs a GitHubDriver and mocks the HttpDownloader/IO (curl_multi_init todo!())"]
fn test_public_repository_archived() {
+ let SetUp { home, config: _ } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf());
todo!()
}
#[test]
#[ignore = "constructs a GitHubDriver and mocks the HttpDownloader/IO (curl_multi_init todo!())"]
fn test_private_repository_no_interaction() {
+ let SetUp { home, config: _ } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf());
todo!()
}
#[test]
#[ignore = "constructs a GitHubDriver and mocks the HttpDownloader/IO (curl_multi_init todo!())"]
fn test_initialize_invalid_repo_url() {
+ let SetUp { home, config: _ } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf());
todo!()
}
#[test]
#[ignore = "constructs a GitHubDriver and mocks the HttpDownloader/IO (curl_multi_init todo!())"]
fn test_get_empty_file_content() {
+ let SetUp { home, config: _ } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf());
todo!()
}
diff --git a/crates/shirabe/tests/repository/vcs/hg_driver_test.rs b/crates/shirabe/tests/repository/vcs/hg_driver_test.rs
index d7ff5c3..155d7ce 100644
--- a/crates/shirabe/tests/repository/vcs/hg_driver_test.rs
+++ b/crates/shirabe/tests/repository/vcs/hg_driver_test.rs
@@ -3,10 +3,58 @@
use std::cell::RefCell;
use std::rc::Rc;
+use indexmap::IndexMap;
use shirabe::config::Config;
use shirabe::io::IOInterface;
use shirabe::io::null_io::NullIO;
use shirabe::repository::vcs::HgDriver;
+use shirabe::util::filesystem::Filesystem;
+use shirabe_php_shim::PhpMixed;
+use tempfile::TempDir;
+
+struct SetUp {
+ home: TempDir,
+ config: Config,
+ // The IOInterface mock is not ported.
+ io: (),
+}
+
+fn set_up() -> SetUp {
+ let io = ();
+ let home = TempDir::new().unwrap();
+ let mut config = Config::new(true, None);
+ let mut top: IndexMap<String, PhpMixed> = IndexMap::new();
+ let mut config_section: IndexMap<String, PhpMixed> = IndexMap::new();
+ config_section.insert(
+ "home".to_string(),
+ PhpMixed::String(home.path().to_string_lossy().into_owned()),
+ );
+ top.insert("config".to_string(), PhpMixed::Array(config_section));
+ config.merge(&top, Config::SOURCE_UNKNOWN);
+
+ SetUp { home, config, io }
+}
+
+fn tear_down(home: &std::path::Path) {
+ let mut fs = Filesystem::new(None);
+ fs.remove_directory(home).unwrap();
+}
+
+struct TearDown {
+ home: std::path::PathBuf,
+}
+
+impl TearDown {
+ fn new(home: std::path::PathBuf) -> Self {
+ TearDown { home }
+ }
+}
+
+impl Drop for TearDown {
+ fn drop(&mut self) {
+ tear_down(&self.home);
+ }
+}
fn supports_data_provider() -> Vec<&'static str> {
vec![
@@ -34,17 +82,26 @@ fn test_supports() {
#[test]
#[ignore = "needs an HgDriver instance (HttpDownloader reaches curl_multi_init, todo!()) and a mocked ProcessExecutor"]
fn test_get_branches_filter_invalid_branch_names() {
+ let SetUp { home, config, io } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf());
+ let _ = (&config, &io);
todo!()
}
#[test]
#[ignore = "needs an HgDriver instance (HttpDownloader reaches curl_multi_init, todo!()) and a mocked ProcessExecutor"]
fn test_file_get_content_invalid_identifier() {
+ let SetUp { home, config, io } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf());
+ let _ = (&config, &io);
todo!()
}
#[test]
#[ignore = "needs an HgDriver instance (HttpDownloader reaches curl_multi_init, todo!()) and a mocked ProcessExecutor"]
fn test_get_change_date_invalid_identifier() {
+ let SetUp { home, config, io } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf());
+ let _ = (&config, &io);
todo!()
}
diff --git a/crates/shirabe/tests/repository/vcs/perforce_driver_test.rs b/crates/shirabe/tests/repository/vcs/perforce_driver_test.rs
index c8353de..1c28487 100644
--- a/crates/shirabe/tests/repository/vcs/perforce_driver_test.rs
+++ b/crates/shirabe/tests/repository/vcs/perforce_driver_test.rs
@@ -3,10 +3,100 @@
use std::cell::RefCell;
use std::rc::Rc;
+use indexmap::IndexMap;
use shirabe::config::Config;
use shirabe::io::IOInterface;
use shirabe::io::null_io::NullIO;
use shirabe::repository::vcs::PerforceDriver;
+use shirabe::util::filesystem::Filesystem;
+use shirabe_php_shim::PhpMixed;
+use tempfile::TempDir;
+
+const TEST_URL: &str = "TEST_PERFORCE_URL";
+const TEST_DEPOT: &str = "TEST_DEPOT_CONFIG";
+const TEST_BRANCH: &str = "TEST_BRANCH_CONFIG";
+
+struct SetUp {
+ test_path: TempDir,
+ config: Config,
+ repo_config: IndexMap<String, PhpMixed>,
+ // The IOInterface, ProcessExecutor, HttpDownloader and Perforce mocks, the
+ // driver instance and the reflection-based perforce override are not ported.
+ io: (),
+ process: (),
+ http_downloader: (),
+ perforce: (),
+ driver: (),
+}
+
+fn get_test_config(test_path: &std::path::Path) -> Config {
+ let mut config = Config::new(true, None);
+ let mut top: IndexMap<String, PhpMixed> = IndexMap::new();
+ let mut config_section: IndexMap<String, PhpMixed> = IndexMap::new();
+ config_section.insert(
+ "home".to_string(),
+ PhpMixed::String(test_path.to_string_lossy().into_owned()),
+ );
+ top.insert("config".to_string(), PhpMixed::Array(config_section));
+ config.merge(&top, Config::SOURCE_UNKNOWN);
+
+ config
+}
+
+fn set_up() -> SetUp {
+ let test_path = TempDir::new().unwrap();
+ let config = get_test_config(test_path.path());
+ let mut repo_config: IndexMap<String, PhpMixed> = IndexMap::new();
+ repo_config.insert("url".to_string(), PhpMixed::String(TEST_URL.to_string()));
+ repo_config.insert(
+ "depot".to_string(),
+ PhpMixed::String(TEST_DEPOT.to_string()),
+ );
+ repo_config.insert(
+ "branch".to_string(),
+ PhpMixed::String(TEST_BRANCH.to_string()),
+ );
+
+ let io = ();
+ let process = ();
+ let http_downloader = ();
+ let perforce = ();
+ // The driver construction and overrideDriverInternalPerforce (reflection) are not ported.
+ let driver = ();
+
+ SetUp {
+ test_path,
+ config,
+ repo_config,
+ io,
+ process,
+ http_downloader,
+ perforce,
+ driver,
+ }
+}
+
+fn tear_down(test_path: &std::path::Path) {
+ // cleanup directory under test path
+ let mut fs = Filesystem::new(None);
+ fs.remove_directory(test_path).unwrap();
+}
+
+struct TearDown {
+ test_path: std::path::PathBuf,
+}
+
+impl TearDown {
+ fn new(test_path: std::path::PathBuf) -> Self {
+ TearDown { test_path }
+ }
+}
+
+impl Drop for TearDown {
+ fn drop(&mut self) {
+ tear_down(&self.test_path);
+ }
+}
#[test]
fn test_supports_returns_false_no_deep_check() {
@@ -21,29 +111,129 @@ fn test_supports_returns_false_no_deep_check() {
#[test]
#[ignore = "mocks Perforce/repository/IO; mocking is not available"]
fn test_initialize_captures_variables_from_repo_config() {
+ let SetUp {
+ test_path,
+ config,
+ repo_config,
+ io,
+ process,
+ http_downloader,
+ perforce,
+ driver,
+ } = set_up();
+ let _tear_down = TearDown::new(test_path.path().to_path_buf());
+ let _ = (
+ &config,
+ &repo_config,
+ &io,
+ &process,
+ &http_downloader,
+ &perforce,
+ &driver,
+ );
todo!()
}
#[test]
#[ignore = "mocks Perforce/repository/IO; mocking is not available"]
fn test_initialize_logs_in_and_connects_client() {
+ let SetUp {
+ test_path,
+ config,
+ repo_config,
+ io,
+ process,
+ http_downloader,
+ perforce,
+ driver,
+ } = set_up();
+ let _tear_down = TearDown::new(test_path.path().to_path_buf());
+ let _ = (
+ &config,
+ &repo_config,
+ &io,
+ &process,
+ &http_downloader,
+ &perforce,
+ &driver,
+ );
todo!()
}
#[test]
#[ignore = "mocks Perforce/repository/IO; mocking is not available"]
fn test_has_composer_file_returns_false_on_no_composer_file() {
+ let SetUp {
+ test_path,
+ config,
+ repo_config,
+ io,
+ process,
+ http_downloader,
+ perforce,
+ driver,
+ } = set_up();
+ let _tear_down = TearDown::new(test_path.path().to_path_buf());
+ let _ = (
+ &config,
+ &repo_config,
+ &io,
+ &process,
+ &http_downloader,
+ &perforce,
+ &driver,
+ );
todo!()
}
#[test]
#[ignore = "mocks Perforce/repository/IO; mocking is not available"]
fn test_has_composer_file_returns_true_with_one_or_more_composer_files() {
+ let SetUp {
+ test_path,
+ config,
+ repo_config,
+ io,
+ process,
+ http_downloader,
+ perforce,
+ driver,
+ } = set_up();
+ let _tear_down = TearDown::new(test_path.path().to_path_buf());
+ let _ = (
+ &config,
+ &repo_config,
+ &io,
+ &process,
+ &http_downloader,
+ &perforce,
+ &driver,
+ );
todo!()
}
#[test]
#[ignore = "mocks Perforce/repository/IO; mocking is not available"]
fn test_cleanup() {
+ let SetUp {
+ test_path,
+ config,
+ repo_config,
+ io,
+ process,
+ http_downloader,
+ perforce,
+ driver,
+ } = set_up();
+ let _tear_down = TearDown::new(test_path.path().to_path_buf());
+ let _ = (
+ &config,
+ &repo_config,
+ &io,
+ &process,
+ &http_downloader,
+ &perforce,
+ &driver,
+ );
todo!()
}
diff --git a/crates/shirabe/tests/repository/vcs/svn_driver_test.rs b/crates/shirabe/tests/repository/vcs/svn_driver_test.rs
index 262f0c3..9625088 100644
--- a/crates/shirabe/tests/repository/vcs/svn_driver_test.rs
+++ b/crates/shirabe/tests/repository/vcs/svn_driver_test.rs
@@ -3,10 +3,55 @@
use std::cell::RefCell;
use std::rc::Rc;
+use indexmap::IndexMap;
use shirabe::config::Config;
use shirabe::io::IOInterface;
use shirabe::io::null_io::NullIO;
use shirabe::repository::vcs::SvnDriver;
+use shirabe::util::filesystem::Filesystem;
+use shirabe_php_shim::PhpMixed;
+use tempfile::TempDir;
+
+struct SetUp {
+ home: TempDir,
+ config: Config,
+}
+
+fn set_up() -> SetUp {
+ let home = TempDir::new().unwrap();
+ let mut config = Config::new(true, None);
+ let mut top: IndexMap<String, PhpMixed> = IndexMap::new();
+ let mut config_section: IndexMap<String, PhpMixed> = IndexMap::new();
+ config_section.insert(
+ "home".to_string(),
+ PhpMixed::String(home.path().to_string_lossy().into_owned()),
+ );
+ top.insert("config".to_string(), PhpMixed::Array(config_section));
+ config.merge(&top, Config::SOURCE_UNKNOWN);
+
+ SetUp { home, config }
+}
+
+fn tear_down(home: &std::path::Path) {
+ let mut fs = Filesystem::new(None);
+ fs.remove_directory(home).unwrap();
+}
+
+struct TearDown {
+ home: std::path::PathBuf,
+}
+
+impl TearDown {
+ fn new(home: std::path::PathBuf) -> Self {
+ TearDown { home }
+ }
+}
+
+impl Drop for TearDown {
+ fn drop(&mut self) {
+ tear_down(&self.home);
+ }
+}
fn support_provider() -> Vec<(&'static str, bool)> {
vec![
@@ -35,5 +80,8 @@ fn test_support() {
#[test]
#[ignore = "constructs an SvnDriver and mocks a ProcessExecutor for the svn invocation"]
fn test_wrong_credentials_in_url() {
+ let SetUp { home, config } = set_up();
+ let _tear_down = TearDown::new(home.path().to_path_buf());
+ let _ = &config;
todo!()
}