insightsengineering / cards

CDISC Analysis Results Data
https://insightsengineering.github.io/cards/
24 stars 0 forks source link

How best to test messages from other pkgs? #225

Closed ddsjoberg closed 2 months ago

ddsjoberg commented 2 months ago

When we process selectors we have an error message that wraps the dplyr::select() error message. But we don't want a change in another package's error message to "break" cards (and more likely cardx).

In this example from cards, we have different messaging from dplyr v1.1.4 to v1.1.3. (The word 'subset' was changed to 'select'.)

── Failure ('test-process_selectors.R:21:3'): process_selectors() works ────────
  Snapshot of code has changed:
  old[3:7] vs new[3:7]
    Condition
      Error:
      ! Error processing `variables` argument.
  -   ! Can't select columns that don't exist. x Column `not_a_column` doesn't exist.
  +   ! Can't subset columns that don't exist. x Column `not_a_column` doesn't exist.
      i Select among columns "mpg", "cyl", "disp", "hp", "drat", "wt", "qsec", "vs", "am", "gear", and "carb"

How best to test messaging, but also not rely on small messaging changes in another package? 🤔

Melkiades commented 2 months ago

I think it is not possible to avoid using snapshots for errors. With expect_error, you can grep the error message or just expect an error. If it is an error from another package, I argue we do not care too much about its form as far as it is happening. I would use only expect_error