From ca9ff03774644d793adaf1d188823b5106eac1e6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 24 Jan 2026 17:21:34 +0000 Subject: [PATCH 1/4] fix: scrub file paths in error/warning snapshots and fix spacing Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com> --- tests/testthat/_snaps/aaa-auto.md | 8 ++++---- tests/testthat/_snaps/games.md | 4 ++-- tests/testthat/helper.R | 22 ++++++++++++++++------ tests/testthat/test-aaa-auto.R | 2 +- tests/testthat/test-games.R | 20 ++++++-------------- 5 files changed, 29 insertions(+), 27 deletions(-) diff --git a/tests/testthat/_snaps/aaa-auto.md b/tests/testthat/_snaps/aaa-auto.md index c37d623cd2b..083286d431d 100644 --- a/tests/testthat/_snaps/aaa-auto.md +++ b/tests/testthat/_snaps/aaa-auto.md @@ -5804,7 +5804,7 @@ hrg_sample_impl(hrg = NULL) Condition Error in `hrg_sample_impl()`: - ! At : : Assertion failed: n >= 0. This is an unexpected igraph error; please report this as a bug, along with the steps to reproduce it. + ! At :: Assertion failed: n >= 0. This is an unexpected igraph error; please report this as a bug, along with the steps to reproduce it. Please restart your R session to avoid crashes or other surprising behavior. # hrg_sample_many_impl basic @@ -5835,7 +5835,7 @@ hrg_sample_many_impl(hrg = NULL, num_samples = 2) Condition Error in `hrg_sample_many_impl()`: - ! At : : Assertion failed: n >= 0. This is an unexpected igraph error; please report this as a bug, along with the steps to reproduce it. + ! At :: Assertion failed: n >= 0. This is an unexpected igraph error; please report this as a bug, along with the steps to reproduce it. Please restart your R session to avoid crashes or other surprising behavior. # hrg_game_impl basic @@ -5857,7 +5857,7 @@ hrg_game_impl(hrg = NULL) Condition Error in `hrg_game_impl()`: - ! At : : Assertion failed: n >= 0. This is an unexpected igraph error; please report this as a bug, along with the steps to reproduce it. + ! At :: Assertion failed: n >= 0. This is an unexpected igraph error; please report this as a bug, along with the steps to reproduce it. Please restart your R session to avoid crashes or other surprising behavior. # hrg_consensus_impl errors @@ -11198,7 +11198,7 @@ Condition Warning in `connect_neighborhood_impl()`: Order smaller than two, graph will be unchanged. - Source: operators/connect_neighborhood.c:85 + Source: : Output IGRAPH U--- 5 5 -- Ring graph + attr: name (g/c), mutual (g/l), circular (g/l) diff --git a/tests/testthat/_snaps/games.md b/tests/testthat/_snaps/games.md index 15522aa0df9..8b30cb21907 100644 --- a/tests/testthat/_snaps/games.md +++ b/tests/testthat/_snaps/games.md @@ -5,7 +5,7 @@ Condition Error in `sample_degseq()`: ! Cannot make a connected graph from the given degree sequence. Invalid value - Source: games/degree_sequence_vl/gengraph_mr-connected.cpp: + Source: : # sample_degseq() works -- Power-law degree error @@ -14,5 +14,5 @@ Condition Error in `sample_degseq()`: ! Cannot realize the given degree sequence as an undirected, simple graph. Invalid value - Source: games/degree_sequence_vl/gengraph_mr-connected.cpp: + Source: : diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index 91c6660ea60..11d83a583c6 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -51,12 +51,22 @@ expect_snapshot_igraph_error <- function(x, ...) { transform = function(y) { # Scrub file name and line number from error/warning messages # Handles "Source: filename:linenumber" and "At path/to/file:line :" patterns - y <- gsub( - "Source: [^:]+:(\\d+|xx|)", - "Source: :", - y - ) - y <- gsub("At [^:]+:(\\d+|xx) :", "At : :", y) + y <- gsub("Source: [^:]+:(\\d+|xx|)", "Source: :", y) + y <- gsub("At [^:]+:(\\d+|xx) ?:", "At ::", y) + y + }, + ... + )) +} + +expect_snapshot_igraph <- function(x, ...) { + inject(expect_snapshot( + {{ x }}, + transform = function(y) { + # Scrub file name and line number from error/warning messages + # Handles "Source: filename:linenumber" and "At path/to/file:line :" patterns + y <- gsub("Source: [^:]+:(\\d+|xx|)", "Source: :", y) + y <- gsub("At [^:]+:(\\d+|xx) ?:", "At ::", y) y }, ... diff --git a/tests/testthat/test-aaa-auto.R b/tests/testthat/test-aaa-auto.R index 50f55a7068a..7004558d28a 100644 --- a/tests/testthat/test-aaa-auto.R +++ b/tests/testthat/test-aaa-auto.R @@ -11044,7 +11044,7 @@ test_that("connect_neighborhood_impl basic", { withr::local_seed(20250909) local_igraph_options(print.id = FALSE) g <- make_ring(5) - expect_snapshot(connect_neighborhood_impl( + expect_snapshot_igraph(connect_neighborhood_impl( graph = g, order = 1, mode = c("all", "out", "in") diff --git a/tests/testthat/test-games.R b/tests/testthat/test-games.R index 0c786e1d23a..46b4c1e7bb5 100644 --- a/tests/testthat/test-games.R +++ b/tests/testthat/test-games.R @@ -71,13 +71,9 @@ test_that("sample_degseq() works -- exponential degree error", { replace = TRUE, prob = exp(-0.5 * (1:100)) ) - expect_snapshot( - { - sample_degseq(exponential_degrees, method = "vl") - }, - error = TRUE, - transform = function(x) sub("\\:[0-9]+", ":", x) - ) + expect_snapshot_igraph_error({ + sample_degseq(exponential_degrees, method = "vl") + }) }) test_that("sample_degseq() works -- Power-law degree ok", { @@ -91,13 +87,9 @@ test_that("sample_degseq() works -- Power-law degree error", { withr::local_seed(7) powerlaw_degrees <- sample(1:100, 100, replace = TRUE, prob = (1:100)^-2) - expect_snapshot( - { - sample_degseq(powerlaw_degrees, method = "vl") - }, - error = TRUE, - transform = function(x) sub("\\:[0-9]+", ":", x) - ) + expect_snapshot_igraph_error({ + sample_degseq(powerlaw_degrees, method = "vl") + }) }) test_that("sample_degseq() works -- fast.heur.simple", { From 71d9fcf61d6fc3bb2d2c89578b076524dd261b8b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 24 Jan 2026 17:23:41 +0000 Subject: [PATCH 2/4] refactor: extract scrub_igraph_file_paths helper to reduce duplication Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com> --- tests/testthat/helper.R | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index 11d83a583c6..01c0ab5a4fc 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -44,17 +44,19 @@ expect_not_identical_graphs <- function(g1, g2, ...) { expect_false(identical_graphs(g1, g2, ...)) } +scrub_igraph_file_paths <- function(y) { + # Scrub file name and line number from error/warning messages + # Handles "Source: filename:linenumber" and "At path/to/file:line :" patterns + y <- gsub("Source: [^:]+:(\\d+|xx|)", "Source: :", y) + y <- gsub("At [^:]+:(\\d+|xx) ?:", "At ::", y) + y +} + expect_snapshot_igraph_error <- function(x, ...) { inject(expect_snapshot( {{ x }}, error = TRUE, - transform = function(y) { - # Scrub file name and line number from error/warning messages - # Handles "Source: filename:linenumber" and "At path/to/file:line :" patterns - y <- gsub("Source: [^:]+:(\\d+|xx|)", "Source: :", y) - y <- gsub("At [^:]+:(\\d+|xx) ?:", "At ::", y) - y - }, + transform = scrub_igraph_file_paths, ... )) } @@ -62,13 +64,7 @@ expect_snapshot_igraph_error <- function(x, ...) { expect_snapshot_igraph <- function(x, ...) { inject(expect_snapshot( {{ x }}, - transform = function(y) { - # Scrub file name and line number from error/warning messages - # Handles "Source: filename:linenumber" and "At path/to/file:line :" patterns - y <- gsub("Source: [^:]+:(\\d+|xx|)", "Source: :", y) - y <- gsub("At [^:]+:(\\d+|xx) ?:", "At ::", y) - y - }, + transform = scrub_igraph_file_paths, ... )) } From 79375644e335cc5c58223ef001b1c6907d1fb0c9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 24 Jan 2026 17:24:31 +0000 Subject: [PATCH 3/4] docs: clarify optional space in regex pattern comment Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com> --- tests/testthat/helper.R | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index 01c0ab5a4fc..7b3609ceb1e 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -47,6 +47,7 @@ expect_not_identical_graphs <- function(g1, g2, ...) { scrub_igraph_file_paths <- function(y) { # Scrub file name and line number from error/warning messages # Handles "Source: filename:linenumber" and "At path/to/file:line :" patterns + # The "At" pattern may have an optional space before the final colon y <- gsub("Source: [^:]+:(\\d+|xx|)", "Source: :", y) y <- gsub("At [^:]+:(\\d+|xx) ?:", "At ::", y) y From 280ce4355dbb3fe8e704d969bfe02e086c836802 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 24 Jan 2026 17:37:47 +0000 Subject: [PATCH 4/4] docs: add FIXME comments for HRG error tests with assertion failures Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com> --- tests/testthat/test-aaa-auto.R | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/testthat/test-aaa-auto.R b/tests/testthat/test-aaa-auto.R index 7004558d28a..2f060d488c7 100644 --- a/tests/testthat/test-aaa-auto.R +++ b/tests/testthat/test-aaa-auto.R @@ -6733,6 +6733,9 @@ test_that("hrg_sample_impl errors", { skip_if(Sys.getenv("R_SANITIZER") == "true") withr::local_seed(20250909) local_igraph_options(print.id = FALSE) + # FIXME: This test triggers an assertion failure in the C code when passing + # NULL/empty HRG. The C code should validate input and return a proper error + # message instead of an assertion failure. expect_snapshot_igraph_error(hrg_sample_impl( hrg = NULL )) @@ -6763,6 +6766,9 @@ test_that("hrg_sample_many_impl errors", { skip_if(Sys.getenv("R_SANITIZER") == "true") withr::local_seed(20250909) local_igraph_options(print.id = FALSE) + # FIXME: This test triggers an assertion failure in the C code when passing + # NULL/empty HRG. The C code should validate input and return a proper error + # message instead of an assertion failure. expect_snapshot_igraph_error(hrg_sample_many_impl( hrg = NULL, num_samples = 2 @@ -6792,6 +6798,9 @@ test_that("hrg_game_impl errors", { skip_if(Sys.getenv("R_SANITIZER") == "true") withr::local_seed(20250909) local_igraph_options(print.id = FALSE) + # FIXME: This test triggers an assertion failure in the C code when passing + # NULL/empty HRG. The C code should validate input and return a proper error + # message instead of an assertion failure. expect_snapshot_igraph_error(hrg_game_impl( hrg = NULL ))