diff --git a/.gitignore b/.gitignore index 44bea8a20c8..9a958f64733 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ cran /.vscode/launch.json /Rplots.pdf /_codeql_detected_source_root +tests/testthat/_problems/ diff --git a/R/utils.R b/R/utils.R index b9c51b8bbbc..d172590cc0d 100644 --- a/R/utils.R +++ b/R/utils.R @@ -94,3 +94,23 @@ modify_list <- function(x, y) { utils::modifyList(x, y) } + +#' Test function to verify error formatting with file and line information +#' +#' @description +#' This is a test function that throws an error from C code with file and line +#' information. +#' The error message should include the source file and line number where the +#' error occurred. +#' +#' @return This function never returns; it always throws an error. +#' @keywords internal +#' @noRd +#' @examples +#' \dontrun{ +#' # This will throw an error with source location information +#' test_error_with_source() +#' } +test_error_with_source <- function() { + .Call(Rx_igraph_test_error_with_source) +} diff --git a/src/cpp11.cpp b/src/cpp11.cpp index 686abff0506..40de1f0bef3 100644 --- a/src/cpp11.cpp +++ b/src/cpp11.cpp @@ -598,6 +598,7 @@ extern SEXP Rx_igraph_st_vertex_connectivity(SEXP, SEXP, SEXP); extern SEXP Rx_igraph_star(SEXP, SEXP, SEXP); extern SEXP Rx_igraph_subcomponent(SEXP, SEXP, SEXP); extern SEXP Rx_igraph_subisomorphic_lad(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP Rx_igraph_test_error_with_source(void); extern SEXP Rx_igraph_transitivity_local_undirected_all(SEXP, SEXP); extern SEXP Rx_igraph_union(SEXP, SEXP); extern SEXP Rx_igraph_vcount(SEXP); @@ -1192,6 +1193,7 @@ static const R_CallMethodDef CallEntries[] = { {"Rx_igraph_star", (DL_FUNC) &Rx_igraph_star, 3}, {"Rx_igraph_subcomponent", (DL_FUNC) &Rx_igraph_subcomponent, 3}, {"Rx_igraph_subisomorphic_lad", (DL_FUNC) &Rx_igraph_subisomorphic_lad, 7}, + {"Rx_igraph_test_error_with_source", (DL_FUNC) &Rx_igraph_test_error_with_source, 0}, {"Rx_igraph_transitivity_local_undirected_all", (DL_FUNC) &Rx_igraph_transitivity_local_undirected_all, 2}, {"Rx_igraph_union", (DL_FUNC) &Rx_igraph_union, 2}, {"Rx_igraph_vcount", (DL_FUNC) &Rx_igraph_vcount, 1}, diff --git a/src/rinterface_extra.c b/src/rinterface_extra.c index ca1dc00f642..9e8c68c9332 100644 --- a/src/rinterface_extra.c +++ b/src/rinterface_extra.c @@ -2315,6 +2315,18 @@ static inline const char* maybe_add_punctuation(const char* msg, const char* pun return is_punctuated(msg) ? "" : punctuation; } +/* Strip vendor/cigraph/src/ prefix from file path. This prefix depends on the + * build procedure, namely on the directory that the compiler is invoked from. */ +static inline const char* simplify_file_path(const char *file) { + const char prefix[] = "vendor/cigraph/src/"; + const size_t prefix_len = sizeof(prefix) - 1; + + if (strncmp(file, prefix, prefix_len) == 0) { + return file + prefix_len; + } + return file; +} + void Rx_igraph_fatal_handler(const char *reason, const char *file, int line) { #ifdef IGRAPH_SANITIZER_AVAILABLE __sanitizer_print_stack_trace(); @@ -2336,10 +2348,12 @@ void Rx_igraph_error_handler(const char *reason, const char *file, * IGRAPH_FINALLY_FREE() can then clean it up. */ if (Rx_igraph_errors_count == 0 || !Rx_igraph_in_r_check) { + const char* simplified_path = simplify_file_path(file); snprintf(Rx_igraph_error_reason, sizeof(Rx_igraph_error_reason), - "At %s:%i : %s%s %s", file, line, reason, - maybe_add_punctuation(reason, ","), - igraph_strerror(igraph_errno)); + "%s%s %s\nSource: %s:%i", reason, + maybe_add_punctuation(reason, "."), + igraph_strerror(igraph_errno), + simplified_path, line); Rx_igraph_error_reason[sizeof(Rx_igraph_error_reason) - 1] = 0; // FIXME: This is a hack, we should replace all memory allocations in the @@ -2356,8 +2370,10 @@ void Rx_igraph_error_handler(const char *reason, const char *file, void Rx_igraph_warning_handler(const char *reason, const char *file, int line) { if (Rx_igraph_warnings_count == 0) { + const char* simplified_path = simplify_file_path(file); snprintf(Rx_igraph_warning_reason, sizeof(Rx_igraph_warning_reason), - "At %s:%i : %s%s", file, line, reason, maybe_add_punctuation(reason, ".")); + "%s%s\nSource: %s:%i", reason, maybe_add_punctuation(reason, "."), + simplified_path, line); Rx_igraph_warning_reason[sizeof(Rx_igraph_warning_reason) - 1] = 0; } Rx_igraph_warnings_count++; 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.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/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/_snaps/aaa-auto.md b/tests/testthat/_snaps/aaa-auto.md index 92d64d9dcbc..c37d623cd2b 100644 --- a/tests/testthat/_snaps/aaa-auto.md +++ b/tests/testthat/_snaps/aaa-auto.md @@ -20,7 +20,8 @@ empty_impl(n = -1) Condition Error in `empty_impl()`: - ! At vendor/cigraph/src/graph/type_indexededgelist.c:xx : Number of vertices must not be negative. Invalid value + ! Number of vertices must not be negative. Invalid value + Source: : # add_edges_impl basic @@ -155,7 +156,8 @@ wheel_impl(n = -1) Condition Error in `wheel_impl()`: - ! At vendor/cigraph/src/constructors/regular.c:xx : Invalid number of vertices. Invalid vertex ID + ! Invalid number of vertices. Invalid vertex ID + Source: : # hypercube_impl basic @@ -181,7 +183,8 @@ hypercube_impl(n = 10000) Condition Error in `hypercube_impl()`: - ! At vendor/cigraph/src/constructors/regular.c:xx : The requested hypercube graph dimension (10000) is too high. It must be no greater than 57. Invalid value + ! The requested hypercube graph dimension (10000) is too high. It must be no greater than 57. Invalid value + Source: : # square_lattice_impl basic @@ -208,7 +211,8 @@ square_lattice_impl(dimvector = -1) Condition Error in `square_lattice_impl()`: - ! At vendor/cigraph/src/constructors/regular.c:xx : Invalid dimension vector. Invalid value + ! Invalid dimension vector. Invalid value + Source: : # triangular_lattice_impl basic @@ -234,7 +238,8 @@ triangular_lattice_impl(dimvector = -1) Condition Error in `triangular_lattice_impl()`: - ! At vendor/cigraph/src/constructors/lattices.c:xx : Invalid dimension vector. Invalid value + ! Invalid dimension vector. Invalid value + Source: : # path_graph_impl basic @@ -260,7 +265,8 @@ path_graph_impl(n = -1) Condition Error in `path_graph_impl()`: - ! At vendor/cigraph/src/constructors/regular.c:xx : The number of vertices must be non-negative, got -1. Invalid value + ! The number of vertices must be non-negative, got -1. Invalid value + Source: : # cycle_graph_impl basic @@ -286,7 +292,8 @@ cycle_graph_impl(n = -1) Condition Error in `cycle_graph_impl()`: - ! At vendor/cigraph/src/constructors/regular.c:xx : The number of vertices must be non-negative, got -1. Invalid value + ! The number of vertices must be non-negative, got -1. Invalid value + Source: : # symmetric_tree_impl basic @@ -312,7 +319,8 @@ symmetric_tree_impl(branches = -1) Condition Error in `symmetric_tree_impl()`: - ! At vendor/cigraph/src/constructors/regular.c:xx : The number of branches must be positive at each level. Invalid value + ! The number of branches must be positive at each level. Invalid value + Source: : # regular_tree_impl basic @@ -339,7 +347,8 @@ regular_tree_impl(h = -1) Condition Error in `regular_tree_impl()`: - ! At vendor/cigraph/src/constructors/regular.c:xx : Height of regular tree must be positive, got -1. Invalid value + ! Height of regular tree must be positive, got -1. Invalid value + Source: : # full_citation_impl basic @@ -365,7 +374,8 @@ full_citation_impl(n = -1) Condition Error in `full_citation_impl()`: - ! At vendor/cigraph/src/constructors/full.c:xx : Invalid number of vertices. Invalid value + ! Invalid number of vertices. Invalid value + Source: : # atlas_impl basic @@ -390,7 +400,8 @@ atlas_impl(number = -1) Condition Error in `atlas_impl()`: - ! At vendor/cigraph/src/constructors/atlas.c:xx : No such graph in atlas. The graph index must be less than 1253. Invalid value + ! No such graph in atlas. The graph index must be less than 1253. Invalid value + Source: : # extended_chordal_ring_impl basic @@ -416,7 +427,8 @@ extended_chordal_ring_impl(nodes = -1, W = matrix(c(1, 2))) Condition Error in `extended_chordal_ring_impl()`: - ! At vendor/cigraph/src/constructors/regular.c:xx : An extended chordal ring has at least 3 nodes. Invalid value + ! An extended chordal ring has at least 3 nodes. Invalid value + Source: : # graph_power_impl basic @@ -477,7 +489,8 @@ de_bruijn_impl(m = -1, n = 3) Condition Error in `de_bruijn_impl()`: - ! At vendor/cigraph/src/constructors/de_bruijn.c:xx : `m' and `n' should be non-negative in a de Bruijn graph, Invalid value + ! `m' and `n' should be non-negative in a de Bruijn graph. Invalid value + Source: : # kautz_impl basic @@ -498,7 +511,8 @@ kautz_impl(m = -1, n = 3) Condition Error in `kautz_impl()`: - ! At vendor/cigraph/src/constructors/kautz.c:xx : `m' and `n' should be non-negative in a Kautz graph, Invalid value + ! `m' and `n' should be non-negative in a Kautz graph. Invalid value + Source: : # lcf_vector_impl basic @@ -517,7 +531,8 @@ lcf_vector_impl(n = -1, shifts = c(3, -3, 4), repeats = 2) Condition Error in `lcf_vector_impl()`: - ! At vendor/cigraph/src/graph/type_indexededgelist.c:xx : Number of vertices must not be negative. Invalid value + ! Number of vertices must not be negative. Invalid value + Source: : # mycielski_graph_impl basic @@ -534,7 +549,8 @@ mycielski_graph_impl(k = -1) Condition Error in `mycielski_graph_impl()`: - ! At vendor/cigraph/src/constructors/mycielskian.c:xx : The Mycielski graph order must not be negative. Invalid value + ! The Mycielski graph order must not be negative. Invalid value + Source: : # adjlist_impl basic @@ -551,7 +567,8 @@ adjlist_impl(adjlist = -1, mode = "out") Condition Error in `adjlist_impl()`: - ! At vendor/cigraph/src/constructors/basic_constructors.c:xx : Invalid (negative or too large) vertex ID. Invalid vertex ID + ! Invalid (negative or too large) vertex ID. Invalid vertex ID + Source: : # full_bipartite_impl basic @@ -587,7 +604,8 @@ full_bipartite_impl(n1 = -1, n2 = 3) Condition Error in `full_bipartite_impl()`: - ! At vendor/cigraph/src/misc/bipartite.c:xx : Invalid number of vertices for bipartite graph. Invalid value + ! Invalid number of vertices for bipartite graph. Invalid value + Source: : # full_multipartite_impl basic @@ -643,7 +661,8 @@ full_multipartite_impl(n = -1) Condition Error in `full_multipartite_impl()`: - ! At vendor/cigraph/src/constructors/full.c:xx : Number of vertices must not be negative in any partition. Invalid value + ! Number of vertices must not be negative in any partition. Invalid value + Source: : # realize_degree_sequence_impl basic @@ -674,7 +693,8 @@ realize_degree_sequence_impl(out_deg = -1) Condition Error in `realize_degree_sequence_impl()`: - ! At vendor/cigraph/src/misc/degree_sequence.cpp:xx : The sum of degrees must be even for an undirected graph. Invalid value + ! The sum of degrees must be even for an undirected graph. Invalid value + Source: : # realize_bipartite_degree_sequence_impl basic @@ -705,7 +725,8 @@ realize_bipartite_degree_sequence_impl(degrees1 = -1, degrees2 = c(2, 2)) Condition Error in `realize_bipartite_degree_sequence_impl()`: - ! At vendor/cigraph/src/misc/degree_sequence.cpp:xx : The given bidegree sequence cannot be realized as a bipartite simple graph. Invalid value + ! The given bidegree sequence cannot be realized as a bipartite simple graph. Invalid value + Source: : # circulant_impl basic @@ -733,7 +754,8 @@ circulant_impl(n = -1, shifts = c(1, 2)) Condition Error in `circulant_impl()`: - ! At vendor/cigraph/src/constructors/circulant.c:xx : Number of nodes = -1 must be non-negative. Invalid value + ! Number of nodes = -1 must be non-negative. Invalid value + Source: : # generalized_petersen_impl basic @@ -751,7 +773,8 @@ generalized_petersen_impl(n = -1, k = 2) Condition Error in `generalized_petersen_impl()`: - ! At vendor/cigraph/src/constructors/generalized_petersen.c:xx : n = -1 must be at least 3. Invalid value + ! n = -1 must be at least 3. Invalid value + Source: : # turan_impl basic @@ -782,7 +805,8 @@ turan_impl(n = -1, r = 2) Condition Error in `turan_impl()`: - ! At vendor/cigraph/src/constructors/full.c:xx : Number of vertices must not be negative, got -1. Invalid value + ! Number of vertices must not be negative, got -1. Invalid value + Source: : # erdos_renyi_game_gnp_impl basic @@ -808,7 +832,8 @@ erdos_renyi_game_gnp_impl(n = -1, p = 0.5) Condition Error in `erdos_renyi_game_gnp_impl()`: - ! At vendor/cigraph/src/games/erdos_renyi.c:xx : Invalid number of vertices. Invalid value + ! Invalid number of vertices. Invalid value + Source: : # erdos_renyi_game_gnm_impl basic @@ -834,7 +859,8 @@ erdos_renyi_game_gnm_impl(n = -1, m = 3) Condition Error in `erdos_renyi_game_gnm_impl()`: - ! At vendor/cigraph/src/games/erdos_renyi.c:xx : Invalid number of vertices. Invalid value + ! Invalid number of vertices. Invalid value + Source: : # growing_random_game_impl basic @@ -872,7 +898,8 @@ growing_random_game_impl(n = -1, m = 2) Condition Error in `growing_random_game_impl()`: - ! At vendor/cigraph/src/games/growing_random.c:xx : Invalid number of vertices. Invalid value + ! Invalid number of vertices. Invalid value + Source: : # preference_game_impl basic @@ -896,7 +923,8 @@ fixed_sizes = FALSE, pref_matrix = matrix(c(0.5, 0.5, 0.5, 0.5), 2, 2)) Condition Error in `preference_game_impl()`: - ! At vendor/cigraph/src/games/preference.c:xx : The number of vertices must be non-negative. Invalid value + ! The number of vertices must be non-negative. Invalid value + Source: : # asymmetric_preference_game_impl basic @@ -925,7 +953,8 @@ c(0.5, 0.5, 0.5, 0.5), 2, 2)) Condition Error in `asymmetric_preference_game_impl()`: - ! At vendor/cigraph/src/games/preference.c:xx : The number of vertices must not be negative. Invalid value + ! The number of vertices must not be negative. Invalid value + Source: : # rewire_edges_impl basic @@ -988,7 +1017,8 @@ forest_fire_game_impl(nodes = -1, fw_prob = 0.5) Condition Error in `forest_fire_game_impl()`: - ! At vendor/cigraph/src/games/forestfire.c:xx : Insufficient memory for forest fire model. Out of memory + ! Insufficient memory for forest fire model. Out of memory + Source: : # simple_interconnected_islands_game_impl basic @@ -1009,7 +1039,8 @@ islands_pin = 0.5, n_inter = 1) Condition Error in `simple_interconnected_islands_game_impl()`: - ! At vendor/cigraph/src/games/islands.c:xx : Number of islands cannot be negative, got -1. Invalid value + ! Number of islands cannot be negative, got -1. Invalid value + Source: : # chung_lu_game_impl basic @@ -1038,7 +1069,8 @@ chung_lu_game_impl(out_weights = -1) Condition Error in `chung_lu_game_impl()`: - ! At vendor/cigraph/src/games/chung_lu.c:xx : Vertex weights must not be negative in Chung-Lu model, got -1. Invalid value + ! Vertex weights must not be negative in Chung-Lu model, got -1. Invalid value + Source: : # static_fitness_game_impl basic @@ -1067,7 +1099,8 @@ static_fitness_game_impl(no_of_edges = -1, fitness_out = c(1, 2, 3)) Condition Error in `static_fitness_game_impl()`: - ! At vendor/cigraph/src/games/static_fitness.c:xx : Number of edges cannot be negative, got -1. Invalid value + ! Number of edges cannot be negative, got -1. Invalid value + Source: : # static_power_law_game_impl basic @@ -1098,7 +1131,8 @@ static_power_law_game_impl(no_of_nodes = -1, no_of_edges = 4, exponent_out = 2.5) Condition Error in `static_power_law_game_impl()`: - ! At vendor/cigraph/src/games/static_fitness.c:xx : Number of nodes cannot be negative, got -1. Invalid value + ! Number of nodes cannot be negative, got -1. Invalid value + Source: : # k_regular_game_impl basic @@ -1126,7 +1160,8 @@ k_regular_game_impl(no_of_nodes = -1, k = 2) Condition Error in `k_regular_game_impl()`: - ! At vendor/cigraph/src/games/k_regular.c:xx : Number of nodes must be non-negative. Invalid value + ! Number of nodes must be non-negative. Invalid value + Source: : # sbm_game_impl basic @@ -1155,7 +1190,8 @@ sbm_game_impl(n = -1, pref_matrix = matrix(0.5, 2, 2), block_sizes = c(2, 3)) Condition Error in `sbm_game_impl()`: - ! At vendor/cigraph/src/games/sbm.c:xx : Sum of the block sizes (5) must equal the number of vertices (-1). Invalid value + ! Sum of the block sizes (5) must equal the number of vertices (-1). Invalid value + Source: : # hsbm_game_impl basic @@ -1173,7 +1209,8 @@ hsbm_game_impl(n = -1, m = 2, rho = 0.5, C = matrix(1, 2, 2), p = 0.5) Condition Error in `hsbm_game_impl()`: - ! At vendor/cigraph/src/games/sbm.c:xx : `n' must be positive for HSBM, Invalid value + ! `n' must be positive for HSBM. Invalid value + Source: : # hsbm_list_game_impl basic @@ -1201,7 +1238,8 @@ matrix(1, 2, 2), matrix(1, 2, 2)), p = 0.5) Condition Error in `hsbm_list_game_impl()`: - ! At vendor/cigraph/src/games/sbm.c:xx : `n' must be positive for HSBM. Invalid value + ! `n' must be positive for HSBM. Invalid value + Source: : # correlated_game_impl basic @@ -1259,7 +1297,8 @@ correlated_pair_game_impl(n = -1, corr = 0.5, p = 0.5) Condition Error in `correlated_pair_game_impl()`: - ! At vendor/cigraph/src/games/erdos_renyi.c:xx : Invalid number of vertices. Invalid value + ! Invalid number of vertices. Invalid value + Source: : # dot_product_game_impl basic @@ -1267,7 +1306,8 @@ dot_product_game_impl(vecs = matrix(0.5, 5, 2)) Condition Warning in `dot_product_game_impl()`: - At vendor/cigraph/src/games/dotproduct.c:90 : Greater than 1 connection probability in dot-product graph. + Greater than 1 connection probability in dot-product graph. + Source: games/dotproduct.c:90 Output IGRAPH U--- 2 1 -- + edge: @@ -1279,7 +1319,8 @@ dot_product_game_impl(vecs = matrix(0.5, 5, 2), directed = TRUE) Condition Warning in `dot_product_game_impl()`: - At vendor/cigraph/src/games/dotproduct.c:90 : Greater than 1 connection probability in dot-product graph. + Greater than 1 connection probability in dot-product graph. + Source: games/dotproduct.c:90 Output IGRAPH D--- 2 2 -- + edges: @@ -1319,7 +1360,8 @@ sample_sphere_surface_impl(dim = -1, n = 5) Condition Error in `sample_sphere_surface_impl()`: - ! At vendor/cigraph/src/games/dotproduct.c:xx : Sphere must be at least two dimensional to sample from surface. Invalid value + ! Sphere must be at least two dimensional to sample from surface. Invalid value + Source: : # sample_sphere_volume_impl basic @@ -1347,7 +1389,8 @@ sample_sphere_volume_impl(dim = -1, n = 5) Condition Error in `sample_sphere_volume_impl()`: - ! At vendor/cigraph/src/games/dotproduct.c:xx : Sphere must be at least two dimensional to sample from surface. Invalid value + ! Sphere must be at least two dimensional to sample from surface. Invalid value + Source: : # sample_dirichlet_impl basic @@ -1365,7 +1408,8 @@ sample_dirichlet_impl(n = -1, alpha = c(1, 1, 1)) Condition Error in `sample_dirichlet_impl()`: - ! At vendor/cigraph/src/games/dotproduct.c:xx : Number of samples should be non-negative, got -1. Invalid value + ! Number of samples should be non-negative, got -1. Invalid value + Source: : # are_adjacent_impl basic @@ -2226,7 +2270,8 @@ transitivity_barrat_impl(graph = g) Condition Warning in `transitivity_barrat_impl()`: - At vendor/cigraph/src/properties/triangles.c:913 : No weights given for Barrat's transitivity, unweighted version is used. + No weights given for Barrat's transitivity, unweighted version is used. + Source: properties/triangles.c:913 Output [1] NaN 0 NaN @@ -2236,7 +2281,8 @@ transitivity_barrat_impl(graph = g, mode = "zero") Condition Warning in `transitivity_barrat_impl()`: - At vendor/cigraph/src/properties/triangles.c:913 : No weights given for Barrat's transitivity, unweighted version is used. + No weights given for Barrat's transitivity, unweighted version is used. + Source: properties/triangles.c:913 Output [1] 0 0 0 @@ -3144,7 +3190,8 @@ centralization_degree_tmax_impl(nodes = -1, loops = TRUE) Condition Error in `centralization_degree_tmax_impl()`: - ! At vendor/cigraph/src/centrality/centralization.c:xx : Number of vertices must not be negative. Invalid value + ! Number of vertices must not be negative. Invalid value + Source: : # centralization_betweenness_impl basic @@ -3204,7 +3251,8 @@ centralization_betweenness_tmax_impl(nodes = -1, directed = TRUE) Condition Error in `centralization_betweenness_tmax_impl()`: - ! At vendor/cigraph/src/centrality/centralization.c:xx : Number of vertices must not be negative. Invalid value + ! Number of vertices must not be negative. Invalid value + Source: : # centralization_closeness_impl basic @@ -3264,7 +3312,8 @@ centralization_closeness_tmax_impl(nodes = -1) Condition Error in `centralization_closeness_tmax_impl()`: - ! At vendor/cigraph/src/centrality/centralization.c:xx : Number of vertices must not be negative. Invalid value + ! Number of vertices must not be negative. Invalid value + Source: : # centralization_eigenvector_centrality_impl basic @@ -3455,7 +3504,8 @@ centralization_eigenvector_centrality_tmax_impl(nodes = -1) Condition Error in `centralization_eigenvector_centrality_tmax_impl()`: - ! At vendor/cigraph/src/centrality/centralization.c:xx : Number of vertices must not be negative. Invalid value + ! Number of vertices must not be negative. Invalid value + Source: : # assortativity_nominal_impl basic @@ -3959,7 +4009,8 @@ Warning in `is_graphical_impl()`: NAs introduced by coercion Error in `is_graphical_impl()`: - ! At rinterface_extra.c:xx : The value nan is not representable as an integer. Invalid value + ! The value nan is not representable as an integer. Invalid value + Source: : # bfs_simple_impl basic @@ -4143,7 +4194,8 @@ bipartite_game_gnp_impl(n1 = -1, n2 = 2, p = 0.5) Condition Error in `bipartite_game_gnp_impl()`: - ! At vendor/cigraph/src/misc/bipartite.c:xx : Invalid number of vertices for bipartite graph. Invalid value + ! Invalid number of vertices for bipartite graph. Invalid value + Source: : # bipartite_game_gnm_impl basic @@ -4179,7 +4231,8 @@ bipartite_game_gnm_impl(n1 = -1, n2 = 2, m = 1) Condition Error in `bipartite_game_gnm_impl()`: - ! At vendor/cigraph/src/misc/bipartite.c:xx : Invalid number of vertices for bipartite graph. Invalid value + ! Invalid number of vertices for bipartite graph. Invalid value + Source: : # get_laplacian_impl basic @@ -5413,7 +5466,8 @@ Warning in `compare_communities_impl()`: NAs introduced by coercion Error in `compare_communities_impl()`: - ! At rinterface_extra.c:xx : The value nan is not representable as an integer. Invalid value + ! The value nan is not representable as an integer. Invalid value + Source: : # modularity_impl basic @@ -5621,7 +5675,8 @@ Warning in `split_join_distance_impl()`: NAs introduced by coercion Error in `split_join_distance_impl()`: - ! At rinterface_extra.c:xx : The value nan is not representable as an integer. Invalid value + ! The value nan is not representable as an integer. Invalid value + Source: : # community_infomap_impl basic @@ -5749,7 +5804,7 @@ hrg_sample_impl(hrg = NULL) Condition Error in `hrg_sample_impl()`: - ! At vendor/cigraph/src/hrg/hrg_types.cc:xx : 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 @@ -5780,7 +5835,7 @@ hrg_sample_many_impl(hrg = NULL, num_samples = 2) Condition Error in `hrg_sample_many_impl()`: - ! At vendor/cigraph/src/hrg/hrg_types.cc:xx : 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 @@ -5802,7 +5857,7 @@ hrg_game_impl(hrg = NULL) Condition Error in `hrg_game_impl()`: - ! At vendor/cigraph/src/hrg/hrg_types.cc:xx : 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 @@ -5836,7 +5891,8 @@ hrg_create_impl(graph = g, prob = 0.5) Condition Error in `hrg_create_impl()`: - ! At vendor/cigraph/src/hrg/hrg.cc:xx : HRG probability vector size (1) should be equal to the number of internal nodes (2). Invalid value + ! HRG probability vector size (1) should be equal to the number of internal nodes (2). Invalid value + Source: : # hrg_resize_impl basic @@ -5865,7 +5921,8 @@ hrg_resize_impl(hrg = -1, newsize = 2) Condition Error in `hrg_resize_impl()`: - ! At rinterface_extra.c:xx : The value nan is not representable as an integer. Invalid value + ! The value nan is not representable as an integer. Invalid value + Source: : # hrg_size_impl basic @@ -5880,7 +5937,8 @@ hrg_size_impl(hrg = -1) Condition Error in `hrg_size_impl()`: - ! At rinterface_extra.c:xx : The value nan is not representable as an integer. Invalid value + ! The value nan is not representable as an integer. Invalid value + Source: : # from_hrg_dendrogram_impl basic @@ -5903,7 +5961,8 @@ from_hrg_dendrogram_impl(hrg = -1) Condition Error in `from_hrg_dendrogram_impl()`: - ! At rinterface_extra.c:xx : The value nan is not representable as an integer. Invalid value + ! The value nan is not representable as an integer. Invalid value + Source: : # get_adjacency_sparse_impl basic @@ -6158,7 +6217,8 @@ motifs_randesu_no_impl(graph = g, size = 3, cut_prob = c(0.1)) Condition Error in `motifs_randesu_no_impl()`: - ! At vendor/cigraph/src/misc/motifs.c:xx : Cut probability vector size (1) must agree with motif size (3). Invalid value + ! Cut probability vector size (1) must agree with motif size (3). Invalid value + Source: : # dyad_census_impl basic @@ -6189,7 +6249,8 @@ triad_census_impl(graph = g) Condition Warning in `triad_census_impl()`: - At vendor/cigraph/src/misc/motifs.c:1157 : Triad census called on an undirected graph. All connections will be treated as mutual. + Triad census called on an undirected graph. All connections will be treated as mutual. + Source: misc/motifs.c:1157 Output [1] 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 @@ -7071,7 +7132,8 @@ Warning in `isoclass_create_impl()`: NAs introduced by coercion Error in `isoclass_create_impl()`: - ! At rinterface_extra.c:xx : The value nan is not representable as an integer. Invalid value + ! The value nan is not representable as an integer. Invalid value + Source: : # isomorphic_vf2_impl basic @@ -7624,7 +7686,8 @@ Warning in `graph_count_impl()`: NAs introduced by coercion Error in `graph_count_impl()`: - ! At rinterface_extra.c:xx : The value nan is not representable as an integer. Invalid value + ! The value nan is not representable as an integer. Invalid value + Source: : # is_matching_impl basic @@ -8066,7 +8129,8 @@ options = list(maxiter = 10)) Condition Error in `eigen_adjacency_impl()`: - ! At vendor/cigraph/src/linalg/eigen.c:xx : 'LAPACK' algorithm not implemented yet, Unimplemented function call + ! 'LAPACK' algorithm not implemented yet. Unimplemented function call + Source: : # eigen_adjacency_impl errors @@ -8126,7 +8190,8 @@ Warning in `power_law_fit_impl()`: NAs introduced by coercion Error in `power_law_fit_impl()`: - ! At vendor/cigraph/src/misc/power_law_fit.c:xx : xmin must be greater than zero, Invalid value + ! xmin must be greater than zero. Invalid value + Source: : # sir_impl basic @@ -9617,7 +9682,8 @@ dim_select_impl(sv = NULL) Condition Error in `dim_select_impl()`: - ! At vendor/cigraph/src/misc/embedding.c:xx : Need at least one singular value for dimensionality selection, Invalid value + ! Need at least one singular value for dimensionality selection. Invalid value + Source: : # solve_lsap_impl basic @@ -9749,7 +9815,8 @@ eulerian_cycle_impl(graph = g1) Condition Error in `eulerian_cycle_impl()`: - ! At vendor/cigraph/src/paths/eulerian.c:xx : The graph does not have an Eulerian cycle. Input problem has no solution + ! The graph does not have an Eulerian cycle. Input problem has no solution + Source: : --- @@ -9892,7 +9959,8 @@ Warning in `from_prufer_impl()`: NAs introduced by coercion Error in `from_prufer_impl()`: - ! At rinterface_extra.c:xx : The value nan is not representable as an integer. Invalid value + ! The value nan is not representable as an integer. Invalid value + Source: : # to_prufer_impl basic @@ -9935,7 +10003,8 @@ Warning in `tree_from_parent_vector_impl()`: NAs introduced by coercion Error in `tree_from_parent_vector_impl()`: - ! At rinterface_extra.c:xx : The value nan is not representable as an integer. Invalid value + ! The value nan is not representable as an integer. Invalid value + Source: : # is_complete_impl basic @@ -9994,7 +10063,8 @@ Warning in `tree_game_impl()`: NAs introduced by coercion Error in `tree_game_impl()`: - ! At rinterface_extra.c:xx : The value nan is not representable as an integer. Invalid value + ! The value nan is not representable as an integer. Invalid value + Source: : # vertex_coloring_greedy_impl basic @@ -10390,7 +10460,8 @@ famous_impl(name = "NonexistentGraph") Condition Error in `famous_impl()`: - ! At vendor/cigraph/src/constructors/famous.c:xx : NonexistentGraph is not a known graph. See the documentation for valid graph names. Invalid value + ! NonexistentGraph is not a known graph. See the documentation for valid graph names. Invalid value + Source: : # constraint_impl errors @@ -11126,7 +11197,8 @@ connect_neighborhood_impl(graph = g, order = 1, mode = c("all", "out", "in")) Condition Warning in `connect_neighborhood_impl()`: - At vendor/cigraph/src/operators/connect_neighborhood.c:85 : Order smaller than two, graph will be unchanged. + Order smaller than two, graph will be unchanged. + Source: operators/connect_neighborhood.c:85 Output IGRAPH U--- 5 5 -- Ring graph + attr: name (g/c), mutual (g/l), circular (g/l) diff --git a/tests/testthat/_snaps/centrality.md b/tests/testthat/_snaps/centrality.md index 62a6c46264f..f6ffca6419b 100644 --- a/tests/testthat/_snaps/centrality.md +++ b/tests/testthat/_snaps/centrality.md @@ -48,7 +48,8 @@ arpack(f, options = list(nev = 2, ncv = 4), sym = TRUE) Condition Error in `arpack()`: - ! At vendor/cigraph/src/linalg/arpack.c:1102 : ARPACK error, N must be positive + ! ARPACK error. N must be positive + Source: : --- diff --git a/tests/testthat/_snaps/error-formatting.md b/tests/testthat/_snaps/error-formatting.md new file mode 100644 index 00000000000..66512692f0e --- /dev/null +++ b/tests/testthat/_snaps/error-formatting.md @@ -0,0 +1,9 @@ +# error messages include source file and line information + + Code + test_error_with_source() + Condition + Error in `test_error_with_source()`: + ! Test error message for verifying source location formatting. Invalid value + Source: test_error_with_source.c:31 + diff --git a/tests/testthat/_snaps/games.md b/tests/testthat/_snaps/games.md index 922ef9a505f..15522aa0df9 100644 --- a/tests/testthat/_snaps/games.md +++ b/tests/testthat/_snaps/games.md @@ -4,7 +4,8 @@ sample_degseq(exponential_degrees, method = "vl") Condition Error in `sample_degseq()`: - ! At vendor/cigraph/src/games/degree_sequence_vl/gengraph_mr-connected.cpp: : Cannot make a connected graph from the given degree sequence. Invalid value + ! Cannot make a connected graph from the given degree sequence. Invalid value + Source: games/degree_sequence_vl/gengraph_mr-connected.cpp: # sample_degseq() works -- Power-law degree error @@ -12,5 +13,6 @@ sample_degseq(powerlaw_degrees, method = "vl") Condition Error in `sample_degseq()`: - ! At vendor/cigraph/src/games/degree_sequence_vl/gengraph_mr-connected.cpp: : Cannot realize the given degree sequence as an undirected, simple graph. Invalid value + ! Cannot realize the given degree sequence as an undirected, simple graph. Invalid value + Source: games/degree_sequence_vl/gengraph_mr-connected.cpp: diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index 644486107af..91c6660ea60 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -49,7 +49,15 @@ expect_snapshot_igraph_error <- function(x, ...) { {{ x }}, error = TRUE, transform = function(y) { - gsub(":(\\d+)", ":xx", 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-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 41653455073..71bd753a7e6 100644 --- a/tests/testthat/test-centrality.R +++ b/tests/testthat/test-centrality.R @@ -845,10 +845,10 @@ test_that("eigen_centrality() deprecated scale argument", { test_that("arpack() errors well", { f <- function(x, extra = NULL) x - expect_snapshot(error = TRUE, { + 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..65a2858fc67 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", { @@ -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) ) }) @@ -679,7 +677,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 new file mode 100644 index 00000000000..a29e5d59c7e --- /dev/null +++ b/tests/testthat/test-error-formatting.R @@ -0,0 +1,12 @@ +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, + { + test_error_with_source() + } + ) +}) 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..d9b9eec71d5 100644 --- a/tests/testthat/test-flow.R +++ b/tests/testthat/test-flow.R @@ -98,15 +98,13 @@ 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( - st_min_cuts(g_path, source = "a", target = NULL), - 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_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") ) }) @@ -142,7 +140,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 +177,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", { @@ -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) ) }) @@ -212,7 +208,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 +221,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 +248,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..3a26f55e8b7 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,13 +72,11 @@ 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( - g <- graph_from_graphdb(nodes = 10, prefix = "not_existing"), - error = TRUE + expect_snapshot_igraph_error(g <- graph_from_graphdb()) + 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-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..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 + } ) }) @@ -292,9 +291,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-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 6ccd5cf2c45..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) ) }) @@ -159,7 +158,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-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") ) }) 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({