nealrichardson commented on a change in pull request #9909:
URL: https://github.com/apache/arrow/pull/9909#discussion_r610751324



##########
File path: r/tests/testthat/helper-expectation.R
##########
@@ -98,12 +103,34 @@ expect_dplyr_equal <- function(expr, # A dplyr pipeline 
with `input` as its star
 expect_dplyr_error <- function(expr, # A dplyr pipeline with `input` as its 
start
                                tbl,  # A tbl/df as reference, will make 
RB/Table with
                                ...) {
+  # ensure we have supplied tbl
+  force(tbl)
+  
   expr <- rlang::enquo(expr)
   msg <- tryCatch(
     rlang::eval_tidy(expr, rlang::new_data_mask(rlang::env(input = tbl))),
-    error = function (e) conditionMessage(e)
+    error = function (e) {
+          msg <- conditionMessage(e)

Review comment:
       This line appears oddly indented

##########
File path: r/tests/testthat/helper-expectation.R
##########
@@ -98,12 +103,34 @@ expect_dplyr_equal <- function(expr, # A dplyr pipeline 
with `input` as its star
 expect_dplyr_error <- function(expr, # A dplyr pipeline with `input` as its 
start
                                tbl,  # A tbl/df as reference, will make 
RB/Table with
                                ...) {
+  # ensure we have supplied tbl
+  force(tbl)
+  
   expr <- rlang::enquo(expr)
   msg <- tryCatch(
     rlang::eval_tidy(expr, rlang::new_data_mask(rlang::env(input = tbl))),
-    error = function (e) conditionMessage(e)
+    error = function (e) {
+          msg <- conditionMessage(e)
+
+      # The error here is of the form:
+      #
+      # Problem with `filter()` input `..1`.
+      # x object 'b_var' not found
+      # ℹ Input `..1` is `chr == b_var`.
+      #
+      # but what we really care about is the `x` block
+      # so (temporarily) let's pull those blocks out when we find them
+      if (grepl("object '.*'.not.found", msg)) {
+        return(gsub("^.*(object '.*'.not found).*$", "\\1", msg))
+      }
+      if (grepl('could not find function ".*"', msg)) {
+        return(gsub('^.*(could not find function ".*").*$', "\\1", msg))
+      }
+      invisible(structure(msg, class = "try-error", condition = e))

Review comment:
       How about this? Uses the same regex pattern we already have encoded for 
this elsewhere.
   
   ```suggestion
         pattern <- i18ize_error_messages()
         if (grepl(pattern, msg)) {
           msg <- sub(paste0("^.*(", pattern, ").*$"), "\\1", msg))
         }
         msg
   ```

##########
File path: r/tests/testthat/helper-expectation.R
##########
@@ -98,12 +103,34 @@ expect_dplyr_equal <- function(expr, # A dplyr pipeline 
with `input` as its star
 expect_dplyr_error <- function(expr, # A dplyr pipeline with `input` as its 
start
                                tbl,  # A tbl/df as reference, will make 
RB/Table with
                                ...) {
+  # ensure we have supplied tbl
+  force(tbl)
+  
   expr <- rlang::enquo(expr)
   msg <- tryCatch(
     rlang::eval_tidy(expr, rlang::new_data_mask(rlang::env(input = tbl))),
-    error = function (e) conditionMessage(e)
+    error = function (e) {
+          msg <- conditionMessage(e)
+
+      # The error here is of the form:
+      #
+      # Problem with `filter()` input `..1`.
+      # x object 'b_var' not found
+      # ℹ Input `..1` is `chr == b_var`.
+      #
+      # but what we really care about is the `x` block
+      # so (temporarily) let's pull those blocks out when we find them
+      if (grepl("object '.*'.not.found", msg)) {
+        return(gsub("^.*(object '.*'.not found).*$", "\\1", msg))
+      }
+      if (grepl('could not find function ".*"', msg)) {
+        return(gsub('^.*(could not find function ".*").*$', "\\1", msg))
+      }
+      invisible(structure(msg, class = "try-error", condition = e))
+    }
   )
-  expect_is(msg, "character", label = "dplyr on data.frame did not error")
+  # make sure msg is a character object (i.e. there has been an error)
+  expect_type(msg, "character")

Review comment:
       ```suggestion
     # If it did not error, we would get a data.frame or whatever
     # This expectation will tell us "dplyr on data.frame errored is not TRUE"
     expect_true(identical(typeof(msg), "character"), label = "dplyr on 
data.frame errored")
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to