From b6e0492593a6c6e30f7a1292949e0fffda6fe717 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 24 Jan 2026 09:48:18 +0000 Subject: [PATCH 1/5] Initial plan From ca6e52d330c8ee439a49dd9a0ff112a7732a0dcf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 24 Jan 2026 09:58:32 +0000 Subject: [PATCH 2/5] refactor: use expect_snapshot_igraph_error() and move test function to separate file Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com> --- src/rinterface_extra.c | 7 ----- src/test_error_with_source.c | 33 +++++++++++++++++++++ tests/testthat/test-adjacency.R | 2 +- tests/testthat/test-attributes.R | 18 +++++------ tests/testthat/test-centrality.R | 2 +- tests/testthat/test-conversion.R | 6 ++-- tests/testthat/test-error-formatting.R | 4 +++ tests/testthat/test-fit.R | 2 +- tests/testthat/test-flow.R | 16 +++++----- tests/testthat/test-foreign.R | 8 ++--- tests/testthat/test-hrg.R | 4 +-- tests/testthat/test-incidence.R | 8 ++--- tests/testthat/test-interface.R | 6 ++-- tests/testthat/test-iterators.R | 4 +-- tests/testthat/test-layout.R | 6 ++-- tests/testthat/test-make.R | 6 ++-- tests/testthat/test-other.R | 2 +- tests/testthat/test-plot.R | 2 +- tests/testthat/test-structural-properties.R | 4 +-- tests/testthat/test-versions.R | 18 +++++------ 20 files changed, 94 insertions(+), 64 deletions(-) create mode 100644 src/test_error_with_source.c diff --git a/src/rinterface_extra.c b/src/rinterface_extra.c index d88ba20810e..9e8c68c9332 100644 --- a/src/rinterface_extra.c +++ b/src/rinterface_extra.c @@ -7760,13 +7760,6 @@ SEXP Rx_igraph_create_bipartite(SEXP types, SEXP edges, SEXP directed) { return R_igraph_create_bipartite(types, edges, directed); } -/* Test function to verify error formatting with file and line information */ -attribute_visible SEXP Rx_igraph_test_error_with_source(void) { - igraph_errorf("Test error message for verifying source location formatting", - __FILE__, __LINE__, IGRAPH_EINVAL); - return R_NilValue; -} - SEXP Rx_igraph_finalizer(void) { return R_igraph_finalizer(); } diff --git a/src/test_error_with_source.c b/src/test_error_with_source.c new file mode 100644 index 00000000000..3a66e48ba34 --- /dev/null +++ b/src/test_error_with_source.c @@ -0,0 +1,33 @@ +/* -*- mode: C -*- */ +/* + IGraph library R interface. + Copyright (C) 2013 Gabor Csardi + 334 Harvard street, Cambridge, MA 02139 USA + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA + +*/ + +#include "rinterface.h" + +#include + +/* Test function to verify error formatting with file and line information */ +attribute_visible SEXP Rx_igraph_test_error_with_source(void) { + igraph_errorf("Test error message for verifying source location formatting", + __FILE__, __LINE__, IGRAPH_EINVAL); + return R_NilValue; +} diff --git a/tests/testthat/test-adjacency.R b/tests/testthat/test-adjacency.R index b488ca4302d..cd8c838e468 100644 --- a/tests/testthat/test-adjacency.R +++ b/tests/testthat/test-adjacency.R @@ -787,7 +787,7 @@ test_that("sparse/dense matrices min/max/plus", { test_that("graph_from_adjacency_matrix errors for NAs", { A <- matrix(c(1, 1, NA, 1), 2, 2) - expect_snapshot(graph_from_adjacency_matrix(A), error = TRUE) + expect_snapshot_igraph_error(graph_from_adjacency_matrix(A)) }) test_that("graph_from_adjacency_matrix handles add.colnames and add.rownames = FALSE correctly", { diff --git a/tests/testthat/test-attributes.R b/tests/testthat/test-attributes.R index 71d70df15f8..bf54e2ae311 100644 --- a/tests/testthat/test-attributes.R +++ b/tests/testthat/test-attributes.R @@ -436,13 +436,13 @@ test_that("adding and removing attributes", { test_that("error messages work", { g <- make_full_graph(5) - expect_snapshot(set_vertex_attr(g, "test", value = c(1, 2)), error = TRUE) - expect_snapshot(set_edge_attr(g, "test", value = c(1, 2)), error = TRUE) - expect_snapshot(delete_graph_attr(g, "a"), error = TRUE) - expect_snapshot(delete_vertex_attr(g, "a"), error = TRUE) - expect_snapshot(delete_edge_attr(g, "a"), error = TRUE) - expect_snapshot(assert_named_list("a"), error = TRUE) - expect_snapshot(assert_named_list(list("a", "b")), error = TRUE) + expect_snapshot_igraph_error(set_vertex_attr(g, "test", value = c(1, 2))) + expect_snapshot_igraph_error(set_edge_attr(g, "test", value = c(1, 2))) + expect_snapshot_igraph_error(delete_graph_attr(g, "a")) + expect_snapshot_igraph_error(delete_vertex_attr(g, "a")) + expect_snapshot_igraph_error(delete_edge_attr(g, "a")) + expect_snapshot_igraph_error(assert_named_list("a")) + expect_snapshot_igraph_error(assert_named_list(list("a", "b"))) }) test_that("empty returns work", { @@ -465,7 +465,7 @@ test_that("assign data.frame attributes works", { test_that("good error message when not using character", { ring <- graph_from_literal(A - B - C - D - E - F - G - A) - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ set_graph_attr(ring, 1, 1) }) }) @@ -476,7 +476,7 @@ test_that("set_vertex_attrs() works", { expect_equal(V(g)$color, rep("blue", vcount(g))) expect_equal(V(g)$size, rep(10, vcount(g))) expect_equal(V(g)$name, LETTERS[1:10]) - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ set_vertex_attrs(g) }) diff --git a/tests/testthat/test-centrality.R b/tests/testthat/test-centrality.R index 65e0a407c0c..71bd753a7e6 100644 --- a/tests/testthat/test-centrality.R +++ b/tests/testthat/test-centrality.R @@ -848,7 +848,7 @@ test_that("arpack() errors well", { expect_snapshot_igraph_error({ arpack(f, options = list(nev = 2, ncv = 4), sym = TRUE) }) - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ arpack( f, options = list(unknown_thing1 = 2, unknown_thing2 = 4), diff --git a/tests/testthat/test-conversion.R b/tests/testthat/test-conversion.R index 5fddb5f12fb..367e4d7d068 100644 --- a/tests/testthat/test-conversion.R +++ b/tests/testthat/test-conversion.R @@ -142,10 +142,10 @@ test_that("as_adjacency_matrix() works -- sparse + not both", { test_that("as_adjacency_matrix() errors well -- sparse", { g <- make_graph(c(1, 2, 2, 1, 2, 2, 3, 3, 3, 3, 3, 4, 4, 2, 4, 2, 4, 2), directed = TRUE) - expect_snapshot(as_adjacency_matrix(g, attr = "bla"), error = TRUE) + expect_snapshot_igraph_error(as_adjacency_matrix(g, attr = "bla")) E(g)$bla <- letters[1:ecount(g)] - expect_snapshot(as_adjacency_matrix(g, attr = "bla"), error = TRUE) + expect_snapshot_igraph_error(as_adjacency_matrix(g, attr = "bla")) }) test_that("as_adjacency_matrix() works -- sparse undirected", { @@ -679,7 +679,7 @@ test_that("edge names work", { test_that("graph_from_edgelist errors for NAs", { A <- matrix(c(1, 2, NA, 1), 2, 2) - expect_snapshot(graph_from_edgelist(A), error = TRUE) + expect_snapshot_igraph_error(graph_from_edgelist(A)) }) test_that("graph_from_data_frame works with factors", { diff --git a/tests/testthat/test-error-formatting.R b/tests/testthat/test-error-formatting.R index 5e19acb2a66..a29e5d59c7e 100644 --- a/tests/testthat/test-error-formatting.R +++ b/tests/testthat/test-error-formatting.R @@ -1,4 +1,8 @@ test_that("error messages include source file and line information", { + # Note: We use expect_snapshot(error = TRUE) here instead of + # expect_snapshot_igraph_error() because we need to test the actual + # line numbers in the error message, which expect_snapshot_igraph_error() + # would transform to "xx". expect_snapshot( error = TRUE, { diff --git a/tests/testthat/test-fit.R b/tests/testthat/test-fit.R index 0b6019461e0..67cb5288880 100644 --- a/tests/testthat/test-fit.R +++ b/tests/testthat/test-fit.R @@ -28,7 +28,7 @@ test_that("fit_power_law() works", { }) test_that("fit_power_law() errors well", { - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ fit_power_law(1, implementation = "R.mle") }) }) diff --git a/tests/testthat/test-flow.R b/tests/testthat/test-flow.R index 3083a8bbf72..c620a0900da 100644 --- a/tests/testthat/test-flow.R +++ b/tests/testthat/test-flow.R @@ -98,8 +98,8 @@ test_that("st_cuts() works", { test_that("st_cuts errors work", { g_path <- graph_from_literal(a -+ b -+ c -+ d -+ e) - expect_snapshot(st_cuts(g_path, source = "a", target = NULL), error = TRUE) - expect_snapshot(st_cuts(g_path, source = NULL, target = "a"), error = TRUE) + expect_snapshot_igraph_error(st_cuts(g_path, source = "a", target = NULL)) + expect_snapshot_igraph_error(st_cuts(g_path, source = NULL, target = "a")) expect_snapshot( st_min_cuts(g_path, source = "a", target = NULL), error = TRUE @@ -142,7 +142,7 @@ test_that("vertex_connectivity() works", { test_that("vertex_connectivity error works", { g_path <- make_ring(5, circular = FALSE) - expect_snapshot(vertex_connectivity(g_path, source = 1), error = TRUE) + expect_snapshot_igraph_error(vertex_connectivity(g_path, source = 1)) }) test_that("edge_connectivity works", { @@ -179,7 +179,7 @@ test_that("edge_connectivity works -- names", { test_that("edge_connectivity error works", { g_path <- make_ring(5, circular = FALSE) - expect_snapshot(edge_connectivity(g_path, source = 1), error = TRUE) + expect_snapshot_igraph_error(edge_connectivity(g_path, source = 1)) }) test_that("edge_disjoint_paths works", { @@ -212,7 +212,7 @@ test_that("vertex_disjoint_paths works", { test_that("vertex_disjoint_paths error works", { g_path <- make_ring(5, circular = FALSE) - expect_snapshot(vertex_disjoint_paths(g_path, source = 1), error = TRUE) + expect_snapshot_igraph_error(vertex_disjoint_paths(g_path, source = 1)) }) test_that("adhesion works", { @@ -225,7 +225,7 @@ test_that("adhesion works", { test_that("vertex_disjoint_paths error works", { g_path <- make_ring(5, circular = FALSE) - expect_snapshot(vertex_disjoint_paths(g_path, source = 1), error = TRUE) + expect_snapshot_igraph_error(vertex_disjoint_paths(g_path, source = 1)) }) @@ -252,8 +252,8 @@ test_that("dominator_tree errors work", { matrix(c(1, 2, 2, 3, 3, 4, 2, 5, 5, 6), byrow = TRUE, ncol = 2), directed = TRUE ) - expect_snapshot(dominator_tree(g_tree), error = TRUE) - expect_snapshot(dominator_tree(g_tree, root = NULL), error = TRUE) + expect_snapshot_igraph_error(dominator_tree(g_tree)) + expect_snapshot_igraph_error(dominator_tree(g_tree, root = NULL)) }) test_that("dominator_tree works -- legacy", { diff --git a/tests/testthat/test-foreign.R b/tests/testthat/test-foreign.R index 75f2c7a53f3..54b2b90c3b3 100644 --- a/tests/testthat/test-foreign.R +++ b/tests/testthat/test-foreign.R @@ -49,17 +49,17 @@ test_that("reading graph, unused argument", { lgl_path <- withr::local_tempfile(pattern = "testfile", fileext = ".lgl") g <- make_graph(c(1, 2, 2, 3)) write_graph(g, lgl_path, "lgl") - expect_snapshot(error = TRUE, read_graph(lgl_path, "lgl", useless = 1)) + expect_snapshot_igraph_error(read_graph(lgl_path, "lgl", useless = 1)) }) test_that("reading graph in unsupported format", { - expect_snapshot(error = TRUE, read_graph("bla", format = "blop")) + expect_snapshot_igraph_error(read_graph("bla", format = "blop")) }) test_that("writing graph in unsupported format", { g <- make_graph(c(1, 2, 2, 3)) file <- withr::local_tempfile() - expect_snapshot(error = TRUE, write_graph(g, file, format = "blop")) + expect_snapshot_igraph_error(write_graph(g, file, format = "blop")) }) test_that("graph_from_graphdb works", { @@ -72,7 +72,7 @@ test_that("graph_from_graphdb works", { skip_if(Sys.getenv("R_SANITIZER") == "true") expect_snapshot(g <- graph_from_graphdb(nodes = 1000)) - expect_snapshot(g <- graph_from_graphdb(), error = TRUE) + expect_snapshot_igraph_error(g <- graph_from_graphdb()) expect_snapshot( g <- graph_from_graphdb(nodes = 10, prefix = "not_existing"), error = TRUE diff --git a/tests/testthat/test-hrg.R b/tests/testthat/test-hrg.R index 381d9669ab1..cbb22bc7c27 100644 --- a/tests/testthat/test-hrg.R +++ b/tests/testthat/test-hrg.R @@ -18,14 +18,14 @@ test_that("as.hclust.igraphHRG() works", { }) test_that("sample_hrg() checks its argument", { - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ sample_hrg(make_ring(10)) }) }) test_that("hrg_tree() checks its argument", { - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ hrg_tree(make_ring(10)) }) }) diff --git a/tests/testthat/test-incidence.R b/tests/testthat/test-incidence.R index 3f4b1ba7c43..68b5fb34d03 100644 --- a/tests/testthat/test-incidence.R +++ b/tests/testthat/test-incidence.R @@ -216,18 +216,18 @@ test_that("graph_from_biadjacency_matrix() errors well", { colnames(inc) <- letters[1:5] rownames(inc) <- LETTERS[1:3] - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ (g <- graph_from_biadjacency_matrix(inc, weight = FALSE)) }) - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ (g <- graph_from_biadjacency_matrix(inc, weight = 42)) }) - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ (g <- graph_from_biadjacency_matrix(inc, multiple = TRUE, weighted = TRUE)) }) }) test_that("graph_from_biadjacency_matrix errors for NAs", { A <- matrix(c(1, 1, NA, 1), 2, 2) - expect_snapshot(graph_from_biadjacency_matrix(A), error = TRUE) + expect_snapshot_igraph_error(graph_from_biadjacency_matrix(A)) }) diff --git a/tests/testthat/test-interface.R b/tests/testthat/test-interface.R index 0d331bda8fc..ff287fbb0a3 100644 --- a/tests/testthat/test-interface.R +++ b/tests/testthat/test-interface.R @@ -181,7 +181,7 @@ test_that("ends works", { test_that("get.edge.ids() deprecation", { g <- make_empty_graph(10) expect_snapshot(get.edge.ids(g, 1:2)) - expect_snapshot(get.edge.ids(g, 1:2, multi = TRUE), error = TRUE) + expect_snapshot_igraph_error(get.edge.ids(g, 1:2, multi = TRUE)) }) test_that("get_edge_id() works with data frame", { @@ -202,7 +202,7 @@ test_that("get_edge_id() works with matrices", { test_that("get_edge_id() errors correctly for wrong vp", { g <- make_full_graph(3, directed = FALSE) el_g <- make_empty_graph() - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ get_edge_ids(g, el_g) }) expect_error(get_edge_ids(g, NULL)) @@ -210,7 +210,7 @@ test_that("get_edge_id() errors correctly for wrong vp", { V(g)$name <- letters[1:3] df <- data.frame(from = c("a", "b"), to = c(1, 2)) - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ get_edge_ids(g, df) }) }) diff --git a/tests/testthat/test-iterators.R b/tests/testthat/test-iterators.R index 50790e1623a..a4acfe64974 100644 --- a/tests/testthat/test-iterators.R +++ b/tests/testthat/test-iterators.R @@ -444,6 +444,6 @@ test_that("edge indexes are stored as raw numbers", { test_that("logical indices are not recycled", { # https://github.com/igraph/rigraph/issues/848 g <- make_ring(5) - expect_snapshot(V(g)[c(TRUE, FALSE)], error = TRUE) - expect_snapshot(E(g)[c(TRUE, FALSE)], error = TRUE) + expect_snapshot_igraph_error(V(g)[c(TRUE, FALSE)]) + expect_snapshot_igraph_error(E(g)[c(TRUE, FALSE)]) }) diff --git a/tests/testthat/test-layout.R b/tests/testthat/test-layout.R index e1c6b22727b..725c966c0fc 100644 --- a/tests/testthat/test-layout.R +++ b/tests/testthat/test-layout.R @@ -17,7 +17,7 @@ test_that("layout_with_fr() works", { test_that("layout_with_fr() deprecated argument", { rlang::local_options(lifecycle_verbosity = "warning") g <- make_ring(10) - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ l <- layout_with_fr( g, niter = 50, @@ -212,7 +212,7 @@ test_that("Kamada-Kawai layout generator works", { test_that("layout_with_kk() deprecated arguments", { g <- make_ring(10) - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ l <- layout_with_kk( g, maxiter = 50, @@ -334,7 +334,7 @@ test_that("add_layout_ works", { test_that("layout_randomly() errors well", { g <- make_empty_graph(1) - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ layout_randomly(g, dim = 4) }) }) diff --git a/tests/testthat/test-make.R b/tests/testthat/test-make.R index c925cb88529..e5708c593ba 100644 --- a/tests/testthat/test-make.R +++ b/tests/testthat/test-make.R @@ -292,9 +292,9 @@ test_that("compatibility when arguments are not named", { }) test_that("make_empty_graph gives an error for invalid arguments", { - expect_snapshot(make_empty_graph(NULL), error = TRUE) - expect_snapshot(make_empty_graph("spam"), error = TRUE) - expect_snapshot(make_empty_graph(10, "spam"), error = TRUE) + expect_snapshot_igraph_error(make_empty_graph(NULL)) + expect_snapshot_igraph_error(make_empty_graph("spam")) + expect_snapshot_igraph_error(make_empty_graph(10, "spam")) }) test_that("make_graph_atlas works", { diff --git a/tests/testthat/test-other.R b/tests/testthat/test-other.R index 6ccd5cf2c45..02bf0248d5b 100644 --- a/tests/testthat/test-other.R +++ b/tests/testthat/test-other.R @@ -159,7 +159,7 @@ karate <- structure( ) test_that("VS/ES require explicit conversion", { - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ V(karate) }) }) diff --git a/tests/testthat/test-plot.R b/tests/testthat/test-plot.R index 1467da59594..bbc29010ab8 100644 --- a/tests/testthat/test-plot.R +++ b/tests/testthat/test-plot.R @@ -142,7 +142,7 @@ test_that("Edges stop at outside of rectangle node", { test_that("layout as graph attribute error works", { g <- make_full_graph(10) g$layout <- layout_in_circle(g)[1:5, ] - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ plot(g) }) }) diff --git a/tests/testthat/test-structural-properties.R b/tests/testthat/test-structural-properties.R index 422e615f969..ac8f7936a8d 100644 --- a/tests/testthat/test-structural-properties.R +++ b/tests/testthat/test-structural-properties.R @@ -20,7 +20,7 @@ test_that("dfs() does not pad order", { test_that("dfs() deprecated arguments", { g <- make_star(3) - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ d <- dfs( g, root = 2, @@ -235,7 +235,7 @@ test_that("bfs() works", { test_that("bfs() deprecated arguments", { g <- graph_from_literal(a -+ b -+ c, z -+ a, d) - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ b <- bfs( g, root = 2, diff --git a/tests/testthat/test-versions.R b/tests/testthat/test-versions.R index 2429e227c24..0af0633de57 100644 --- a/tests/testthat/test-versions.R +++ b/tests/testthat/test-versions.R @@ -6,7 +6,7 @@ test_that("we create graphs of the current version", { }) test_that("we can't upgrade from 0.1.1 to 1.5.0, on the fly", { - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ oldsample_0_1_1() }) }) @@ -16,13 +16,13 @@ test_that("we can't upgrade from 0.1.1 to 1.5.0, explicitly", { expect_equal(graph_version(g), ver_0_1_1) - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ upgrade_graph(g) }) }) test_that("we can't upgrade from 0.2 to 1.5.0, on the fly", { - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ oldsample_0_2() }) }) @@ -37,7 +37,7 @@ test_that("we can upgrade from 0.2 to 1.5.0, explicitly", { }) test_that("we can't upgrade from 0.5 to 1.5.0, on the fly", { - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ oldsample_0_5() }) }) @@ -52,7 +52,7 @@ test_that("we can upgrade from 0.5 to 1.5.0, explicitly", { }) test_that("we can't upgrade from 0.6 to 1.5.0, on the fly", { - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ oldsample_0_6() }) }) @@ -95,16 +95,16 @@ test_that("reading of old igraph formats", { local_igraph_options(print.id = FALSE) s <- oldsamples() - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ s[["0.1.1"]] }) - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ s[["0.2"]] }) - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ s[["0.5"]] }) - expect_snapshot(error = TRUE, { + expect_snapshot_igraph_error({ s[["0.6"]] }) expect_snapshot({ From b56ed3bac0a0de6a59415105866b0bbb4cec181a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 24 Jan 2026 10:01:15 +0000 Subject: [PATCH 3/5] fix: add test_error_with_source.o to build and update snapshot Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com> --- src/sources-glue-c.mk | 2 +- src/test_error_with_source.dd | 4 ++++ .../testthat/_problems/test-error-formatting-11.R | 14 ++++++++++++++ tests/testthat/_snaps/error-formatting.md | 2 +- 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 src/test_error_with_source.dd create mode 100644 tests/testthat/_problems/test-error-formatting-11.R diff --git a/src/sources-glue-c.mk b/src/sources-glue-c.mk index a0ca36b78c0..3508954fced 100644 --- a/src/sources-glue-c.mk +++ b/src/sources-glue-c.mk @@ -1 +1 @@ -GLUE_C_SOURCES=rcallback.o rinterface.o rinterface_extra.o rrandom.o uuid.o +GLUE_C_SOURCES=rcallback.o rinterface.o rinterface_extra.o rrandom.o test_error_with_source.o uuid.o diff --git a/src/test_error_with_source.dd b/src/test_error_with_source.dd new file mode 100644 index 00000000000..3eea9c3527c --- /dev/null +++ b/src/test_error_with_source.dd @@ -0,0 +1,4 @@ +# Generated by deps.mk, do not edit by hand and do not add dependencies to system headers +test_error_with_source.o: \ + rinterface.h \ + test_error_with_source.c \ diff --git a/tests/testthat/_problems/test-error-formatting-11.R b/tests/testthat/_problems/test-error-formatting-11.R new file mode 100644 index 00000000000..dcf2fa7f4eb --- /dev/null +++ b/tests/testthat/_problems/test-error-formatting-11.R @@ -0,0 +1,14 @@ +# Extracted from test-error-formatting.R:11 + +# setup ------------------------------------------------------------------------ +library(testthat) +test_env <- simulate_test_env(package = "igraph", path = "..") +attach(test_env, warn.conflicts = FALSE) + +# test ------------------------------------------------------------------------- +expect_snapshot( + error = TRUE, + { + test_error_with_source() + } + ) diff --git a/tests/testthat/_snaps/error-formatting.md b/tests/testthat/_snaps/error-formatting.md index fca0e7ab3a1..66512692f0e 100644 --- a/tests/testthat/_snaps/error-formatting.md +++ b/tests/testthat/_snaps/error-formatting.md @@ -5,5 +5,5 @@ Condition Error in `test_error_with_source()`: ! Test error message for verifying source location formatting. Invalid value - Source: rinterface_extra.c:7766 + Source: test_error_with_source.c:31 From e42ebce6a08a6a31685ba3d7b372a9d1c5f07a7d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 24 Jan 2026 10:01:23 +0000 Subject: [PATCH 4/5] chore: remove test problems file Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com> --- .../testthat/_problems/test-error-formatting-11.R | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 tests/testthat/_problems/test-error-formatting-11.R diff --git a/tests/testthat/_problems/test-error-formatting-11.R b/tests/testthat/_problems/test-error-formatting-11.R deleted file mode 100644 index dcf2fa7f4eb..00000000000 --- a/tests/testthat/_problems/test-error-formatting-11.R +++ /dev/null @@ -1,14 +0,0 @@ -# Extracted from test-error-formatting.R:11 - -# setup ------------------------------------------------------------------------ -library(testthat) -test_env <- simulate_test_env(package = "igraph", path = "..") -attach(test_env, warn.conflicts = FALSE) - -# test ------------------------------------------------------------------------- -expect_snapshot( - error = TRUE, - { - test_error_with_source() - } - ) From 4a4a59993816c218fbbeb4c0a2344c7b07216301 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 24 Jan 2026 10:18:19 +0000 Subject: [PATCH 5/5] fix: transform remaining multi-line expect_snapshot with error = TRUE Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com> --- tests/testthat/test-conversion.R | 10 ++++------ tests/testthat/test-flow.R | 20 ++++++++------------ tests/testthat/test-foreign.R | 10 ++++------ tests/testthat/test-make.R | 5 ++--- tests/testthat/test-minimum.spanning.tree.R | 5 ++--- tests/testthat/test-other.R | 5 ++--- tests/testthat/test-utils-assert-args.R | 5 ++--- 7 files changed, 24 insertions(+), 36 deletions(-) diff --git a/tests/testthat/test-conversion.R b/tests/testthat/test-conversion.R index 367e4d7d068..65a2858fc67 100644 --- a/tests/testthat/test-conversion.R +++ b/tests/testthat/test-conversion.R @@ -197,15 +197,13 @@ test_that("as_adjacency_matrix() works -- dense", { test_that("as_adjacency_matrix() errors well -- dense", { g <- make_graph(c(1, 2, 2, 1, 2, 2, 3, 3, 3, 3, 3, 4, 4, 2, 4, 2, 4, 2), directed = TRUE) - expect_snapshot( - as_adjacency_matrix(g, attr = "bla", sparse = FALSE), - error = TRUE + expect_snapshot_igraph_error( + as_adjacency_matrix(g, attr = "bla", sparse = FALSE) ) E(g)$bla <- letters[1:ecount(g)] - expect_snapshot( - as_adjacency_matrix(g, attr = "bla", sparse = FALSE), - error = TRUE + expect_snapshot_igraph_error( + as_adjacency_matrix(g, attr = "bla", sparse = FALSE) ) }) diff --git a/tests/testthat/test-flow.R b/tests/testthat/test-flow.R index c620a0900da..d9b9eec71d5 100644 --- a/tests/testthat/test-flow.R +++ b/tests/testthat/test-flow.R @@ -100,13 +100,11 @@ test_that("st_cuts errors work", { expect_snapshot_igraph_error(st_cuts(g_path, source = "a", target = NULL)) expect_snapshot_igraph_error(st_cuts(g_path, source = NULL, target = "a")) - expect_snapshot( - st_min_cuts(g_path, source = "a", target = NULL), - error = TRUE + expect_snapshot_igraph_error( + st_min_cuts(g_path, source = "a", target = NULL) ) - expect_snapshot( - st_min_cuts(g_path, source = NULL, target = "a"), - error = TRUE + expect_snapshot_igraph_error( + st_min_cuts(g_path, source = NULL, target = "a") ) }) @@ -192,13 +190,11 @@ test_that("edge_disjoint_paths works", { test_that("edge_disjoint_paths error works", { g_path <- make_ring(5, circular = FALSE) - expect_snapshot( - edge_disjoint_paths(g_path, source = 1, target = NULL), - error = TRUE + expect_snapshot_igraph_error( + edge_disjoint_paths(g_path, source = 1, target = NULL) ) - expect_snapshot( - edge_disjoint_paths(g_path, source = NULL, target = 1), - error = TRUE + expect_snapshot_igraph_error( + edge_disjoint_paths(g_path, source = NULL, target = 1) ) }) diff --git a/tests/testthat/test-foreign.R b/tests/testthat/test-foreign.R index 54b2b90c3b3..3a26f55e8b7 100644 --- a/tests/testthat/test-foreign.R +++ b/tests/testthat/test-foreign.R @@ -73,12 +73,10 @@ test_that("graph_from_graphdb works", { expect_snapshot(g <- graph_from_graphdb(nodes = 1000)) expect_snapshot_igraph_error(g <- graph_from_graphdb()) - expect_snapshot( - g <- graph_from_graphdb(nodes = 10, prefix = "not_existing"), - error = TRUE + expect_snapshot_igraph_error( + g <- graph_from_graphdb(nodes = 10, prefix = "not_existing") ) - expect_snapshot( - g <- graph_from_graphdb(nodes = 10, type = "not_existing"), - error = TRUE + expect_snapshot_igraph_error( + g <- graph_from_graphdb(nodes = 10, type = "not_existing") ) }) diff --git a/tests/testthat/test-make.R b/tests/testthat/test-make.R index e5708c593ba..ca8b9c658c8 100644 --- a/tests/testthat/test-make.R +++ b/tests/testthat/test-make.R @@ -42,7 +42,7 @@ test_that("sample_, graph_ also work", { test_that("error messages are proper", { rlang::local_options(lifecycle_verbosity = "quiet") - expect_snapshot( + expect_snapshot_igraph_error( { make_() make_(1:10) @@ -54,8 +54,7 @@ test_that("error messages are proper", { sample_() sample_(1:10) sample_(directed_graph(), directed_graph()) - }, - error = TRUE + } ) }) diff --git a/tests/testthat/test-minimum.spanning.tree.R b/tests/testthat/test-minimum.spanning.tree.R index c6422d7a385..3fddd46813b 100644 --- a/tests/testthat/test-minimum.spanning.tree.R +++ b/tests/testthat/test-minimum.spanning.tree.R @@ -34,8 +34,7 @@ test_that("mst works", { test_that("mst error works", { g <- sample_gnp(10, 0.4) - expect_snapshot( - mst(g, algorithm = "undefined"), - error = TRUE + expect_snapshot_igraph_error( + mst(g, algorithm = "undefined") ) }) diff --git a/tests/testthat/test-other.R b/tests/testthat/test-other.R index 02bf0248d5b..063ab5a13e9 100644 --- a/tests/testthat/test-other.R +++ b/tests/testthat/test-other.R @@ -29,9 +29,8 @@ test_that("can create graphs when igraph is not attached", { test_that("running_mean works", { expect_equal(running_mean(1:10, 2), 2:10 - 0.5) - expect_snapshot( - running_mean(1:3, 4), - error = TRUE + expect_snapshot_igraph_error( + running_mean(1:3, 4) ) }) diff --git a/tests/testthat/test-utils-assert-args.R b/tests/testthat/test-utils-assert-args.R index a2984d3a94b..d2b2654a3b2 100644 --- a/tests/testthat/test-utils-assert-args.R +++ b/tests/testthat/test-utils-assert-args.R @@ -7,8 +7,7 @@ test_that("ensure_igraph() works", { }) test_that("igraph_match_arg() works", { - expect_snapshot( - cluster_leiden(make_graph("Zachary"), objective_function = "something"), - error = TRUE + expect_snapshot_igraph_error( + cluster_leiden(make_graph("Zachary"), objective_function = "something") ) })