refactor: standardize error snapshot testing with expect_snapshot_igraph_error()#2528
Merged
refactor: standardize error snapshot testing with expect_snapshot_igraph_error()#2528
expect_snapshot_igraph_error()#2528Conversation
…o separate file Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix error message formatting in C tests
refactor: standardize error snapshot testing with Jan 24, 2026
expect_snapshot_igraph_error()
krlmlr
requested changes
Jan 24, 2026
tests/testthat/test-flow.R
Outdated
| expect_snapshot_igraph_error(st_cuts(g_path, source = NULL, target = "a")) | ||
| expect_snapshot( | ||
| st_min_cuts(g_path, source = "a", target = NULL), | ||
| error = TRUE |
Contributor
There was a problem hiding this comment.
Look harder for usages where error = TRUE is on a separate line.
Contributor
Author
There was a problem hiding this comment.
Fixed in 4a4a599. Found and transformed 10 additional occurrences where error = TRUE was on a separate line in: test-flow.R (4), test-conversion.R (2), test-foreign.R (2), test-make.R (1), test-minimum.spanning.tree.R (1), test-other.R (1), test-utils-assert-args.R (1). All tests pass.
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Contributor
Author
There was a problem hiding this comment.
Pull request overview
This PR standardizes error snapshot testing across the test suite by introducing a consistent helper function and isolating test infrastructure for better stability.
Changes:
- Replaced 67 occurrences of
expect_snapshot(error = TRUE)withexpect_snapshot_igraph_error()across 24 test files, ensuring line numbers in error messages are normalized toxxfor stability - Moved the test error function
Rx_igraph_test_error_with_source()fromrinterface_extra.cto a dedicated filetest_error_with_source.cto prevent unrelated changes from invalidating error line number tests - Added explanatory comment in
test-error-formatting.Rdocumenting why it retainsexpect_snapshot(error = TRUE)(needs actual line numbers for validation)
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/testthat/test-versions.R | Converted 8 error snapshot tests to use standardized helper |
| tests/testthat/test-utils-assert-args.R | Converted 1 multi-line error snapshot to single-line helper call |
| tests/testthat/test-structural-properties.R | Converted 2 deprecated argument tests to use standardized helper |
| tests/testthat/test-plot.R | Converted 1 layout error test to use standardized helper |
| tests/testthat/test-other.R | Converted 2 error snapshots to use standardized helper |
| tests/testthat/test-minimum.spanning.tree.R | Converted 1 algorithm error test to use standardized helper |
| tests/testthat/test-make.R | Converted 4 error snapshot tests to use standardized helper |
| tests/testthat/test-layout.R | Converted 3 layout error tests to use standardized helper |
| tests/testthat/test-iterators.R | Converted 2 logical index tests to use standardized helper |
| tests/testthat/test-interface.R | Converted 3 error tests to use standardized helper |
| tests/testthat/test-incidence.R | Converted 4 biadjacency matrix error tests to use standardized helper |
| tests/testthat/test-hrg.R | Converted 2 argument validation tests to use standardized helper |
| tests/testthat/test-foreign.R | Converted 5 file format error tests to use standardized helper |
| tests/testthat/test-flow.R | Converted 11 flow algorithm error tests to use standardized helper |
| tests/testthat/test-fit.R | Converted 1 power law fitting error test to use standardized helper |
| tests/testthat/test-error-formatting.R | Added explanatory comment for retaining expect_snapshot(error = TRUE) |
| tests/testthat/test-conversion.R | Converted 5 conversion error tests to use standardized helper |
| tests/testthat/test-centrality.R | Converted 1 arpack error test to use standardized helper |
| tests/testthat/test-attributes.R | Converted 9 attribute error tests to use standardized helper |
| tests/testthat/test-adjacency.R | Converted 1 adjacency matrix NA test to use standardized helper |
| tests/testthat/_snaps/error-formatting.md | Updated snapshot to reflect new source location (test_error_with_source.c:31) |
| src/test_error_with_source.c | New dedicated file containing isolated test error function |
| src/test_error_with_source.dd | Build dependency file for new test source file |
| src/sources-glue-c.mk | Updated build configuration to include new test source file |
| src/rinterface_extra.c | Removed test error function (moved to dedicated file) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses review feedback from #2515 to improve consistency and stability of error message testing.
Changes
Standardized error snapshots: Replaced 67 occurrences of
expect_snapshot(error = TRUE)withexpect_snapshot_igraph_error()across 24 test files. This ensures line numbers in error messages are normalized toxxfor stability. Includes both single-line and multi-line patterns whereerror = TRUEappeared on a separate line.Isolated test function: Moved
Rx_igraph_test_error_with_source()fromrinterface_extra.c(line 7766) to dedicated filetest_error_with_source.c(line 31). Prevents unrelated changes from invalidating error line number tests.Exception documented: Added comment in
test-error-formatting.Rexplaining why it retainsexpect_snapshot(error = TRUE)- needs actual line numbers for validation.Technical Notes
Updated
sources-glue-c.mkto include new C file in build. Snapshot updated to reflect new source location.Note: test-games.R retains 2 instances of
expect_snapshot(error = TRUE)with customtransformfunctions that would conflict with the built-in transform inexpect_snapshot_igraph_error().Testing
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.