From 07e80a5177abfd4185a4bdc191774347c484fc90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Wed, 25 Nov 2026 15:06:34 -0500 Subject: [PATCH 1/3] test(script): the go-to-error tests name the cursor offset and remove their temp file even when an assert fails (#2938) --- crates/engine/src/tests.rs | 12 +++++++++--- crates/ui-egui/src/analysispane.rs | 13 ++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index d2bc6eec41..a530b35379 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -3461,11 +3461,17 @@ fn a_scripts_error_says_where_it_stopped() { // JSON cut short: its last character, never past the line. assert_eq!(stop(&mut s, "layer.rename {\"name\": ", "line 1: "), Some((1, Some(21)))); // An edit to a layer read in place. - let path = grid_fgb("script-stopped-at", 4); - let mut streamed = with_streamed(&path); + // The file goes when the test ends, whether or not an assert failed first (`stop` asserts too). + struct RemoveOnDrop(std::path::PathBuf); + impl Drop for RemoveOnDrop { + fn drop(&mut self) { + let _ = std::fs::remove_file(&self.0); + } + } + let path = RemoveOnDrop(grid_fgb("script-stopped-at", 4)); + let mut streamed = with_streamed(&path.0); let script = "edit.enable {\"on\": true}\nedit.addFeature {\"layer\": \"Streamed\", \"geometry\": {\"type\": \"Point\", \"coordinates\": [1, 2]}}"; assert_eq!(stop(&mut streamed, script, "line 2: "), Some((2, None))); - let _ = std::fs::remove_file(path); // Errors that name no line of the script. let long = "map.zoomFull\n".repeat(crate::cmd::workflows::MAX_SCRIPT_LINES + 1); let e = s.run("script.run", &json!({"script": long})).unwrap_err(); diff --git a/crates/ui-egui/src/analysispane.rs b/crates/ui-egui/src/analysispane.rs index 43a9177620..87afd4c6a6 100644 --- a/crates/ui-egui/src/analysispane.rs +++ b/crates/ui-egui/src/analysispane.rs @@ -3124,18 +3124,21 @@ mod tests { script_ran(&mut app, crate::Landed::NotRun("cancelled".into())); assert_eq!(at(&app), None); // JSON that doesn't read, after two lines; a click on the error goes to its column. - let e = stopped(&mut app, "# move\nmap.zoomFull\nlayer.rename {\"layer\": }"); - assert_eq!(at(&app), Some((3, Some(24))), "{e}"); + let (first, second, column) = ("# move\n", "map.zoomFull\n", 24); + let e = stopped(&mut app, &format!("{first}{second}layer.rename {{\"layer\": }}")); + assert_eq!(at(&app), Some((3, Some(column))), "{e}"); + // The cursor goes to the error: the characters of the two lines before it, and its column. + let error_at = first.chars().count() + second.chars().count() + (column - 1); let mut h = egui_kittest::Harness::builder() .with_size(vec2(900.0, 800.0)) .build_ui_state(|ui, app: &mut RustGisApp| script_pane(app, ui, &Tokens::light()), app); h.run(); let box_id = egui::Id::unique("script_text"); let cursor = |h: &egui_kittest::Harness<'_, RustGisApp>| crate::widgets::cursor_range(&h.ctx, box_id).map(|r| r.primary.index.0); - assert_ne!(cursor(&h), Some(7 + 13 + 23)); + assert_ne!(cursor(&h), Some(error_at)); h.get_by_label(&e).click(); h.run(); - assert_eq!(cursor(&h), Some(7 + 13 + 23), "line 3, column 24"); + assert_eq!(cursor(&h), Some(error_at), "line 3, column {column}"); assert!(h.ctx.memory(|m| m.has_focus(box_id))); // From the keyboard: the error takes the focus (Tab), and Enter goes there too. crate::widgets::set_cursor_range(&h.ctx, box_id, egui::text::CCursorRange::one(egui::text::CCursor::new(0))); @@ -3144,7 +3147,7 @@ mod tests { assert_eq!(cursor(&h), Some(0), "moved away first"); h.key_press(egui::Key::Enter); h.run(); - assert_eq!(cursor(&h), Some(7 + 13 + 23), "by the keyboard"); + assert_eq!(cursor(&h), Some(error_at), "by the keyboard"); // Edited since: the error no longer goes anywhere. h.state_mut().workflow.script.insert(0, '\n'); h.run(); From d8a55196935a6c5783f58c3fa27cac5130c18059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Wed, 25 Nov 2026 15:51:49 -0500 Subject: [PATCH 2/3] test(script): the guard's comment sits with its code, and the error's column comes from the script's line (#2938) --- crates/engine/src/tests.rs | 2 +- crates/ui-egui/src/analysispane.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index a530b35379..517bef441a 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -3460,7 +3460,6 @@ fn a_scripts_error_says_where_it_stopped() { assert_eq!(stop(&mut s, "layer.rename {\"name\": \"Bogotá\", }", "line 1: "), Some((1, Some(33)))); // JSON cut short: its last character, never past the line. assert_eq!(stop(&mut s, "layer.rename {\"name\": ", "line 1: "), Some((1, Some(21)))); - // An edit to a layer read in place. // The file goes when the test ends, whether or not an assert failed first (`stop` asserts too). struct RemoveOnDrop(std::path::PathBuf); impl Drop for RemoveOnDrop { @@ -3468,6 +3467,7 @@ fn a_scripts_error_says_where_it_stopped() { let _ = std::fs::remove_file(&self.0); } } + // An edit to a layer read in place. let path = RemoveOnDrop(grid_fgb("script-stopped-at", 4)); let mut streamed = with_streamed(&path.0); let script = "edit.enable {\"on\": true}\nedit.addFeature {\"layer\": \"Streamed\", \"geometry\": {\"type\": \"Point\", \"coordinates\": [1, 2]}}"; diff --git a/crates/ui-egui/src/analysispane.rs b/crates/ui-egui/src/analysispane.rs index 87afd4c6a6..414a03392e 100644 --- a/crates/ui-egui/src/analysispane.rs +++ b/crates/ui-egui/src/analysispane.rs @@ -3124,8 +3124,10 @@ mod tests { script_ran(&mut app, crate::Landed::NotRun("cancelled".into())); assert_eq!(at(&app), None); // JSON that doesn't read, after two lines; a click on the error goes to its column. - let (first, second, column) = ("# move\n", "map.zoomFull\n", 24); - let e = stopped(&mut app, &format!("{first}{second}layer.rename {{\"layer\": }}")); + let (first, second, third) = ("# move\n", "map.zoomFull\n", r#"layer.rename {"layer": }"#); + // The JSON stops reading at the closing brace, the line's last character. + let column = third.chars().count(); + let e = stopped(&mut app, &format!("{first}{second}{third}")); assert_eq!(at(&app), Some((3, Some(column))), "{e}"); // The cursor goes to the error: the characters of the two lines before it, and its column. let error_at = first.chars().count() + second.chars().count() + (column - 1); From c0ab3b9c945e88a7d18a56bd67ec79995e8b1694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Wed, 25 Nov 2026 16:06:57 -0500 Subject: [PATCH 3/3] test(script): the guard's drop order is written down (#2938) --- crates/engine/src/tests.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 517bef441a..60fe6a9fa5 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -3468,6 +3468,8 @@ fn a_scripts_error_says_where_it_stopped() { } } // An edit to a layer read in place. + // `streamed` is declared after `path`, so it drops first and releases the file before it is removed + // (a file still open can't be removed on Windows): keep this order. let path = RemoveOnDrop(grid_fgb("script-stopped-at", 4)); let mut streamed = with_streamed(&path.0); let script = "edit.enable {\"on\": true}\nedit.addFeature {\"layer\": \"Streamed\", \"geometry\": {\"type\": \"Point\", \"coordinates\": [1, 2]}}";