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 ...

  1. Make your fake cover
  2. Then you say "use_ok", which is "Math: : Random :: MT QW (RAND); "
  3. 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

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -