Skip to content

Add tests for the documented error paths - #66

Merged
dmccoystephenson merged 1 commit into
masterfrom
feature/error-path-tests
Oct 29, 2026
Merged

dmccoystephenson merged 1 commit into
masterfrom
feature/error-path-tests

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

Stage B (unit-test expansion) cycle. No open issues existed at triage, so the cycle was spent on test coverage. README's ## Errors section documents several std::runtime_error throw paths, and before this PR no test in src/tests.cpp exercised any of them (there was no try/catch anywhere in the suite).

Five characterization tests are added to src/tests.cpp and registered in main():

  • Test 48: Environment::getFirstEntity throws on an empty environment.
  • Test 49: Environment::getEntity throws for an unknown id, and the message names the requested id, the environment, and the ids that were found (found: 3, ).
  • Test 50: Grid::getLocation and Grid::getLocationByCoordinates throw when nothing matches (including an off-grid coordinate).
  • Test 51: Environment::moveEntityToNewLocation with an unknown location id throws and leaves the entity's ids, placement and the entity count unchanged.
  • Test 52: moveEntityToNewLocation and a directional move (moveEntityUp) throw for an entity id that is not in the environment.

The tests assert the current behaviour only. No production code is changed, and each assertion was checked against src/environment.cpp and src/grid.cpp before it was written. <stdexcept> is now included directly in src/tests.cpp.

No tracking issue: the coverage gap was found during triage.

Test plan

  • make compiles cleanly locally
  • CI "Library tests" job runs run_tests.sh and every test through Test 52 prints --- Success (local execution of tests_executable is denied in this sandbox, so CI is the anchor)

This PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).

🤖 Generated with Claude Code


drafted by Claude on behalf of Daniel Stephenson

Characterize the runtime_error throws listed in README's Errors
section: getFirstEntity on an empty environment, getEntity on an
unknown id (including the found-ids message), Grid::getLocation and
getLocationByCoordinates with no match, and moveEntityToNewLocation /
directional moves with an unknown entity or location id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dmccoystephenson

Copy link
Copy Markdown
Member Author

Self-review rubric (anchor: CI "Library tests (make + CMake)" job, run 40826748536, where Tests 1–52 each printed --- Success and ctest reported 100% tests passed; local execution of tests_executable is denied in this sandbox, so CI was used as the anchor):

  • Scope: PASS. Only src/tests.cpp is modified (+99 lines: five test functions, five main() registrations, one #include <stdexcept>).
  • Tests-new: PASS. No public method was added; the five tests cover the throw paths listed in README's ## Errors section, which had no coverage before.
  • Tests-fix: N/A. No bug fix is included, and the tests only characterize behaviour (no production code was changed).
  • Sibling structure: PASS. Each test follows the existing Test N - <description> / --- Success pattern, and the numbering continues from Test 47.
  • Sibling renames: N/A. Nothing was renamed.
  • Docs: PASS. README's ## Errors claims were checked against src/environment.cpp and src/grid.cpp and are now asserted by the tests. No behaviour changed, so no README edit is needed.
  • Issue resolution: N/A. No Closes #N; the gap was found during triage.
  • Local test suite: PASS. The CI log shows Tests 48–52 executed and succeeded, and the Strata and Web build jobs are green too.
  • Header/definition parity: N/A. No header was touched.
  • Include guards: N/A. No new header.
  • Test registration: PASS. All five new functions are called from main(), and their output appears in the CI log.

Observation: src/tests.cpp — six of the seven new catch (const std::runtime_error& e) blocks never use e. This is harmless under the current g++ invocation (no warning flags), but catch (const std::runtime_error&) would be tidier. It was left as-is for consistency across the new tests.

This review was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson
dmccoystephenson merged commit 2ef4894 into master Oct 29, 2026
3 checks passed
@dmccoystephenson
dmccoystephenson deleted the feature/error-path-tests branch October 29, 2026 06:05
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.

1 participant