Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
39 changes: 0 additions & 39 deletions R/expect-equality.R
Original file line number Diff line number Diff line change
Expand Up @@ -201,42 +201,3 @@ expect_equivalent <- function(
}
pass(act$val)
}


#' Does code return a reference to the expected object?
#'
#' `expect_reference()` compares the underlying memory addresses of
#' two symbols. It is for expert use only.
#'
#' @section 3rd edition:
#' `r lifecycle::badge("deprecated")`
#'
#' `expect_reference()` is deprecated in the third edition. If you know what
#' you're doing, and you really need this behaviour, just use `is_reference()`
#' directly: `expect_true(rlang::is_reference(x, y))`.
#'
#' @inheritParams expect_equal
#' @family expectations
#' @keywords internal
#' @export
expect_reference <- function(
object,
expected,
info = NULL,
label = NULL,
expected.label = NULL
) {
edition_deprecate(3, "expect_reference()")

act <- quasi_label(enquo(object), label, arg = "object")
exp <- quasi_label(enquo(expected), expected.label, arg = "expected")

if (!is_reference(act$val, exp$val)) {
msg <- sprintf("%s not a reference to %s.", act$lab, exp$lab)
return(fail(msg, info = info))
}
pass(act$val)
}

# expect_reference() needs dev version of rlang
utils::globalVariables("is_reference")
File renamed without changes.
37 changes: 37 additions & 0 deletions R/expect-reference.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#' Does code return a reference to the expected object?
#'
#' `expect_reference()` compares the underlying memory addresses of
#' two symbols. It is for expert use only.
#'
#' @section 3rd edition:
#' `r lifecycle::badge("deprecated")`
#'
#' `expect_reference()` is deprecated in the third edition. If you know what
#' you're doing, and you really need this behaviour, just use `is_reference()`
#' directly: `expect_true(rlang::is_reference(x, y))`.
#'
#' @inheritParams expect_equal
#' @family expectations
#' @keywords internal
#' @export
expect_reference <- function(
object,
expected,
info = NULL,
label = NULL,
expected.label = NULL
) {
edition_deprecate(3, "expect_reference()")

act <- quasi_label(enquo(object), label, arg = "object")
exp <- quasi_label(enquo(expected), expected.label, arg = "expected")

if (!is_reference(act$val, exp$val)) {
msg <- sprintf("%s not a reference to %s.", act$lab, exp$lab)
return(fail(msg, info = info))
}
pass(act$val)
}

# expect_reference() needs dev version of rlang
utils::globalVariables("is_reference")
2 changes: 1 addition & 1 deletion man/expect_match.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/expect_reference.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/testthat_examples.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions tests/testthat/test-browser.R

This file was deleted.

File renamed without changes.
5 changes: 5 additions & 0 deletions tests/testthat/test-expect-constant.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ test_that("expect_null works", {
expect_snapshot_failure(expect_null(1L))
expect_snapshot_failure(expect_null(environment()))
})

test_that("returns the input value", {
res <- expect_true(TRUE)
expect_equal(res, TRUE)
})
Empty file.
5 changes: 0 additions & 5 deletions tests/testthat/test-expect-that.R

This file was deleted.

4 changes: 0 additions & 4 deletions tests/testthat/test-expect_that.R

This file was deleted.

15 changes: 0 additions & 15 deletions tests/testthat/test-label.R

This file was deleted.

7 changes: 7 additions & 0 deletions tests/testthat/test-local.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,10 @@ test_that("can force cli to display RStudio style hyperlinks", {
str(cli::ansi_hyperlink_types())
})
})

test_that("browser() usages are errors in tests", {
skip_if(getRversion() < "4.3.0")
if (!interactive()) {
expect_error(browser())
}
})
16 changes: 16 additions & 0 deletions tests/testthat/test-quasi-label.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ test_that("other inlined other objects are deparsed", {
)
})

test_that("labelling compound {} expression gives single string", {
out <- expr_label(quote({
1 + 2
}))

expect_length(out, 1)
expect_type(out, "character")
})

test_that("can label multiline functions", {
expect_equal(
expr_label(quote(function(x, y) {})),
"function(x, y) ..."
)
})

test_that("informative error for missing arg", {
expect_snapshot(error = TRUE, expect_equal())
})
24 changes: 24 additions & 0 deletions tests/testthat/test-source.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,27 @@ test_that("errors if duplicate labels", {

expect_snapshot(filter_desc(code, "baz"), error = TRUE)
})

test_that("source_dir()", {
res <- source_dir("test_dir", pattern = "hello", chdir = TRUE, wrap = FALSE)
expect_equal(res[[1]](), "Hello World")

res <- source_dir(
normalizePath("test_dir"),
pattern = "hello",
chdir = TRUE,
wrap = FALSE
)
expect_equal(res[[1]](), "Hello World")

res <- source_dir("test_dir", pattern = "hello", chdir = FALSE, wrap = FALSE)
expect_equal(res[[1]](), "Hello World")

res <- source_dir(
normalizePath("test_dir"),
pattern = "hello",
chdir = FALSE,
wrap = FALSE
)
expect_equal(res[[1]](), "Hello World")
})
23 changes: 0 additions & 23 deletions tests/testthat/test-source_dir.R

This file was deleted.

File renamed without changes.
Loading