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 testImport and mockImport #1

Open
PhilippMDoerner opened this issue Dec 27, 2022 · 1 comment
Open

Add testImport and mockImport #1

PhilippMDoerner opened this issue Dec 27, 2022 · 1 comment

Comments

@PhilippMDoerner
Copy link
Owner

The idea is that your source code no longer has to be changed. You don't test your source-code, you test a modified copy that allows mocking.

How so?

All modules imported via mockImport get read in, modified as they would be in mocker.nim (so that the exported procs get the mockable pragma attached) and that modified copy gets written to "testDirectory".
You then import that modified copy in the test.

All modules imported via testImport get read in, modified in the sense that their imports no longer point to the source code, but instead to the modified copies and that modified testImport-ed module gets also written to "testDirectory".
You then import that modified copy in the test.

Tests get written for the procs of the testImport-ed module. This means you are no longer actually testing source-code, but near identical code, that should be similar enough.
If that isn't good enough for the user though, they can instead just use mockable themselves in their source code and work with that.

@PhilippMDoerner
Copy link
Owner Author

Change of approach.

Provide a module that people can import into their config.nims of their testfile.
This module provides procs that do the following:

  • Copy all files in the src dir into a user-specified folder
  • If they are nim files, analyze them before copying and add the {.mockable.} pragma to all exported procs in a module
  • Change the import path from src to the user-specified folder with the modified copy of the src dir

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

No branches or pull requests

1 participant