Skip to content

Conversation

@culix-7
Copy link

@culix-7 culix-7 commented Jan 4, 2026

Hello, thank you very much for creating and sharing Mesen. It is excellent.

Would it be helpful if I offer to add some tests to the Mesen codebase? Would that make refactoring or bugfixing any easier, if we can have some confidence about parts of the codebase not breaking?

As a proof of concept I created some simple tests for the CodeDataLogger class.

Overall the CodeDataLogger works well. The tests I wrote confirm that it has correct behaviour and always does the right thing.
I created an integration test that creates a new CodeDataLogger, marks some bytes and code and data, saves the file to disk, and then reads and loads the file. It is able to confim the data is what we expect.

I was able to also create a few tests that cause CodeDataLogger to crash or die in unlikely scenarios - basically by passing in nullptr or invalid lengths and offsets that cause it to read outside of normal memory bounds.
These are unlikely scenarios. But I added a few bounds checks and null checks just to make the class more robust.

The most difficult part of creating the tests was not anything about writing the tests themselves - it was getting the new project set up and configured correctly in Visual Studio. So I thought that sharing a new test project with any small number of tests added might create a useful starting point. Anyone can then add more tests more easily for any part of the code that they want.

Thank you for your time.

Before:

mesen_cdl_tests_before_several_failing

culix-7 added 22 commits January 4, 2026 13:49
needed to build Utilities reference for Core.Test project.
fixes:

```
unresolved external symbol __imp_timeBeginPeriod
unresolved external symbol __imp_timeEndPeriod
```
so test project can find the output files it needs
add a simple nullcheck wrapper around the `debugger` instance,
to make it easy to test this class
without having to mock or implement the full Debugger class.

add simple constructor checks
write docstring to clarify return values
then fix them so they pass all tests
the full workflow of: create, mark bytes, save, load works.
technically if you have a `_memSize` bigger than the size of max int,
then `i` would overflow and wrap, leading to bad things.

That's probably unlikely, since you likely won't have a ROM file
of size > max int.
But this is more correct and costs nothing, so we might as well fix it.
@culix-7 culix-7 changed the title Add Core.Test c++ test project; add tests for CodeDataLogger 3. Add Core.Test c++ test project; add tests for CodeDataLogger Jan 9, 2026
@culix-7 culix-7 marked this pull request as draft January 9, 2026 14:23
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