Skip to content

Commit 9f23256

Browse files
authored
Merge pull request #95 from rodneylab/fix__make_dependencies_optional
fix: 💫 make dependemcies in Cargo.toml optional
2 parents 0e74232 + 44528bc commit 9f23256

File tree

8 files changed

+30
-67
lines changed

8 files changed

+30
-67
lines changed

.cargo/audit.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[advisories]
2-
ignore = ["RUSTSEC-2025-0014"]
2+
ignore = []

Cargo.lock

Lines changed: 0 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ opt-level = 3
1818
opt-level = 3
1919

2020
[dependencies]
21-
ahash = "0.8.11"
2221
anyhow = "1.0.97"
2322
clap = { version = "4.5.35", features = ["derive"] }
2423
clap-verbosity-flag = "3.0.2"

deny.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ feature-depth = 1
7171
# A list of advisory IDs to ignore. Note that ignored advisories will still
7272
# output a note when they are encountered.
7373
ignore = [
74-
"RUSTSEC-2025-0014",
7574
# "RUSTSEC-0000-0000",
7675
# { id = "RUSTSEC-0000-0000", reason = "you can specify a reason the advisory is ignored" },
7776
# "[email protected]", # you can also ignore yanked crate versions if you wish
@@ -92,7 +91,6 @@ ignore = [
9291
# [possible values: any SPDX 3.11 short identifier (+ optional exception)].
9392
allow = [
9493
"Apache-2.0",
95-
"BSD-2-Clause",
9694
"BSD-3-Clause",
9795
"ISC",
9896
"MIT",

justfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
default:
2+
just --list
3+
14
# find comments in Rust source
25
comments:
36
rg --pcre2 -t rust '(^|\s+)(\/\/|\/\*)\s+(?!(act|arrange|assert))' .

src/domain/cargo_toml/mod.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ use super::SemverVersion;
1616

1717
#[derive(Debug)]
1818
pub struct File {
19-
dependencies: BTreeMap<String, CargoDependencyValue>,
19+
dependencies: Option<BTreeMap<String, CargoDependencyValue>>,
2020
build_dependencies: Option<BTreeMap<String, CargoDependencyValue>>,
2121
dev_dependencies: Option<BTreeMap<String, CargoDependencyValue>>,
22+
23+
#[expect(dead_code)]
24+
workspace_dependencies: Option<BTreeMap<String, CargoDependencyValue>>,
2225
}
2326

2427
impl File {
@@ -31,6 +34,7 @@ impl File {
3134
dependencies,
3235
build_dependencies,
3336
dev_dependencies,
37+
workspace_dependencies,
3438
} = current_cargo
3539
.try_deserialize::<CargoFile>()
3640
.with_context(|| format!("Error parsing `{path}`"))?;
@@ -42,6 +46,7 @@ impl File {
4246
dependencies,
4347
build_dependencies,
4448
dev_dependencies,
49+
workspace_dependencies,
4550
})
4651
}
4752

@@ -56,13 +61,15 @@ impl File {
5661
dependencies,
5762
build_dependencies,
5863
dev_dependencies,
64+
workspace_dependencies,
5965
} = toml::from_str(toml_str).context("Creating `CargoFile` from str")?;
6066
log::trace!("Cargo: {dependencies:?}");
6167

6268
Ok(Self {
6369
dependencies,
6470
build_dependencies,
6571
dev_dependencies,
72+
workspace_dependencies,
6673
})
6774
}
6875

@@ -285,9 +292,9 @@ impl File {
285292
pub fn print_changes_versus_previous_version(&self, previous: &Self) -> anyhow::Result<String> {
286293
let mut result: String = String::new();
287294

288-
Self::get_dependency_changes_versus_previous(
289-
&self.dependencies,
290-
&previous.dependencies,
295+
Self::get_optional_dependency_changes_versus_previous(
296+
self.dependencies.as_ref(),
297+
previous.dependencies.as_ref(),
291298
None,
292299
&mut result,
293300
)?;
@@ -353,7 +360,8 @@ pub enum CargoDependencyValue {
353360
#[cfg_attr(test, derive(serde::Serialize))]
354361
#[serde(rename_all = "kebab-case")]
355362
pub struct CargoFile {
356-
pub dependencies: BTreeMap<String, CargoDependencyValue>,
363+
pub dependencies: Option<BTreeMap<String, CargoDependencyValue>>,
357364
pub build_dependencies: Option<BTreeMap<String, CargoDependencyValue>>,
358365
pub dev_dependencies: Option<BTreeMap<String, CargoDependencyValue>>,
366+
pub workspace_dependencies: Option<BTreeMap<String, CargoDependencyValue>>,
359367
}

src/domain/cargo_toml/snapshots/rust_crate_diffs__domain__cargo_toml__tests__new_from_buffer_creates_expected_config.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
source: src/domain/cargo_toml/tests.rs
33
expression: "format!(\"{outcome:?}\")"
44
---
5-
File { dependencies: {"ahash": Simple("0.8.11"), "clap": Detailed(DetailedCargoDependency { version: "4.5.23", package: None }), "clap-verbosity-flag": Simple("3.0.1"), "config": Simple("0.14.1"), "env_logger": Simple("0.11.5"), "git2": Simple("0.19.0"), "log": Simple("0.4.22"), "serde": Detailed(DetailedCargoDependency { version: "1.0.215", package: None }), "sqlx": Detailed(DetailedCargoDependency { version: "0.8.2", package: None })}, build_dependencies: None, dev_dependencies: Some({"assert_fs": Simple("1.1.2"), "trycmd": Simple("0.15.8")}) }
5+
File { dependencies: Some({"ahash": Simple("0.8.11"), "clap": Detailed(DetailedCargoDependency { version: "4.5.23", package: None }), "clap-verbosity-flag": Simple("3.0.1"), "config": Simple("0.14.1"), "env_logger": Simple("0.11.5"), "git2": Simple("0.19.0"), "log": Simple("0.4.22"), "serde": Detailed(DetailedCargoDependency { version: "1.0.215", package: None }), "sqlx": Detailed(DetailedCargoDependency { version: "0.8.2", package: None })}), build_dependencies: None, dev_dependencies: Some({"assert_fs": Simple("1.1.2"), "trycmd": Simple("0.15.8")}), workspace_dependencies: None }

src/domain/cargo_toml/tests.rs

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,32 @@ fn new_successfully_parses_valid_cargo_toml_dependencies() {
5353
let File { dependencies, .. } = File::new(temporary_cargo_toml_path.to_str().unwrap()).unwrap();
5454

5555
// assert
56-
assert_eq!(dependencies.len(), 9);
56+
assert!(dependencies.is_some());
57+
let Some(dependencies_value) = dependencies else {
58+
panic!("dependencies should be some");
59+
};
60+
assert_eq!(dependencies_value.len(), 9);
5761
assert_eq!(
58-
dependencies.get("ahash"),
62+
dependencies_value.get("ahash"),
5963
Some(CargoDependencyValue::Simple(String::from("0.8.11"))).as_ref()
6064
);
6165
assert_eq!(
62-
dependencies.get("serde"),
66+
dependencies_value.get("serde"),
6367
Some(CargoDependencyValue::Detailed(DetailedCargoDependency {
6468
version: String::from("1.0.215"),
6569
package: None
6670
}))
6771
.as_ref()
6872
);
6973
assert_eq!(
70-
dependencies.get("sqlx"),
74+
dependencies_value.get("sqlx"),
7175
Some(CargoDependencyValue::Detailed(DetailedCargoDependency {
7276
version: String::from("0.8.2"),
7377
package: None
7478
}))
7579
.as_ref()
7680
);
77-
insta::assert_json_snapshot!(dependencies);
81+
insta::assert_json_snapshot!(dependencies_value);
7882
}
7983

8084
#[test]
@@ -112,7 +116,7 @@ fn new_handles_missing_cargo_toml() {
112116
assert!(chain.next().is_none());
113117
}
114118
#[test]
115-
fn new_handles_missing_dependencies_in_cargo_toml() {
119+
fn new_accetps_missing_dependencies_in_cargo_toml() {
116120
// arrange
117121
let temp_dir = assert_fs::TempDir::new().unwrap();
118122
let cargo_toml_content = r#"[package]
@@ -133,25 +137,10 @@ trycmd = "0.15.8"
133137
let temporary_cargo_toml_path = temp_dir.join("Cargo.toml");
134138

135139
// act
136-
let outcome = File::new(temporary_cargo_toml_path.to_str().unwrap()).unwrap_err();
140+
let outcome = File::new(temporary_cargo_toml_path.to_str().unwrap());
137141

138142
// assert
139-
assert_eq!(
140-
format!("{outcome}"),
141-
format!("Error parsing `{}`", temporary_cargo_toml_path.display())
142-
);
143-
let mut chain = outcome.chain();
144-
assert_eq!(
145-
chain.next().map(|val| format!("{val}")),
146-
Some(format!(
147-
"Error parsing `{}`",
148-
temporary_cargo_toml_path.display()
149-
))
150-
);
151-
assert_eq!(
152-
chain.next().map(|val| format!("{val}")),
153-
Some(String::from("missing field `dependencies`",))
154-
);
143+
assert!(outcome.is_ok());
155144
}
156145

157146
#[test]

0 commit comments

Comments
 (0)