Craft Anything: understand how any software works, and craft your own.
Rust
The change summary counts a comparison where files only moved as changed (#345)
BFlat9bec65baf2ee
diff --git a/crates/engine/src/tools/compare_tools.rs b/crates/engine/src/tools/compare_tools.rsindex 9ad648a8..b8a33034 100644--- a/crates/engine/src/tools/compare_tools.rs+++ b/crates/engine/src/tools/compare_tools.rs@@ -483,9 +483,13 @@ fn comparison_is_changed(result: &Value) -> bool {if let Some(s) = result.get("overall").and_then(Value::as_str) {return s != "unchanged";}+ // A comparison that says whether the two are identical decides; a moved file counts (#286).+ if let Some(same) = result.get("identical").and_then(Value::as_bool) {+ return !same;+ }if let Some(counts) = result.get("counts") {let n = |k: &str| counts.get(k).and_then(Value::as_u64).unwrap_or(0);- return n("added") + n("removed") + n("changed") > 0;+ return n("added") + n("removed") + n("changed") + n("moved") > 0;}false}@@ -779,6 +783,15 @@ mod tests {use craft_anything_testkit as tk;use serde_json::{Value, json};+ /// #286: an archive comparison where a file only moved was summarised as unchanged.+ #[test]+ fn a_moved_file_is_a_change() {+ let moved = json!({"identical": false, "counts": {"added": 0, "removed": 0, "changed": 0, "moved": 1, "unchanged": 0}});+ assert!(super::comparison_is_changed(&moved));+ assert!(super::comparison_is_changed(&json!({"counts": {"moved": 1}})));+ assert!(!super::comparison_is_changed(&json!({"identical": true, "counts": {"unchanged": 3}})));+ }+fn call_val(e: &Engine, id: &str, p: Value) -> Result<Value, craft_anything_evidence::ToolError> {e.call(id, p, CallOptions::new(Caller::Cli)).map(|o| o.to_json())}