From 0ad4e1e3a6f3615ad0a18196baeff243a9697ec8 Mon Sep 17 00:00:00 2001 From: olivroy <52606734+olivroy@users.noreply.github.com> Date: Fri, 8 Dec 2023 10:18:23 -0500 Subject: [PATCH 1/4] Add an actual link to the file --- R/utils.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utils.R b/R/utils.R index 51a0ce21..cccff224 100644 --- a/R/utils.R +++ b/R/utils.R @@ -69,7 +69,7 @@ write_if_different <- function(path, contents, href = NULL, check = TRUE) { name <- basename(path) if (check && !made_by_roxygen(path)) { cli::cli_inform(c( - x = "Skipping {.path {name}}", + x = "Skipping {.href [{name}](file://man/{name})}", i = "It already exists and was not generated by roxygen2." )) return(FALSE) From b83b0af53829732af313e7d9f36349421248c7ea Mon Sep 17 00:00:00 2001 From: olivroy Date: Thu, 14 Dec 2023 08:48:00 -0500 Subject: [PATCH 2/4] Make tests pass by using the full path. --- R/utils.R | 2 +- tests/testthat/_snaps/utils.md | 10 ---------- tests/testthat/test-utils.R | 2 +- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/R/utils.R b/R/utils.R index cccff224..517216ef 100644 --- a/R/utils.R +++ b/R/utils.R @@ -69,7 +69,7 @@ write_if_different <- function(path, contents, href = NULL, check = TRUE) { name <- basename(path) if (check && !made_by_roxygen(path)) { cli::cli_inform(c( - x = "Skipping {.href [{name}](file://man/{name})}", + x = "Skipping {.href [{name}](file://{path}}", i = "It already exists and was not generated by roxygen2." )) return(FALSE) diff --git a/tests/testthat/_snaps/utils.md b/tests/testthat/_snaps/utils.md index 99d745a8..b100199a 100644 --- a/tests/testthat/_snaps/utils.md +++ b/tests/testthat/_snaps/utils.md @@ -7,16 +7,6 @@ Output [1] TRUE ---- - - Code - write_if_different(path, "a <- 2") - Message - x Skipping 'test.R' - i It already exists and was not generated by roxygen2. - Output - [1] FALSE - --- Code diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 55987183..e2cd90c1 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -22,7 +22,7 @@ test_that("write_if_different produces informative messages", { expect_snapshot(write_if_different(path, "a <- 2")) write_lines("a <- 1", path) - expect_snapshot(write_if_different(path, "a <- 2")) + expect_message(write_if_different(path, "a <- 2"), "Skipping.+test.R") path <- file.path(dir, "+.R") expect_snapshot(write_if_different(path, "a <- 2")) From 76b7e66ad3ca9ce1840c1e44884d1cf4ed545499 Mon Sep 17 00:00:00 2001 From: olivroy <52606734+olivroy@users.noreply.github.com> Date: Thu, 14 Dec 2023 08:55:23 -0500 Subject: [PATCH 3/4] test that it returns false --- tests/testthat/test-utils.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index e2cd90c1..50cbe41a 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -22,7 +22,8 @@ test_that("write_if_different produces informative messages", { expect_snapshot(write_if_different(path, "a <- 2")) write_lines("a <- 1", path) - expect_message(write_if_different(path, "a <- 2"), "Skipping.+test.R") + expect_message(out <- write_if_different(path, "a <- 2"), "Skipping.+test.R") + expect_false(out) path <- file.path(dir, "+.R") expect_snapshot(write_if_different(path, "a <- 2")) From a49621afae181154abbee484a441f66f764fa77d Mon Sep 17 00:00:00 2001 From: olivroy Date: Wed, 10 Jul 2024 08:47:38 -0400 Subject: [PATCH 4/4] Restore snapshot test + make correction --- R/utils.R | 2 +- tests/testthat/_snaps/utils.md | 10 ++++++++++ tests/testthat/test-utils.R | 7 +++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/R/utils.R b/R/utils.R index a6052707..37273174 100644 --- a/R/utils.R +++ b/R/utils.R @@ -69,7 +69,7 @@ write_if_different <- function(path, contents, command = NULL, check = TRUE) { name <- basename(path) if (check && !made_by_roxygen(path)) { cli::cli_inform(c( - x = "Skipping {.href [{name}](file://{path}}", + x = "Skipping {.href [{name}](file://{path})}", i = "It already exists and was not generated by {.pkg roxygen2}." )) return(FALSE) diff --git a/tests/testthat/_snaps/utils.md b/tests/testthat/_snaps/utils.md index 8d6a0391..5d124fbf 100644 --- a/tests/testthat/_snaps/utils.md +++ b/tests/testthat/_snaps/utils.md @@ -7,6 +7,16 @@ Output [1] TRUE +--- + + Code + write_if_different(path, "a <- 2") + Message + x Skipping test.R () + i It already exists and was not generated by roxygen2. + Output + [1] FALSE + --- Code diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 0d8a620b..b3d3ed13 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -22,8 +22,11 @@ test_that("write_if_different produces informative messages", { expect_snapshot(write_if_different(path, "a <- 2")) write_lines("a <- 1", path) - expect_message(out <- write_if_different(path, "a <- 2"), "Skipping.+test.R") - expect_false(out) + # strip temp path + expect_snapshot( + write_if_different(path, "a <- 2"), + transform = function(x) gsub(dir, "", x, fixed = TRUE) + ) path <- file.path(dir, "+.R") expect_snapshot(write_if_different(path, "a <- 2"))