Skip to content

Commit e231702

Browse files
committed
cargo-rail: fmt
1 parent 11f31d0 commit e231702

File tree

3 files changed

+31
-29
lines changed

3 files changed

+31
-29
lines changed

src/commands/init.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,12 @@ fn detect_workspace_patterns(ctx: &WorkspaceContext) -> WorkspacePatternInfo {
166166
for pkg in &members {
167167
if let Ok(rel_path) = pkg.manifest_path.strip_prefix(workspace_root)
168168
&& let Some(first_component) = rel_path.components().next()
169-
&& let Some(dir_name) = first_component.as_os_str().to_str()
170-
&& dir_name != "Cargo.toml" && !dir_name.starts_with('.') {
171-
subdirs.insert(dir_name.to_string());
172-
}
169+
&& let Some(dir_name) = first_component.as_os_str().to_str()
170+
&& dir_name != "Cargo.toml"
171+
&& !dir_name.starts_with('.')
172+
{
173+
subdirs.insert(dir_name.to_string());
174+
}
173175
}
174176

175177
let subdirectories: Vec<_> = subdirs.into_iter().collect();
@@ -590,11 +592,12 @@ fn check_existing_config(workspace_root: &Path) -> Option<PathBuf> {
590592
/// Ensure output directory exists (create if needed)
591593
fn ensure_output_dir(output_path: &Path) -> RailResult<()> {
592594
if let Some(parent) = output_path.parent()
593-
&& !parent.exists() {
594-
println!("📁 Creating directory: {}", parent.display());
595-
fs::create_dir_all(parent)
596-
.map_err(|e| RailError::message(format!("Failed to create directory {}: {}", parent.display(), e)))?;
597-
}
595+
&& !parent.exists()
596+
{
597+
println!("📁 Creating directory: {}", parent.display());
598+
fs::create_dir_all(parent)
599+
.map_err(|e| RailError::message(format!("Failed to create directory {}: {}", parent.display(), e)))?;
600+
}
598601
Ok(())
599602
}
600603

@@ -652,7 +655,10 @@ pub fn run_init_standalone(
652655
let policy_config = detect_policy_config(workspace_root)?;
653656

654657
// Display detected settings
655-
println!(" Toolchain: {} ({})", toolchain_config.channel, toolchain_config.profile);
658+
println!(
659+
" Toolchain: {} ({})",
660+
toolchain_config.channel, toolchain_config.profile
661+
);
656662
if let Some(ref resolver) = policy_config.resolver {
657663
println!(" Resolver: {}", resolver);
658664
}

tests/integration/helpers.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,5 @@ pub fn run_cargo_rail(cwd: &Path, args: &[&str]) -> Result<Output> {
209209

210210
/// Load RailConfig from a workspace
211211
pub fn load_rail_config(workspace_root: &Path) -> Result<cargo_rail::config::RailConfig> {
212-
cargo_rail::config::RailConfig::load(workspace_root)
213-
.context("Failed to load rail.toml configuration")
212+
cargo_rail::config::RailConfig::load(workspace_root).context("Failed to load rail.toml configuration")
214213
}

tests/integration/test_init.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Integration tests for `cargo rail init` command
22
3-
use crate::helpers::{load_rail_config, run_cargo_rail, TestWorkspace};
3+
use crate::helpers::{TestWorkspace, load_rail_config, run_cargo_rail};
44
use anyhow::Result;
55

66
#[test]
@@ -19,7 +19,7 @@ fn test_init_creates_config() -> Result<()> {
1919
assert!(config_path.exists(), "config file should be created");
2020

2121
// Verify config is valid TOML and contains expected sections
22-
let config_content = std::fs::read_to_string(&config_path)?;
22+
let config_content = std::fs::read_to_string(config_path)?;
2323
assert!(config_content.contains("[workspace]"));
2424
assert!(config_content.contains("[toolchain]"));
2525
assert!(config_content.contains("[unify]"));
@@ -69,7 +69,7 @@ fn test_init_detects_toolchain() -> Result<()> {
6969

7070
// Create rust-toolchain.toml with specific version
7171
std::fs::write(
72-
&ws.path.join("rust-toolchain.toml"),
72+
ws.path.join("rust-toolchain.toml"),
7373
r#"[toolchain]
7474
channel = "1.76.0"
7575
profile = "minimal"
@@ -81,7 +81,7 @@ components = ["clippy", "rustfmt"]
8181
run_cargo_rail(&ws.path, &["rail", "init", "--non-interactive"])?;
8282

8383
// Verify config detects toolchain
84-
let config_content = std::fs::read_to_string(&ws.path.join(".config/rail.toml"))?;
84+
let config_content = std::fs::read_to_string(ws.path.join(".config/rail.toml"))?;
8585
assert!(
8686
config_content.contains("channel = \"1.76.0\""),
8787
"should detect channel from rust-toolchain.toml"
@@ -105,20 +105,17 @@ fn test_init_detects_policy_from_cargo_toml() -> Result<()> {
105105

106106
// Update workspace Cargo.toml to add rust-version to existing workspace.package
107107
let cargo_toml = &ws.path.join("Cargo.toml");
108-
let existing_content = std::fs::read_to_string(&cargo_toml)?;
108+
let existing_content = std::fs::read_to_string(cargo_toml)?;
109109

110110
// Add rust-version to existing [workspace.package] section
111-
let new_content = existing_content.replace(
112-
"edition = \"2021\"",
113-
"edition = \"2021\"\nrust-version = \"1.75.0\"",
114-
);
115-
std::fs::write(&cargo_toml, new_content)?;
111+
let new_content = existing_content.replace("edition = \"2021\"", "edition = \"2021\"\nrust-version = \"1.75.0\"");
112+
std::fs::write(cargo_toml, new_content)?;
116113

117114
// Run init
118115
run_cargo_rail(&ws.path, &["rail", "init", "--non-interactive"])?;
119116

120117
// Verify config detects policy
121-
let config_content = std::fs::read_to_string(&ws.path.join(".config/rail.toml"))?;
118+
let config_content = std::fs::read_to_string(ws.path.join(".config/rail.toml"))?;
122119
assert!(
123120
config_content.contains("resolver = \"2\""),
124121
"should detect resolver from Cargo.toml"
@@ -221,9 +218,9 @@ fn test_init_generated_config_is_valid() -> Result<()> {
221218
assert_eq!(config.workspace.root.to_str().unwrap(), ".");
222219
assert_eq!(config.toolchain.channel, "stable");
223220
assert_eq!(config.toolchain.profile, "default");
224-
assert_eq!(config.unify.use_all_features, true);
225-
assert_eq!(config.unify.sync_on_unify, true);
226-
assert_eq!(config.security.require_signed_commits, false);
221+
assert!(config.unify.use_all_features);
222+
assert!(config.unify.sync_on_unify);
223+
assert!(!config.security.require_signed_commits);
227224
assert_eq!(config.security.protected_branches, vec!["main", "master"]);
228225

229226
Ok(())
@@ -235,13 +232,13 @@ fn test_init_with_rust_toolchain_plain_file() -> Result<()> {
235232
ws.remove_config()?; // Remove default config for init test
236233

237234
// Create plain rust-toolchain file (no .toml extension)
238-
std::fs::write(&ws.path.join("rust-toolchain"), "1.80.0\n")?;
235+
std::fs::write(ws.path.join("rust-toolchain"), "1.80.0\n")?;
239236

240237
// Run init
241238
run_cargo_rail(&ws.path, &["rail", "init", "--non-interactive"])?;
242239

243240
// Verify config detects channel
244-
let config_content = std::fs::read_to_string(&ws.path.join(".config/rail.toml"))?;
241+
let config_content = std::fs::read_to_string(ws.path.join(".config/rail.toml"))?;
245242
assert!(
246243
config_content.contains("channel = \"1.80.0\""),
247244
"should detect channel from rust-toolchain file"
@@ -258,7 +255,7 @@ fn test_init_all_fields_present() -> Result<()> {
258255
// Run init
259256
run_cargo_rail(&ws.path, &["rail", "init", "--non-interactive"])?;
260257

261-
let config_content = std::fs::read_to_string(&ws.path.join(".config/rail.toml"))?;
258+
let config_content = std::fs::read_to_string(ws.path.join(".config/rail.toml"))?;
262259

263260
// Verify ALL config sections and fields are present (active or commented)
264261

0 commit comments

Comments
 (0)