Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add service locator, setup unit tests. #19

Merged
merged 4 commits into from
Jan 28, 2024
Merged

Add service locator, setup unit tests. #19

merged 4 commits into from
Jan 28, 2024

Conversation

karnkaul
Copy link
Member

@karnkaul karnkaul commented Jan 28, 2024

Motivation: https://gameprogrammingpatterns.com/service-locator.html

Unit tests are generally a separate executable, but to achieve that here we would have to move all the game code into a library that both the game exe and unit tests exe can link to.
Instead, here we bundle unit tests into the game exe itself, and add a command line switch to run them instead of the game. Keep the project simple at the cost of binary bloat.

To add unit tests, simply create a cpp file in src/tests and use the ADD_TEST macro from src/tests/test.hpp. See test_services.cpp for a working example.

Running the unit tests:

  • Manually:
DogTales[.exe] --run-tests
DogTales[.exe] -t
  • CTest:
cd out/ubsan # CMake build directory
ctest -C Debug
  • IDE: On VSCode click the Tests icon on the left toolbar.

- Move test framework into exe target.
- Add CLI option to run tests instead of the game.

Unit tests should ideally be in a separate executable, but that would require refactoring all the code into a library that both the game exe and unit tests exe would link to. This monolithic approach keeps things simple at the cost of game binary bloat.
- Decouple concrete type from mapped/bound type.
- Use a class to own stored service instances.
@karnkaul karnkaul marked this pull request as ready for review January 28, 2024 18:55
@karnkaul karnkaul requested review from Legac3e and A-rms January 28, 2024 18:56
@A-rms
Copy link
Collaborator

A-rms commented Jan 28, 2024

Approved :).

@A-rms A-rms merged commit 3ac64c5 into main Jan 28, 2024
2 checks passed
@A-rms A-rms deleted the karnage/services branch January 28, 2024 21:03
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