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..7b3609ceb1e 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -44,21 +44,28 @@ 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 + # 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 +} + 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, + ... + )) +} + +expect_snapshot_igraph <- function(x, ...) { + inject(expect_snapshot( + {{ x }}, + transform = scrub_igraph_file_paths, ... )) } diff --git a/tests/testthat/test-aaa-auto.R b/tests/testthat/test-aaa-auto.R index 50f55a7068a..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 )) @@ -11044,7 +11053,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", {