Skip to content

Testthat failure due to typo in snapshot #614

Description

@morten-dreher

Hi,

thanks for maintaining stringr!

linux-gnu, R 4.5.3, stringr 1.6.0, testthat 3.3.2

When executing testthat::test_package(stringr), the following test failure occurs:

══ Failed tests ════════════════════════════════════════════════════════════════
── Failure ('test-sub.R:111:3'): bad vectorisation gives informative error ─────
Snapshot of code has changed:
old[2:10] vs new[2:10]
    str_sub(x, 1:2, 1:3)
  Condition
    Error in `str_sub()`:
-   ! Can't recycle `string` (size 2) to match `end` (size 3).
+   ! Can't recycle `start` (size 2) to match `end` (size 3).
  Code
    str_sub(x, 1:2, 1:2) <- 1:3
  Condition
    Error in `str_sub<-`:
-   ! Can't recycle `string` (size 2) to match `value` (size 3).
+   ! Can't recycle `start` (size 2) to match `value` (size 3).

The test code in test-sub is:

test_that("bad vectorisation gives informative error", {
  x <- "a"
  expect_snapshot(error = TRUE, {
    str_sub(x, 1:2, 1:3)
    str_sub(x, 1:2, 1:2) <- 1:3
  })
})

The snapshot test fails because it expects the error (in both cases) to be (specified in tests/testthat/_snaps/sub.md):

Error in `str_sub()`:
! Can't recycle `string` (size 2) to match `end` (size 3).

... which would occur if string (i.e., x in the test code) was of size 2, but the error really is (in both cases):

str_sub(x, 1:2, 1:3)

Error in `str_sub()`:
! Can't recycle `start` (size 2) to match `end` (size 3).

This seems like a typo in the snapshot file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions