Skip to content

Add tests on Linux - #702

Merged
strengejacke merged 2 commits into
mainfrom
tests_on_linux
Nov 12, 2026
Merged

strengejacke merged 2 commits into
mainfrom
tests_on_linux

Conversation

@strengejacke

@strengejacke strengejacke commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

@jmgirard What would be best practice to have vdiffr tests for both Windows and Linux? Snapshot SVG files usually slightly differ on both OS, so you can't have just one test for both OS.

@strengejacke

Copy link
Copy Markdown
Member Author

@copilot please review and check whether this is an appropriate way to add tests specifically for linux.

Copilot AI commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

@copilot please review and check whether this is an appropriate way to add tests specifically for linux.

Yes, this is functionally appropriate: the OS guard restricts the tests to Linux, and variant = "linux" keeps the Linux SVG snapshots separate. The repository already uses this variant pattern for Linux-specific vdiffr snapshots. The main tradeoff is duplicated test setup/assertions, which can drift from test-plot-facet.R; consider sharing the plot-generation code if these tests will evolve. I’d also use the repository’s usual .R extension rather than .r. Neither point invalidates the current approach.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the Linux visual regression test additions and platform-specific snapshots.

No open issues 🎉

What changed in this PR

Extends modelbased’s visual regression tests to Linux, using separate snapshot variants where rendering differs from Windows. No production code changes are included.

Changes:

  • Enables ordinal plotting tests on Linux and separates Linux-specific bracl and nnet snapshots.
  • Adds Linux-only facet plotting tests, including categorical predictors and the emmeans backend.
  • Adds Linux SVG baselines for ordinal and faceted plots.
File Description
tests/​testthat/​test-plot-ordinal.R Enables Linux execution and adds platform-specific snapshot checks.
tests/​testthat/​test-plot-facet-linux.r Adds Linux facet plotting tests.
tests/​testthat/​_snaps/​linux/​plot-ordinal/​plot-ordinal-nnet.svg Linux baseline for multinomial predictions by gender.
tests/​testthat/​_snaps/​linux/​plot-ordinal/​plot-ordinal-nnet-2.svg Linux baseline for multinomial interaction predictions.
tests/​testthat/​_snaps/​linux/​plot-ordinal/​plot-ordinal-bracl.svg Linux baseline for adjacent-category model predictions.
tests/​testthat/​_snaps/​linux/​plot-facet-linux/​plot-interaction-facets-cat-4emmeans.svg Categorical facet baseline using emmeans.
tests/​testthat/​_snaps/​linux/​plot-facet-linux/​plot-interaction-facets-cat-1.svg Categorical facet baseline without connecting lines.
tests/​testthat/​_snaps/​linux/​plot-facet-linux/​plot-interaction-facets-cat-1-lines.svg Categorical facet baseline with connecting lines.
tests/​testthat/​_snaps/​linux/​plot-facet-linux/​plot-interaction-facets-2.svg Baseline for continuous predictions with opacity grouping.
tests/​testthat/​_snaps/​linux/​plot-facet-linux/​plot-interaction-facets-10.svg Baseline for multi-factor facets with confidence bands.
tests/​testthat/​_snaps/​linux/​plot-facet-linux/​plot-interaction-facets-1.svg Baseline for two-panel interaction predictions.

Review effort: Balanced

@strengejacke
strengejacke merged commit 8daacef into main Nov 12, 2026
13 of 22 checks passed
@strengejacke
strengejacke deleted the tests_on_linux branch November 12, 2026 09:19
@jmgirard

Copy link
Copy Markdown
Contributor

Sorry I missed this

@strengejacke

Copy link
Copy Markdown
Member Author

No worries. This is still "work in progress", and this was just a test. So I still need to figure out how I can add variants of visual snapshot for windows and linux, so that testing on one system does not remove those snapshots for the other system?

@jmgirard

jmgirard commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

@strengejacke Right now the Linux facet tests live in their own file, test-plot-facet-linux.R, which is skipped on Windows, while test-plot-facet.R is skipped on Linux. The catch is that when you run the full test suite locally, testthat deletes any snapshot that no test used during that run. It doesn't do this on CI. So a full local run on Windows removes the Linux facet snapshots, and a full run on Linux removes the Windows ones. I tried this on a small test package to be sure.

The fix is to use one expect_doppelganger() call per plot and let the variant argument depend on the OS. testthat then sees the same snapshot name on both systems and keeps both copies. That's also why test-plot-ordinal.R doesn't have this problem, because its Windows and Linux blocks are in the same file and use the same names.

You'd add a helper to tests/testthat/helper.R:

snapshot_variant <- function() {
  if (identical(Sys.info()[["sysname"]], "Linux")) "linux" else NULL
}

and each call in test-plot-facet.R becomes:

vdiffr::expect_doppelganger(
  "plot-interaction-facets-1",
  plot(pr, show_data = FALSE),
  variant = snapshot_variant()
)

Then we'd remove "linux" from that file's skip_on_os(), delete test-plot-facet-linux.R, and move the Linux SVGs from _snaps/linux/plot-facet-linux/ to _snaps/linux/plot-facet/. The Windows snapshots stay where they are. The same approach would also let test-plot-ordinal.R drop its duplicated Linux block.

Want me to open a PR for this?

@strengejacke

Copy link
Copy Markdown
Member Author

Sounds good! But I would wait for #704 (and #705) to be resolved first.

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 this pull request may close these issues.

4 participants