From c6eb8f105146e4fded5bc757f1250bab13e12aa6 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 23 Aug 2024 10:02:08 +0200 Subject: [PATCH] Cleanup (rearranging test methods; linter warnings; typos) GitOrigin-RevId: 2994970f6f993b313638701d5278eb7b96b93ecb --- native/XPlatLauncher/tests/user_dir_tests.rs | 18 +++++++++++++----- native/XPlatLauncher/tests/utils/mod.rs | 14 +++----------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/native/XPlatLauncher/tests/user_dir_tests.rs b/native/XPlatLauncher/tests/user_dir_tests.rs index 92e9158ad778..0a2f7f685be1 100644 --- a/native/XPlatLauncher/tests/user_dir_tests.rs +++ b/native/XPlatLauncher/tests/user_dir_tests.rs @@ -4,8 +4,9 @@ pub mod utils; #[cfg(test)] mod tests { + use std::path::PathBuf; use std::sync::Mutex; - use xplat_launcher::jvm_property; + use xplat_launcher::{get_config_home, jvm_property}; use crate::utils::*; /// Tests depending on the shared user config directory cannot run concurrently. @@ -18,7 +19,7 @@ mod tests { let expected_rt = test.create_jbr_link("_user_jbr"); let jdk_config_name = if cfg!(target_os = "windows") { "xplat64.exe.jdk" } else { "xplat.jdk" }; - test.create_user_config_file(jdk_config_name, expected_rt.to_str().unwrap(), get_custom_config_dir()); + test.create_user_config_file(jdk_config_name, expected_rt.to_str().unwrap(), get_standard_config_dir()); let result = run_launcher_ext(&test, LauncherRunSpec::standard().assert_status()); test_runtime_selection(result, expected_rt); @@ -30,7 +31,7 @@ mod tests { let mut test = prepare_test_env(LauncherLocation::Standard); let vm_options_name = get_vm_options_name(); - let vm_options_file = test.create_user_config_file(vm_options_name, "-Done.user.option=whatever\n", get_custom_config_dir()); + let vm_options_file = test.create_user_config_file(vm_options_name, "-Done.user.option=whatever\n", get_standard_config_dir()); let dump = run_launcher_ext(&test, LauncherRunSpec::standard().with_dump().assert_status()).dump(); @@ -47,10 +48,17 @@ mod tests { let mut test = prepare_test_env(LauncherLocation::Standard); let vm_options_name = get_vm_options_name(); - let custom_config_dir = get_jetbrains_config_root().join("XPlatLauncherTestCustom"); - test.create_user_config_file(vm_options_name, "-Dcustom.property=custom.value\n", custom_config_dir); + test.create_user_config_file(vm_options_name, "-Dcustom.property=custom.value\n", get_custom_config_dir()); let result = run_launcher(LauncherRunSpec::standard().with_args(&["custom-command"]).assert_status()); assert!(result.stdout.contains("Custom command: product.property=product.value, custom.property=custom.value"), "Custom system property is not set: {:?}", result); } + + fn get_standard_config_dir() -> PathBuf { + get_config_home().unwrap().join("JetBrains").join("XPlatLauncherTest") + } + + fn get_custom_config_dir() -> PathBuf { + get_config_home().unwrap().join("JetBrains").join("XPlatLauncherTestCustom") + } } diff --git a/native/XPlatLauncher/tests/utils/mod.rs b/native/XPlatLauncher/tests/utils/mod.rs index cc9b72713340..027aa692e289 100644 --- a/native/XPlatLauncher/tests/utils/mod.rs +++ b/native/XPlatLauncher/tests/utils/mod.rs @@ -14,7 +14,7 @@ use log::debug; use serde::{Deserialize, Serialize}; use tempfile::{Builder, TempDir}; -use xplat_launcher::{DEBUG_MODE_ENV_VAR, get_config_home, PathExt}; +use xplat_launcher::{DEBUG_MODE_ENV_VAR, PathExt}; static INIT: Once = Once::new(); static mut SHARED: Option = None; @@ -208,7 +208,7 @@ fn init_test_environment_once() -> Result { let product_info_path = project_root.join(format!("resources/product_info_{}.json", env::consts::OS)); let vm_options_path = project_root.join("resources/xplat.vmoptions"); - // on build agents, a temp directory may reside in a different filesystem, so copies are needed for later linking + // on build agents, a temp directory may reside in a different filesystem, so copies are necessary for later linking let temp_dir = Builder::new().prefix("xplat_launcher_shared_").tempdir().context("Failed to create temp directory")?; let launcher_path = temp_dir.path().join(launcher_file.file_name().unwrap()); fs::copy(&launcher_file, &launcher_path).with_context(|| format!("Failed to copy {launcher_file:?} to {launcher_path:?}"))?; @@ -422,14 +422,6 @@ fn symlink(original: &Path, link: &Path) -> Result<()> { result.with_context(|| format!("Failed to create symlink {link:?} -> {original:?}; {message}")) } -pub fn get_custom_config_dir() -> PathBuf { - get_jetbrains_config_root().join("XPlatLauncherTest") -} - -pub fn get_jetbrains_config_root() -> PathBuf { - get_config_home().unwrap().join("JetBrains") -} - pub struct LauncherRunSpec { location: LauncherLocation, dump: bool, @@ -607,7 +599,7 @@ fn read_output_file(path: &Path) -> Result { if let Ok(string) = String::from_utf8(bytes.to_owned()) { Ok(string) } else { - for line in bytes.split(|b| *b == '\n' as u8) { + for line in bytes.split(|b| *b == b'\n') { if let Err(e) = String::from_utf8(line.to_owned()) { bail!("{}: {:?} {:?}", e, line, String::from_utf8_lossy(line)) }