Skip to content

Adds some headless roommatrix tests#161

Merged
LiquidityC merged 2 commits intodevfrom
headless_roommatrix_test
Mar 14, 2026
Merged

Adds some headless roommatrix tests#161
LiquidityC merged 2 commits intodevfrom
headless_roommatrix_test

Conversation

@LiquidityC
Copy link
Member

@LiquidityC LiquidityC commented Mar 14, 2026

Summary by CodeRabbit

  • Tests
    • Added comprehensive unit test suite for room matrix surrounding-space functionality, validating behavior across multiple scenarios including fully open spaces, occupied tiles, lethal tiles, and corner positions. Tests configured for automated validation.

@coderabbitai
Copy link

coderabbitai bot commented Mar 14, 2026

📝 Walkthrough

Walkthrough

A new unit test suite for RoomMatrix surrounding-space logic is introduced via CMake configuration and test implementation, complete with SDL offscreen rendering setup and four test scenarios validating space computation behavior.

Changes

Cohort / File(s) Summary
Build Configuration
test/CMakeLists.txt
Adds test_roommatrix executable target with source files and linked libraries (cmocka, SDL, SDL_image, SDL_ttf, physfs). Configures environment variables for offscreen SDL rendering and registers test execution.
Unit Test Implementation
test/test_roommatrix.c
Introduces 144 lines of cmocka-based unit tests validating RoomMatrix surrounding-space logic. Includes test harness setup/teardown (SDL/window/renderer initialization), and four test cases covering all-open spaces, occupied tile exclusion, lethal tile exclusion, and corner position scenarios.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 New tests hop into the warren so bright,
Checking surrounding spaces with all their might,
SDL renders offscreen, no flicker or fuss,
Four scenarios tested—room logic for us! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Adds some headless roommatrix tests' accurately describes the main change—adding new unit tests for the roommatrix module with headless/offscreen SDL configuration.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch headless_roommatrix_test
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@LiquidityC LiquidityC enabled auto-merge (squash) March 14, 2026 22:44
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
test/test_roommatrix.c (2)

52-57: Consider checking malloc return for NULL.

While unlikely to fail in a test environment, adding a NULL check aligns with defensive coding practices.

 	TestState *s = malloc(sizeof(TestState));
+	if (!s) {
+		SDL_DestroyRenderer(renderer);
+		SDL_DestroyWindow(window);
+		SDL_Quit();
+		return -1;
+	}
 	s->window   = window;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/test_roommatrix.c` around lines 52 - 57, Check the return value from
malloc when allocating TestState in the test setup (the allocation into variable
TestState *s) and handle NULL: after TestState *s = malloc(sizeof(TestState));
verify s != NULL and on failure report the error and abort the test (e.g., call
a test-failure/cleanup path or exit with a descriptive message), ensuring you do
not dereference s or call roommatrix_create(renderer) if allocation failed.

103-118: LGTM, consider adding coverage for TILE_DAMAGE.

The test correctly validates lethal tile exclusion. Per SPACE_IS_WALKABLE macro in src/roommatrix.h:58, TILE_DAMAGE is also checked but not covered by the current test suite. Consider adding a similar test for completeness.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/test_roommatrix.c` around lines 103 - 118, Add a new test mirroring
test_surrounding_lethal_excluded that sets TILE_DAMAGE on an adjacent space and
verifies roommatrix_get_surrounding_spaces excludes it; use the same pattern
with SPACE_SET_FLAG(&rm->spaces[x][y], TILE_DAMAGE), call
roommatrix_get_surrounding_spaces with the same center position, assert the
returned count matches expected (8), and then clear the flag with
SPACE_CLEAR_FLAG(&rm->spaces[x][y], TILE_DAMAGE); this exercises the
SPACE_IS_WALKABLE logic that checks TILE_DAMAGE.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/test_roommatrix.c`:
- Line 2: The file header comment contains a typo "dungeone" in the string
"BreakHack - A dungeone crawler RPG"; update that comment to read "BreakHack - A
dungeon crawler RPG" (search for the header/comment line containing "BreakHack -
A dungeone" to locate the exact spot).

---

Nitpick comments:
In `@test/test_roommatrix.c`:
- Around line 52-57: Check the return value from malloc when allocating
TestState in the test setup (the allocation into variable TestState *s) and
handle NULL: after TestState *s = malloc(sizeof(TestState)); verify s != NULL
and on failure report the error and abort the test (e.g., call a
test-failure/cleanup path or exit with a descriptive message), ensuring you do
not dereference s or call roommatrix_create(renderer) if allocation failed.
- Around line 103-118: Add a new test mirroring test_surrounding_lethal_excluded
that sets TILE_DAMAGE on an adjacent space and verifies
roommatrix_get_surrounding_spaces excludes it; use the same pattern with
SPACE_SET_FLAG(&rm->spaces[x][y], TILE_DAMAGE), call
roommatrix_get_surrounding_spaces with the same center position, assert the
returned count matches expected (8), and then clear the flag with
SPACE_CLEAR_FLAG(&rm->spaces[x][y], TILE_DAMAGE); this exercises the
SPACE_IS_WALKABLE logic that checks TILE_DAMAGE.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6df75c9d-ee95-40c4-b07b-3c82ab209ef9

📥 Commits

Reviewing files that changed from the base of the PR and between b3d0d81 and 2faa13b.

📒 Files selected for processing (2)
  • test/CMakeLists.txt
  • test/test_roommatrix.c

@@ -0,0 +1,144 @@
/*
* BreakHack - A dungeone crawler RPG
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Typo: "dungeone" should be "dungeon".

- * BreakHack - A dungeone crawler RPG
+ * BreakHack - A dungeon crawler RPG
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
* BreakHack - A dungeone crawler RPG
* BreakHack - A dungeon crawler RPG
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/test_roommatrix.c` at line 2, The file header comment contains a typo
"dungeone" in the string "BreakHack - A dungeone crawler RPG"; update that
comment to read "BreakHack - A dungeon crawler RPG" (search for the
header/comment line containing "BreakHack - A dungeone" to locate the exact
spot).

@LiquidityC LiquidityC merged commit ad593be into dev Mar 14, 2026
13 checks passed
@LiquidityC LiquidityC deleted the headless_roommatrix_test branch March 14, 2026 22:56
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