Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MichaelChirico opened this issue Nov 11, 2021 · 1 comment · Fixed by #1489
Closed

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

MichaelChirico opened this issue Nov 11, 2021 · 1 comment · Fixed by #1489

Comments

@MichaelChirico
Copy link
Contributor

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).

@hadley
Copy link
Member

hadley commented Nov 11, 2021

I'll take a look at the character() issue when I'm next working on testthat.

For the windows build challenge, you could try using a variant — when you set variant, the snapshot is created in _snaps/{variant}/{test}.md instead of _snaps/{test}.md so you could maybe use .Platform$OS.type? The key challenge is getting the variant snapshots back into your local repo. Variants are new so we don't yet have any automation around retrieving them from (e.g.) GHA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants