Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expect_condition() #621

Closed
lionel- opened this Issue Sep 18, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@lionel-
Copy link
Member

lionel- commented Sep 18, 2017

expect_condition <- function(expr,
                             class = NULL,
                             regex = NULL,
                             ...,
                             info = NULL,
                             label = NULL) {
  object <- tryCatch(expr, condition = identity)

  if (is_na(class)) {
    expect_false(inherits(object, "condition"), info = info, label = label)
    return(invisible(object))
  }

  expect_is(object, "condition", info = info, label = label)

  if (!is_null(class)) {
    expect_is(object, class, info = info, label = label)
  }
  if (!is_null(regex)) {
    expect_match(object$message, regex, ..., info = info, label = label)
  }

  invisible(object)
}

@hadley hadley changed the title Utils for conditions expect_condition Oct 1, 2017

@hadley hadley changed the title expect_condition expect_condition() Oct 2, 2017

@hadley

This comment has been minimized.

Copy link
Member

hadley commented Oct 3, 2017

Should use the same basic approach for expect_error().

It's a bit painful to implement because each expect_ function should only call expect() once, and there's currently no great way to compose multiple expectations.

@hadley

This comment has been minimized.

Copy link
Member

hadley commented Oct 6, 2017

The main challenge here is that these expectations call expect_match() and it's not readily composable. I think pull out a common lower-level line comparison function will help (and will also improve the error messages).

hadley added a commit that referenced this issue Oct 9, 2017

Convert output expectations
Includes some refactoring of expect_error in expectation of #621

hadley added a commit that referenced this issue Oct 10, 2017

Convert output expectations
Includes some refactoring of expect_error in expectation of #621

hadley added a commit that referenced this issue Oct 10, 2017

Convert output expectations
Includes some refactoring of expect_error in expectation of #621

hadley added a commit that referenced this issue Oct 10, 2017

Implement unquoting for automatically generated labels (#637)
* Implement `quasi_label()` as a exported developer facing function 
* Convert `expect_*` to use it

Includes some refactoring:
* Improvements to expect_error in advance of #621
* Add capture_message and capture_warning
* Rename capture_first_expectation to  capture_expectation and export
* Correctly spell expect_condition
* Improve skip_if_not_installed message

Fixes #626. Closes #524.

@hadley hadley closed this in 11833e5 Oct 10, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.