-
Notifications
You must be signed in to change notification settings - Fork 17
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
define() method has a bug #64
Comments
At first glance this looks a bug in your code here. You try to mock the But in fact when you start defining the function the value of Two issues here:
Hope this helps. I think we can close this case. Let me know if you object. |
No we cannot close this case:
|
If you adjust in your script the line to use -$mock = Test::MockModule->new( $class, no_auto => 1 )->define( stat => $code );
+$mock = Test::MockModule->new( $class, no_auto => 1 )->redefine( stat => $code ); You would then notice that you are not mocking
I still think you should mock |
Yes I want to mock
Now I am able to mock
I disagree with the indeed...! I don't want to restore
By the way the new |
How do we continue with this issue? |
Sorry for the delay. The issue is with the example above, you fill the CV for So once compiling the optree, every call to I wonder if we cannot consider something more dynamic to solve your case where when restoring the function if missing we then add the parent or the CORE:: one. I think your problem is that
when you would expect a different one |
is wrong. Yes, I have defined Defining something is not mocking, so |
I would like to mock the
stat()
CORE subroutine in theBar
moduleThis is my failing test script
Uncommenting the line
#$mock->{ _orig }{ stat } = $code;
makes the test script pass.
What is the strategy of my test script: In the BEGIN block (compile time) before loading the
Bar
module I have useddefine()
to add a wrapper subroutine (it wrapsCORE::stat
) with the namestat
to theBar
module. Then I have loaded theBar
module. At run time I have usedredefine()
to mock the wrapper subroutine. I have done an is-test. Then I haveunmock()
ed the wrapper subroutine. My expectation was that unmocking brings back the implementation of the wrapper subroutine. Unfortunatelydefine()
doestest-mockmodule/lib/Test/MockModule.pm
Line 144 in a2d8108
instead of
test-mockmodule/lib/Test/MockModule.pm
Line 142 in a2d8108
To me this is a bug caused by the fact that the implementation of
define()
is based on_mock()
.The text was updated successfully, but these errors were encountered: