perl - MockModule's mock not being called? -
I have a module that uses random numbers in it. For testing purposes, I want to set it before giving a number to the random number generator set. Under test, my code includes such dependency:
Use Math :: Random :: MT Q (RAND);
and uses this:
My $ currdice = int (rand ($ true) + 1);
And my joke is done as such:
$ my fake; BEGIN {$ mockRand = Test :: MockModule-> New ('Math :: Random :: MT'); Use_ok (LogiDice); } $ MockRand- & gt; Counterfeit ('rand' => sub {return1}); ($ Successes, $ output) = LogiDice :: roll ("3d10", "ww"); OK ($ successes == 0, "Whitewolf Mode can return 0 successes") or Diage ("Reported". $ Successes. "Successes instead.");
I am always getting the success of random numbers rather than expecting 0 (because the random number should always be 1, which should always fail). Is there something like how I did QW? Am I using MockModule incorrectly? Should I use MockMDU? I tried MockObject, before I found MockModule, but it was not working either
So, I think this happens ...
- Make your fake cover
- Then you say "use_ok", which is "Math: : Random :: MT QW (RAND); "
- Your counterfeit call replaces MT :: Rand (but is not affected by this, which is a direct reference for the old "Rand" already)
Probably will work if you make fun of "rand" after calling "call_ok" Alternatively, no LogiDice can import "rand" in its namespace, and always references the MT :: Rand.
Comments
Post a Comment