Skip to content

Commit

Permalink
Test refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Jan 22, 2024
1 parent 0359aad commit 9507c54
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
12 changes: 3 additions & 9 deletions tests/testthat/_snaps/namespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,15 @@
# warns if S3 method not documented

Code
roc_proc_text(namespace_roclet(),
"\n foo <- function(x) UseMethod('foo')\n foo.numeric <- function(x) 1\n\n mean.myclass <- function(x) 2\n ")
. <- roc_proc_text(namespace_roclet(), block)
Message
x <text>:5: S3 method `mean.myclass` needs @export or @exportS3method tag.
x <text>:3: S3 method `foo.numeric` needs @export or @exportS3method tag.
Output
character(0)

# correctly interpolates warning
---

Code
roc_proc_text(namespace_roclet(),
"\n foo <- function(x) UseMethod('foo')\n `foo.{` <- function(x) 1\n ")
. <- roc_proc_text(namespace_roclet(), block)
Message
x <text>:3: S3 method `foo.{` needs @export or @exportS3method tag.
Output
character(0)

32 changes: 16 additions & 16 deletions tests/testthat/test-namespace.R
Original file line number Diff line number Diff line change
Expand Up @@ -472,32 +472,32 @@ test_that("non-syntactic imports can use multiple quoting forms", {
# warn_missing_s3_exports -------------------------------------------------

test_that("warns if S3 method not documented", {
expect_snapshot(
roc_proc_text(namespace_roclet(), "
# Need to manually transform since the srcref is coming from the function;
# roc_proc_text() uses fake srcrefs for the blocks themselves
fix_srcref <- function(x) gsub("file[a-z0-9]+", "<text>", x)

block <- "
foo <- function(x) UseMethod('foo')
foo.numeric <- function(x) 1
mean.myclass <- function(x) 2
"),
# Need to manually transform since the srcref is coming from the function;
# roc_proc_text() uses fake srcrefs for the blocks themselves
transform = function(x) gsub("file[a-z0-9]+", "<text>", x)
"
expect_snapshot(
. <- roc_proc_text(namespace_roclet(), block),
transform = fix_srcref
)
})

test_that("correctly interpolates warning", {
# Works even if method contains {
block <- "
foo <- function(x) UseMethod('foo')
`foo.{` <- function(x) 1
"
expect_snapshot(
roc_proc_text(namespace_roclet(), "
foo <- function(x) UseMethod('foo')
`foo.{` <- function(x) 1
"),
# Need to manually transform since the srcref is coming from the function;
# roc_proc_text() uses fake srcrefs for the blocks themselves
transform = function(x) gsub("file[a-z0-9]+", "<text>", x)
. <- roc_proc_text(namespace_roclet(), block),
transform = fix_srcref
)
})


test_that("can suppress the warning", {
block <- "
#' @exportS3Method NULL
Expand Down

0 comments on commit 9507c54

Please sign in to comment.