Skip to content

snapshot transform "leaves a trace" when returning character(0)? #1487

@MichaelChirico

Description

@MichaelChirico

I am trying to deal with some Windows-specific output issues while converting to snapshot tests:

MichaelChirico/potools#257, as of 8558cf2479195e41a783677c4141eebf933a7a05

To deal with some output that is not produced on Windows, I wrote this helper:

normalize_output <- function(x) {
  # different platforms/installations of gettext apparently
  #   produce a different number of "." in "progress" output; normalize
  x <- gsub("\\.{2,}", ".", x)

  # en@quot translations are not produced on Windows (as of now)
  x <- grep("Generating en@quot translations", x, fixed = TRUE, invert = TRUE, value = TRUE)

  # this is produced alongside the previous message, but in a different iteration of transform()
  idx <- grep("running msgfmt on (?:R-)?en@quot\\.po", x)
  if (length(idx)) {
    browser()
    x <- x[-(idx + 0:1)]
  }
  x
}

Whenever either of the grep() match the snapshot input x, the resulting output x is character() (confirmed by browser()-ing normalize_output() while running tests interactively). That is as intended -- I want the snapshot to act as if that output was never produced, in order to imitate the corresponding output on Windows.

However, on Windows, my CI build still fails:

https://github.com/MichaelChirico/potools/runs/4174597881?check_suite_focus=true

-- Failure (test-translate-package.R:101:1): (code run outside of `test_that()`) --
Snapshot of code has changed:
old[2:8] vs new[2:7]
  "  translate_package(languages = \"cy\")"
  "Message <simpleMessage>"
  "  Writing R-rMsg.pot"
- "  "
  "  'cy' is not a known language. "
  "  Please help supply some metadata about it. You can check https://l10n.gnome.org/teams/<language>"
  "Output"

It seems - " " is a residual line left after running normalize_output(). Either that, or the " " line is not supplied to transform() and thus not available to remove. Either way, it seems I have no way of matching my local snapshot to that produced on Windows CI.

Laterally, is it feasible to support Windows/platform-specific snapshots? Windows in particular seems potentially fruitful given how much the Windows/non-Windows builds of R already differ (terminal access, file paths, etc). I'd rather not use skip_on_os('windows') (e.g., the same failing tests seem to be showing me some encoding issues that I need to fix, so keeping the snapshots running on windows would be ideal).

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