@@ -258,11 +258,13 @@ expect_condition_matching <- function(base_class,
258258 ellipsis :: check_dots_used(action = warn )
259259
260260 matcher <- cnd_matcher(
261- class %|| % base_class ,
261+ base_class ,
262+ class ,
262263 regexp ,
263264 ... ,
264265 inherit = inherit ,
265- ignore_deprecation = base_class == " warning" && identical(regexp , NA )
266+ ignore_deprecation = base_class == " warning" && identical(regexp , NA ),
267+ error_call = trace_env
266268 )
267269
268270 act <- quasi_capture(
@@ -286,13 +288,15 @@ expect_condition_matching <- function(base_class,
286288
287289# -------------------------------------------------------------------------
288290
289- cnd_matcher <- function (class , pattern = NULL , ... , inherit = TRUE , ignore_deprecation = FALSE ) {
290- if (! is_string(class )) {
291- abort(" `class` must be a single string" )
292- }
293- if (! is_string(pattern ) && ! is.null(pattern ) && ! isNA(pattern )) {
294- abort(" `pattern` must be a single string, NULL, or NA" )
295- }
291+ cnd_matcher <- function (base_class ,
292+ class = NULL ,
293+ pattern = NULL ,
294+ ... ,
295+ inherit = TRUE ,
296+ ignore_deprecation = FALSE ,
297+ error_call = caller_env()) {
298+ check_string(class , allow_null = TRUE , call = error_call )
299+ check_string(pattern , allow_null = TRUE , allow_na = TRUE , call = error_call )
296300
297301 function (cnd ) {
298302 if (! inherit ) {
@@ -303,26 +307,31 @@ cnd_matcher <- function(class, pattern = NULL, ..., inherit = TRUE, ignore_depre
303307 return (FALSE )
304308 }
305309
306- if (is.null(pattern ) || isNA(pattern )) {
307- cnd_inherits(cnd , class )
308- } else {
309- cnd_matches(cnd , class , pattern , ... )
310+ matcher <- function (x ) {
311+ if (! inherits(x , base_class )) {
312+ return (FALSE )
313+ }
314+ if (! is.null(class ) && ! inherits(x , class )) {
315+ return (FALSE )
316+ }
317+ if (! is.null(pattern ) && ! isNA(pattern )) {
318+ grepl(pattern , conditionMessage(x ), ... )
319+ } else {
320+ TRUE
321+ }
310322 }
323+ cnd_some(cnd , matcher )
311324 }
312325}
313326
327+ has_classes <- function (x , classes ) {
328+ all(classes %in% class(x ))
329+ }
330+
314331is_deprecation <- function (x ) {
315332 inherits(x , " lifecycle_warning_deprecated" )
316333}
317334
318- cnd_inherits <- function (cnd , class ) {
319- cnd_some(cnd , ~ inherits(.x , class ))
320- }
321- cnd_matches <- function (cnd , class , pattern , ... ) {
322- cnd_some(cnd , function (x ) {
323- inherits(x , class ) && grepl(pattern , conditionMessage(x ), ... )
324- })
325- }
326335cnd_some <- function (.cnd , .p , ... ) {
327336 .p <- as_function(.p )
328337
0 commit comments