Skip to content

refactor: standardize error snapshot testing with expect_snapshot_igraph_error()#2528

Merged
krlmlr merged 5 commits intobetterfrom
copilot/sub-pr-2515
Jan 24, 2026
Merged

refactor: standardize error snapshot testing with expect_snapshot_igraph_error()#2528
krlmlr merged 5 commits intobetterfrom
copilot/sub-pr-2515

Conversation

Copy link
Contributor

Copilot AI commented Jan 24, 2026

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) with expect_snapshot_igraph_error() across 24 test files. This ensures line numbers in error messages are normalized to xx for stability. Includes both single-line and multi-line patterns where error = TRUE appeared on a separate line.

  • Isolated test function: Moved Rx_igraph_test_error_with_source() from rinterface_extra.c (line 7766) to dedicated file test_error_with_source.c (line 31). Prevents unrelated changes from invalidating error line number tests.

  • Exception documented: Added comment in test-error-formatting.R explaining why it retains expect_snapshot(error = TRUE) - needs actual line numbers for validation.

Technical Notes

Updated sources-glue-c.mk to 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 custom transform functions that would conflict with the built-in transform in expect_snapshot_igraph_error().

Testing

  • ✅ Full test suite run: 7,511 tests passed, 0 failed
  • ✅ All snapshots are current and accepted

  • By submitting this pull request, I assign the copyright of my contribution to The igraph development team.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits January 24, 2026 09:58
…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 expect_snapshot_igraph_error() Jan 24, 2026
Copilot AI requested a review from krlmlr January 24, 2026 10:05
Copy link
Contributor

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

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

@copilot: Good job. Also run the tests and accept snapshots when done.

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Look harder for usages where error = TRUE is on a separate line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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>
Copy link
Contributor Author

Copilot AI commented Jan 24, 2026

@copilot: Good job. Also run the tests and accept snapshots when done.

Completed in 4a4a599. Full test suite run: 7511 tests passed, 0 failed. All snapshots are current and accepted.

Copilot AI requested a review from krlmlr January 24, 2026 10:20
@krlmlr krlmlr marked this pull request as ready for review January 24, 2026 10:23
Copilot AI review requested due to automatic review settings January 24, 2026 10:23
@krlmlr krlmlr merged commit 5a93c98 into better Jan 24, 2026
@krlmlr krlmlr deleted the copilot/sub-pr-2515 branch January 24, 2026 10:23
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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) with expect_snapshot_igraph_error() across 24 test files, ensuring line numbers in error messages are normalized to xx for stability
  • Moved the test error function Rx_igraph_test_error_with_source() from rinterface_extra.c to a dedicated file test_error_with_source.c to prevent unrelated changes from invalidating error line number tests
  • Added explanatory comment in test-error-formatting.R documenting why it retains expect_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)

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.

2 participants