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

Leave module loaded state as it was #228

Merged
merged 1 commit into from
Mar 25, 2021
Merged

Conversation

zsoci
Copy link
Contributor

@zsoci zsoci commented Mar 15, 2021

No description provided.

@zsoci zsoci force-pushed the restore branch 2 times, most recently from b00b227 to 634668b Compare March 15, 2021 16:47
@eproxus
Copy link
Owner

eproxus commented Mar 18, 2021

Do you think you can add tests for this? Ideally one test with a loaded module and one with an unloaded module.

@zsoci
Copy link
Contributor Author

zsoci commented Mar 18, 2021

Do you think you can add tests for this? Ideally one test with a loaded module and one with an unloaded module.

Do you mean in addition to the cases that already provide full coverage for the added code?
Screen Shot 2021-03-18 at 7 47 54 PM

@eproxus
Copy link
Owner

eproxus commented Mar 23, 2021

I think those tests are only implicitly loading the module by running cover? Not sure if there's a test that is equivalent to:

  1. load module
  2. mock module
  3. unload mock
  4. check that module is re-loaded (without calling the actual module)

Might be wrong though...

@zsoci
Copy link
Contributor Author

zsoci commented Mar 23, 2021

Yes you are right, I think no tests performs step 4. I will create one.

?assertEqual({module, meck_test_module}, code:load_file(meck_test_module)),
ok = meck:new(meck_test_module),
?assertEqual(ok, meck:unload(meck_test_module)),
?assertNotEqual(false, code:is_loaded(meck_test_module)),
Copy link
Owner

Choose a reason for hiding this comment

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

Can you change this to ?assertMatch({file, _}, code:is_loaded(meck_test_module)),?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I did not find assertMatch around the line so tried to comply to assertEqual style ;)

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, unfortunately code:is_loaded/1 does not return a boolean 😄 Otherwise ?assert(not code:is_loaded(...)) would have looked beautiful.

ok.
case Restore andalso false =:= code:is_loaded(Mod) of
true ->
_ = code:load_file(Mod),
Copy link
Owner

Choose a reason for hiding this comment

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

Can you add this comment before the call to code:load_file/1?

            % We make a best effort to reload the module here. Since this runs
            % in a terminating process there is nothing we can do to recover if
            % the loading fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the good reasoning. Done

@zsoci
Copy link
Contributor Author

zsoci commented Mar 25, 2021

I think this also fixes #214

@eproxus
Copy link
Owner

eproxus commented Mar 25, 2021

Oh, forgot. One more request. Can you add an entry to CHANGELOG.md too under Unreleased and squash all commits into one?

@zsoci
Copy link
Contributor Author

zsoci commented Mar 25, 2021

Done.

@@ -7,6 +7,8 @@ The format is based on [Keep a Changelog], and this project adheres to

## [Unreleased]

- Leave module loaded state as it was [\#228](https://github.com/eproxus/meck/pull/228)
Copy link
Owner

Choose a reason for hiding this comment

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

Last minor nitpick. This should be under a ### Added heading. Otherwise looks good!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected. Thanks for the clarification. IMO it could also be under Fixed #214

Copy link
Owner

Choose a reason for hiding this comment

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

True, but I feel it is more appropriate to label it as new behavior since it changes the behavior of Meck. It also happens to fix an old issue. 🙂

@eproxus eproxus merged commit 3efce27 into eproxus:master Mar 25, 2021
@eproxus
Copy link
Owner

eproxus commented Mar 25, 2021

Thanks so much! ❤️

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.

None yet

2 participants