From 1f727eca077eeab3ec8be11513bc023e1d2b03c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 11 Jun 2023 22:49:03 +0200 Subject: [PATCH 01/10] R_igraph_add_myid_to_env --- R/versions.R | 2 ++ src/cpp11.cpp | 2 ++ src/rinterface_extra.c | 14 ++++++++------ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/R/versions.R b/R/versions.R index 17090ae02ec..ec4c9b578fa 100644 --- a/R/versions.R +++ b/R/versions.R @@ -96,6 +96,8 @@ upgrade_graph <- function(graph) { if (g_ver == "0.4.0") { .Call(R_igraph_add_env, graph) } else if (g_ver == "0.7.999") { + # Not observed in the wild + .Call(R_igraph_add_myid_to_env, graph) .Call(R_igraph_add_version_to_env, graph) } else { stop("Don't know how to upgrade graph from ", g_ver, " to ", p_ver) diff --git a/src/cpp11.cpp b/src/cpp11.cpp index 4878ba5e4e9..f7a41348fa0 100644 --- a/src/cpp11.cpp +++ b/src/cpp11.cpp @@ -17,6 +17,7 @@ extern "C" { /* .Call calls */ extern SEXP R_igraph_add_edges(SEXP, SEXP); extern SEXP R_igraph_add_env(SEXP); +extern SEXP R_igraph_add_myid_to_env(SEXP); extern SEXP R_igraph_add_version_to_env(SEXP); extern SEXP R_igraph_add_vertices(SEXP, SEXP); extern SEXP R_igraph_address(SEXP); @@ -398,6 +399,7 @@ extern SEXP promise_expr_(SEXP); static const R_CallMethodDef CallEntries[] = { {"R_igraph_add_edges", (DL_FUNC) &R_igraph_add_edges, 2}, {"R_igraph_add_env", (DL_FUNC) &R_igraph_add_env, 1}, + {"R_igraph_add_myid_to_env", (DL_FUNC) &R_igraph_add_myid_to_env, 1}, {"R_igraph_add_version_to_env", (DL_FUNC) &R_igraph_add_version_to_env, 1}, {"R_igraph_add_vertices", (DL_FUNC) &R_igraph_add_vertices, 2}, {"R_igraph_address", (DL_FUNC) &R_igraph_address, 1}, diff --git a/src/rinterface_extra.c b/src/rinterface_extra.c index ed369659b00..2f08abb64c6 100644 --- a/src/rinterface_extra.c +++ b/src/rinterface_extra.c @@ -9950,24 +9950,26 @@ SEXP R_igraph_graph_version(SEXP graph) { } } -SEXP R_igraph_add_version_to_env(SEXP graph) { +SEXP R_igraph_add_myid_to_env(SEXP graph) { uuid_t my_id; char my_id_chr[40]; - PROTECT(graph = Rf_duplicate(graph)); - uuid_generate(my_id); uuid_unparse_lower(my_id, my_id_chr); SEXP l1 = PROTECT(Rf_install("myid")); SEXP l2 = PROTECT(Rf_mkString(my_id_chr)); Rf_defineVar(l1, l2, R_igraph_graph_env(graph)); UNPROTECT(2); - l1 = PROTECT(Rf_install(R_IGRAPH_VERSION_VAR)); - l2 = PROTECT(Rf_mkString(R_IGRAPH_TYPE_VERSION)); + + return graph; +} + +SEXP R_igraph_add_version_to_env(SEXP graph) { + SEXP l1 = PROTECT(Rf_install(R_IGRAPH_VERSION_VAR)); + SEXP l2 = PROTECT(Rf_mkString(R_IGRAPH_TYPE_VERSION)); Rf_defineVar(l1, l2, R_igraph_graph_env(graph)); UNPROTECT(2); - UNPROTECT(1); return graph; } From 1de0c85051e934222f09e24eaed468dbcdeda534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Mon, 5 Jun 2023 13:00:26 +0200 Subject: [PATCH 02/10] Bump igraph format version to 1.5.0 --- R/versions.R | 2 +- src/rinterface.h | 2 +- tests/testthat/_snaps/versions.md | 113 +++++++++++++++++++++++++++++- tests/testthat/test-versions.R | 6 +- 4 files changed, 116 insertions(+), 7 deletions(-) diff --git a/R/versions.R b/R/versions.R index ec4c9b578fa..7a1aa9d8a8c 100644 --- a/R/versions.R +++ b/R/versions.R @@ -22,7 +22,7 @@ ## ## ---------------------------------------------------------------------- -pkg_graph_version <- "0.8.0" +pkg_graph_version <- "1.5.0" pkg_graph_version_obj <- as.package_version(pkg_graph_version) diff --git a/src/rinterface.h b/src/rinterface.h index 8117872f9ef..08547677dea 100644 --- a/src/rinterface.h +++ b/src/rinterface.h @@ -25,7 +25,7 @@ #include "uuid/uuid.h" -#define R_IGRAPH_TYPE_VERSION "0.8.0" +#define R_IGRAPH_TYPE_VERSION "1.5.0" #define R_IGRAPH_VERSION_VAR ".__igraph_version__." SEXP R_igraph_add_env(SEXP graph); diff --git a/tests/testthat/_snaps/versions.md b/tests/testthat/_snaps/versions.md index 09044316cbd..9f3f730e6ef 100644 --- a/tests/testthat/_snaps/versions.md +++ b/tests/testthat/_snaps/versions.md @@ -34,16 +34,125 @@ Code s[["1.0.0"]] + Message + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... Output IGRAPH D--- 3 3 -- Ring graph + Message + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + Output + attr: name (g/c), mutual (g/l), circular (g/l), bar (v/c), foo (e/c) + Message + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + Output + edges: + Message + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + Output [1] 1->2 2->3 3->1 --- Code s[["1.5.0"]] - Error - This graph was created by a new(er) igraph version. Please install the latest version of igraph and try again. + Output + IGRAPH D--- 3 3 -- Ring graph + + attr: name (g/c), mutual (g/l), circular (g/l), bar (v/c), foo (e/c) + + edges: + [1] 1->2 2->3 3->1 diff --git a/tests/testthat/test-versions.R b/tests/testthat/test-versions.R index 97b93212587..4b4f7f72e20 100644 --- a/tests/testthat/test-versions.R +++ b/tests/testthat/test-versions.R @@ -5,7 +5,7 @@ test_that("we create graphs of the current version", { expect_equal(v1, v2) }) -test_that("we can upgrade from 0.4.0 to 0.8.0", { +test_that("we can upgrade from 0.4.0 to 1.5.0", { g <- make_ring(10) g <- unclass(g) g[[10]] <- NULL @@ -14,7 +14,7 @@ test_that("we can upgrade from 0.4.0 to 0.8.0", { expect_equal(graph_version(g), as.package_version("0.4.0")) g2 <- upgrade_graph(g) - expect_equal(graph_version(g2), as.package_version("0.8.0")) + expect_equal(graph_version(g2), as.package_version("1.5.0")) }) test_that("reading of old igraph formats", { @@ -36,7 +36,7 @@ test_that("reading of old igraph formats", { expect_snapshot({ s[["1.0.0"]] }) - expect_snapshot(error = TRUE, { + expect_snapshot({ s[["1.5.0"]] }) }) From 9a274fc7cd7f2594319a2dd7d8eb8ea7f830a1fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 11 Jun 2023 15:08:07 +0200 Subject: [PATCH 03/10] Avoid noise --- R/versions.R | 11 ++++ tests/testthat/_snaps/versions.md | 102 ------------------------------ 2 files changed, 11 insertions(+), 102 deletions(-) diff --git a/R/versions.R b/R/versions.R index 7a1aa9d8a8c..cfe65fc807c 100644 --- a/R/versions.R +++ b/R/versions.R @@ -124,6 +124,17 @@ warn_version <- function(graph) { " Call upgrade_graph() on it to use with the current igraph version\n", " For now we convert it on the fly..." ) + + # In-place upgrade: + # - The igraph element in the igraph_t_idx_env component will be added + # transparently because it's missing. + # - The components igraph_t_idx_oi, igraph_t_idx_ii, igraph_t_idx_os, + # igraph_t_idx_is are ignored, but we can't do much about the contents. + # Users will have to call upgrade_graph(), but this is what the message + # is about. + if (pkg_graph_version <= "1.5.0") { + .Call(R_igraph_add_version_to_env, graph) + } return(TRUE) } diff --git a/tests/testthat/_snaps/versions.md b/tests/testthat/_snaps/versions.md index 9f3f730e6ef..f921d7124b4 100644 --- a/tests/testthat/_snaps/versions.md +++ b/tests/testthat/_snaps/versions.md @@ -38,112 +38,10 @@ This graph was created by an old(er) igraph version. Call upgrade_graph() on it to use with the current igraph version For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... Output IGRAPH D--- 3 3 -- Ring graph - Message - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - Output + attr: name (g/c), mutual (g/l), circular (g/l), bar (v/c), foo (e/c) - Message - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - Output + edges: - Message - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - This graph was created by an old(er) igraph version. - Call upgrade_graph() on it to use with the current igraph version - For now we convert it on the fly... - Output [1] 1->2 2->3 3->1 --- From 020a0be78fbe930de5b5581e434f6ebdbf0fb3a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 11 Jun 2023 15:21:33 +0200 Subject: [PATCH 04/10] Add successful tests --- tests/testthat/test-versions.R | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tests/testthat/test-versions.R b/tests/testthat/test-versions.R index 4b4f7f72e20..c0ae57672c0 100644 --- a/tests/testthat/test-versions.R +++ b/tests/testthat/test-versions.R @@ -5,11 +5,26 @@ test_that("we create graphs of the current version", { expect_equal(v1, v2) }) -test_that("we can upgrade from 0.4.0 to 1.5.0", { - g <- make_ring(10) - g <- unclass(g) - g[[10]] <- NULL - class(g) <- "igraph" +test_that("we can upgrade from 0.2 to 1.5.0", { + g <- oldsample_0_2() + + expect_equal(graph_version(g), as.package_version("0.4.0")) + + g2 <- upgrade_graph(g) + expect_equal(graph_version(g2), as.package_version("1.5.0")) +}) + +test_that("we can upgrade from 0.5 to 1.5.0", { + g <- oldsample_0_5() + + expect_equal(graph_version(g), as.package_version("0.4.0")) + + g2 <- upgrade_graph(g) + expect_equal(graph_version(g2), as.package_version("1.5.0")) +}) + +test_that("we can upgrade from 0.6 to 1.5.0", { + g <- oldsample_0_6() expect_equal(graph_version(g), as.package_version("0.4.0")) From 57e26df761006a909fb70c2e1319c16ceb83a27c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 11 Jun 2023 22:47:27 +0200 Subject: [PATCH 05/10] No upgrade path from the very first version 0.1.1 --- src/rinterface_extra.c | 6 ++++-- tests/testthat/_snaps/versions.md | 7 +++++++ tests/testthat/test-versions.R | 10 ++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/rinterface_extra.c b/src/rinterface_extra.c index 2f08abb64c6..45786077aab 100644 --- a/src/rinterface_extra.c +++ b/src/rinterface_extra.c @@ -2964,7 +2964,7 @@ static int restore_pointer(SEXP graph, igraph_t *g) { IGRAPH_CHECK(igraph_empty(g, no_of_nodes, directed)); IGRAPH_FINALLY(igraph_destroy, g); IGRAPH_CHECK(igraph_add_edges(g, &edges, NULL)); - + igraph_vector_destroy(&edges); IGRAPH_FINALLY_CLEAN(2); /* +1 for g */ @@ -9938,7 +9938,9 @@ SEXP R_igraph_identical_graphs(SEXP g1, SEXP g2, SEXP attrs) { } SEXP R_igraph_graph_version(SEXP graph) { - if (GET_LENGTH(graph) == igraph_t_idx_max && Rf_isEnvironment(R_igraph_graph_env(graph))) { + if (GET_LENGTH(graph) == 11) { + return Rf_mkString("0.1.1"); + } else if (GET_LENGTH(graph) == igraph_t_idx_max && Rf_isEnvironment(R_igraph_graph_env(graph))) { SEXP ver = Rf_findVar(Rf_install(R_IGRAPH_VERSION_VAR), R_igraph_graph_env(graph)); if (ver != R_UnboundValue) { return ver; diff --git a/tests/testthat/_snaps/versions.md b/tests/testthat/_snaps/versions.md index f921d7124b4..0786a52f5ec 100644 --- a/tests/testthat/_snaps/versions.md +++ b/tests/testthat/_snaps/versions.md @@ -1,3 +1,10 @@ +# we can't upgrade from 0.1.1 to 1.5.0 + + Code + upgrade_graph(g) + Error + Don't know how to upgrade graph from 0.1.1 to 1.5.0 + # reading of old igraph formats Code diff --git a/tests/testthat/test-versions.R b/tests/testthat/test-versions.R index c0ae57672c0..2df64c27339 100644 --- a/tests/testthat/test-versions.R +++ b/tests/testthat/test-versions.R @@ -5,6 +5,16 @@ test_that("we create graphs of the current version", { expect_equal(v1, v2) }) +test_that("we can't upgrade from 0.1.1 to 1.5.0", { + g <- oldsample_0_1_1() + + expect_equal(graph_version(g), as.package_version("0.1.1")) + + expect_snapshot(error = TRUE, { + upgrade_graph(g) + }) +}) + test_that("we can upgrade from 0.2 to 1.5.0", { g <- oldsample_0_2() From 70fc5fcbb612977842634fe57a0ea45411a06639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 11 Jun 2023 22:47:43 +0200 Subject: [PATCH 06/10] Implement upgrade paths --- R/versions.R | 17 +++++++++++++++++ tests/testthat/_snaps/versions.md | 23 +++++++++++++++++++++++ tests/testthat/test-versions.R | 23 +++++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/R/versions.R b/R/versions.R index cfe65fc807c..87779d45fa0 100644 --- a/R/versions.R +++ b/R/versions.R @@ -99,6 +99,17 @@ upgrade_graph <- function(graph) { # Not observed in the wild .Call(R_igraph_add_myid_to_env, graph) .Call(R_igraph_add_version_to_env, graph) + } else if (g_ver == "0.8.0") { + .Call(R_igraph_add_version_to_env, graph) + graph <- unclass(graph) + graph[igraph_t_idx_oi:igraph_t_idx_is] <- list(NULL) + class(graph) <- "igraph" + + # Calling for side effect: error if R_SEXP_to_igraph() fails, create native igraph, + # update "me" element of environment + V(graph) + + graph } else { stop("Don't know how to upgrade graph from ", g_ver, " to ", p_ver) } @@ -162,3 +173,9 @@ oldsamples <- function() { "0.1.1" = oldsample_0_1_1() ) } + +clear_native_ptr <- function(g) { + gx <- unclass(g) + gx[[igraph_t_idx_env]]$igraph <- NULL + g +} diff --git a/tests/testthat/_snaps/versions.md b/tests/testthat/_snaps/versions.md index 0786a52f5ec..397ecf5a5d8 100644 --- a/tests/testthat/_snaps/versions.md +++ b/tests/testthat/_snaps/versions.md @@ -5,6 +5,29 @@ Error Don't know how to upgrade graph from 0.1.1 to 1.5.0 +# we can upgrade from 1.0.0 to 1.5.0, on the fly + + Code + g <- oldsample_1_0_0() + graph_version(g) + Output + [1] '0.8.0' + Code + g + Message + This graph was created by an old(er) igraph version. + Call upgrade_graph() on it to use with the current igraph version + For now we convert it on the fly... + Output + IGRAPH 0fb28c0 D--- 3 3 -- Ring graph + + attr: name (g/c), mutual (g/l), circular (g/l), bar (v/c), foo (e/c) + + edges from 0fb28c0: + [1] 1->2 2->3 3->1 + Code + graph_version(g) + Output + [1] '1.5.0' + # reading of old igraph formats Code diff --git a/tests/testthat/test-versions.R b/tests/testthat/test-versions.R index 2df64c27339..560b8110f2d 100644 --- a/tests/testthat/test-versions.R +++ b/tests/testthat/test-versions.R @@ -42,6 +42,29 @@ test_that("we can upgrade from 0.6 to 1.5.0", { expect_equal(graph_version(g2), as.package_version("1.5.0")) }) +test_that("we can upgrade from 1.0.0 to 1.5.0, on the fly", { + expect_snapshot({ + g <- oldsample_1_0_0() + graph_version(g) + g + graph_version(g) + }) +}) + +test_that("we can upgrade from 1.0.0 to 1.5.0, explicitly", { + g <- oldsample_1_0_0() + graph_version(g) + g2 <- upgrade_graph(g) + graph_version(g2) + + g3 <- oldsample_1_5_0() + + expect_identical( + unclass(clear_native_ptr(g2)), + unclass(clear_native_ptr(g3)) + ) +}) + test_that("reading of old igraph formats", { local_igraph_options(print.id = FALSE) From b3edfa4759358b54b24d78e5001edc63e6ae95aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 11 Jun 2023 22:56:46 +0200 Subject: [PATCH 07/10] Test implicit upgrades --- tests/testthat/_snaps/versions.md | 34 ++++++++++++++++++++++++++++++- tests/testthat/test-versions.R | 32 +++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/tests/testthat/_snaps/versions.md b/tests/testthat/_snaps/versions.md index 397ecf5a5d8..0bf66f40d9c 100644 --- a/tests/testthat/_snaps/versions.md +++ b/tests/testthat/_snaps/versions.md @@ -1,10 +1,42 @@ -# we can't upgrade from 0.1.1 to 1.5.0 +# we can't upgrade from 0.1.1 to 1.5.0, on the fly + + Code + oldsample_0_1_1() + Error + This graph was created by a now unsupported old igraph version. + Call upgrade_version() before using igraph functions on that object. + +# we can't upgrade from 0.1.1 to 1.5.0, explicitly Code upgrade_graph(g) Error Don't know how to upgrade graph from 0.1.1 to 1.5.0 +# we can't upgrade from 0.2 to 1.5.0, on the fly + + Code + oldsample_0_2() + Error + This graph was created by a now unsupported old igraph version. + Call upgrade_version() before using igraph functions on that object. + +# we can't upgrade from 0.5 to 1.5.0, on the fly + + Code + oldsample_0_5() + Error + This graph was created by a now unsupported old igraph version. + Call upgrade_version() before using igraph functions on that object. + +# we can't upgrade from 0.6 to 1.5.0, on the fly + + Code + oldsample_0_6() + Error + This graph was created by a now unsupported old igraph version. + Call upgrade_version() before using igraph functions on that object. + # we can upgrade from 1.0.0 to 1.5.0, on the fly Code diff --git a/tests/testthat/test-versions.R b/tests/testthat/test-versions.R index 560b8110f2d..dd6a43c2152 100644 --- a/tests/testthat/test-versions.R +++ b/tests/testthat/test-versions.R @@ -5,7 +5,13 @@ test_that("we create graphs of the current version", { expect_equal(v1, v2) }) -test_that("we can't upgrade from 0.1.1 to 1.5.0", { +test_that("we can't upgrade from 0.1.1 to 1.5.0, on the fly", { + expect_snapshot(error = TRUE, { + oldsample_0_1_1() + }) +}) + +test_that("we can't upgrade from 0.1.1 to 1.5.0, explicitly", { g <- oldsample_0_1_1() expect_equal(graph_version(g), as.package_version("0.1.1")) @@ -15,7 +21,13 @@ test_that("we can't upgrade from 0.1.1 to 1.5.0", { }) }) -test_that("we can upgrade from 0.2 to 1.5.0", { +test_that("we can't upgrade from 0.2 to 1.5.0, on the fly", { + expect_snapshot(error = TRUE, { + oldsample_0_2() + }) +}) + +test_that("we can upgrade from 0.2 to 1.5.0, explicitly", { g <- oldsample_0_2() expect_equal(graph_version(g), as.package_version("0.4.0")) @@ -24,7 +36,13 @@ test_that("we can upgrade from 0.2 to 1.5.0", { expect_equal(graph_version(g2), as.package_version("1.5.0")) }) -test_that("we can upgrade from 0.5 to 1.5.0", { +test_that("we can't upgrade from 0.5 to 1.5.0, on the fly", { + expect_snapshot(error = TRUE, { + oldsample_0_5() + }) +}) + +test_that("we can upgrade from 0.5 to 1.5.0, explicitly", { g <- oldsample_0_5() expect_equal(graph_version(g), as.package_version("0.4.0")) @@ -33,7 +51,13 @@ test_that("we can upgrade from 0.5 to 1.5.0", { expect_equal(graph_version(g2), as.package_version("1.5.0")) }) -test_that("we can upgrade from 0.6 to 1.5.0", { +test_that("we can't upgrade from 0.6 to 1.5.0, on the fly", { + expect_snapshot(error = TRUE, { + oldsample_0_6() + }) +}) + +test_that("we can upgrade from 0.6 to 1.5.0, explicitly", { g <- oldsample_0_6() expect_equal(graph_version(g), as.package_version("0.4.0")) From e241fb576068646fd5041901492af9d83b8bcb1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 11 Jun 2023 23:04:27 +0200 Subject: [PATCH 08/10] Special-case igraph < 0.2 --- src/rinterface_extra.c | 3 +++ tests/testthat/_snaps/versions.md | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/rinterface_extra.c b/src/rinterface_extra.c index 45786077aab..5912da6912e 100644 --- a/src/rinterface_extra.c +++ b/src/rinterface_extra.c @@ -2979,6 +2979,9 @@ void R_igraph_restore_pointer(SEXP graph) { igraph_t *R_igraph_get_pointer(SEXP graph) { if (GET_LENGTH(graph) != igraph_t_idx_max || !Rf_isEnvironment(R_igraph_graph_env(graph))) { + if (GET_LENGTH(graph) == 11) { + Rf_error("This graph was created by igraph < 0.2.\n Upgrading this format is not supported, sorry."); + } Rf_error("This graph was created by a now unsupported old igraph version.\n Call upgrade_version() before using igraph functions on that object."); } diff --git a/tests/testthat/_snaps/versions.md b/tests/testthat/_snaps/versions.md index 0bf66f40d9c..fff15aed8a2 100644 --- a/tests/testthat/_snaps/versions.md +++ b/tests/testthat/_snaps/versions.md @@ -3,8 +3,8 @@ Code oldsample_0_1_1() Error - This graph was created by a now unsupported old igraph version. - Call upgrade_version() before using igraph functions on that object. + This graph was created by igraph < 0.2. + Upgrading this format is not supported, sorry. # we can't upgrade from 0.1.1 to 1.5.0, explicitly @@ -65,8 +65,8 @@ Code s[["0.1.1"]] Error - This graph was created by a now unsupported old igraph version. - Call upgrade_version() before using igraph functions on that object. + This graph was created by igraph < 0.2. + Upgrading this format is not supported, sorry. --- From 9861bb8c1ce55d9a1e2f3c0fae0f49414af4ccb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 11 Jun 2023 23:35:16 +0200 Subject: [PATCH 09/10] Stabilize --- tests/testthat/_snaps/versions.md | 12 ++++++------ tests/testthat/test-versions.R | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/testthat/_snaps/versions.md b/tests/testthat/_snaps/versions.md index fff15aed8a2..6bdad3af1df 100644 --- a/tests/testthat/_snaps/versions.md +++ b/tests/testthat/_snaps/versions.md @@ -51,9 +51,9 @@ Call upgrade_graph() on it to use with the current igraph version For now we convert it on the fly... Output - IGRAPH 0fb28c0 D--- 3 3 -- Ring graph + IGRAPH D--- 3 3 -- Ring graph + attr: name (g/c), mutual (g/l), circular (g/l), bar (v/c), foo (e/c) - + edges from 0fb28c0: + + edges: [1] 1->2 2->3 3->1 Code graph_version(g) @@ -101,9 +101,9 @@ Call upgrade_graph() on it to use with the current igraph version For now we convert it on the fly... Output - IGRAPH D--- 3 3 -- Ring graph + IGRAPH 0fb28c0 D--- 3 3 -- Ring graph + attr: name (g/c), mutual (g/l), circular (g/l), bar (v/c), foo (e/c) - + edges: + + edges from 0fb28c0: [1] 1->2 2->3 3->1 --- @@ -111,8 +111,8 @@ Code s[["1.5.0"]] Output - IGRAPH D--- 3 3 -- Ring graph + IGRAPH 0fb28c0 D--- 3 3 -- Ring graph + attr: name (g/c), mutual (g/l), circular (g/l), bar (v/c), foo (e/c) - + edges: + + edges from 0fb28c0: [1] 1->2 2->3 3->1 diff --git a/tests/testthat/test-versions.R b/tests/testthat/test-versions.R index dd6a43c2152..b9d038f0f26 100644 --- a/tests/testthat/test-versions.R +++ b/tests/testthat/test-versions.R @@ -67,6 +67,8 @@ test_that("we can upgrade from 0.6 to 1.5.0, explicitly", { }) test_that("we can upgrade from 1.0.0 to 1.5.0, on the fly", { + local_igraph_options(print.id = FALSE) + expect_snapshot({ g <- oldsample_1_0_0() graph_version(g) From 91cf0190dda7dec3904e2d9aedcf8edae0b1c485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Mon, 12 Jun 2023 22:05:10 +0200 Subject: [PATCH 10/10] Stabilize --- tests/testthat/_snaps/versions.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/_snaps/versions.md b/tests/testthat/_snaps/versions.md index 6bdad3af1df..223c08c52e7 100644 --- a/tests/testthat/_snaps/versions.md +++ b/tests/testthat/_snaps/versions.md @@ -101,9 +101,9 @@ Call upgrade_graph() on it to use with the current igraph version For now we convert it on the fly... Output - IGRAPH 0fb28c0 D--- 3 3 -- Ring graph + IGRAPH D--- 3 3 -- Ring graph + attr: name (g/c), mutual (g/l), circular (g/l), bar (v/c), foo (e/c) - + edges from 0fb28c0: + + edges: [1] 1->2 2->3 3->1 --- @@ -111,8 +111,8 @@ Code s[["1.5.0"]] Output - IGRAPH 0fb28c0 D--- 3 3 -- Ring graph + IGRAPH D--- 3 3 -- Ring graph + attr: name (g/c), mutual (g/l), circular (g/l), bar (v/c), foo (e/c) - + edges from 0fb28c0: + + edges: [1] 1->2 2->3 3->1