[Pdx-pm] interesting testing hole thats been dug

Eric Wilhelm scratchcomputing at gmail.com
Tue Jan 2 18:39:24 PST 2007

# from benh
# on Tuesday 02 January 2007 04:36 pm:

>when I
>want to test it should be a mocDB object... so we now have a DBTest
>that builds out the mocDB stuffies. But the issue now is that to get
>all the existing scripts to use DBTest for our tests.

Are those test scripts?  If so, sed or perl -pie should do the trick.  
It sounds like it is maybe not so easy though (e.g. you have modules 
that use said module.)  Possibly you could make a wee use() module that 
just checks the environment variable and requires one or another.  If 
need be, you could then goto that \&import from this import, but it 
might be easier to do something less voodooey.

  package whatever;
  use DBAdaptor;

  package DBAdaptor;
  my $selected;
    $selected = DBFaker;
  else {
    $selected = DBReal;
  eval("require $selected") or die $@;
  sub selected {$selected};

Though I might instead lean toward something that just pretends to be 
the real db module, moving into his %INC house, eating his *{} bacon 
and all that, so that once somebody says "use DBFaker;", package DBReal 
has been smashed and require will just ignore you (or your evil twin 
who keeps forgetting about that adaptor.)  Similarly, the faker could 
actually use the real module and then just steal its fire, which gives 
you the added benefit of being able to test the real db code, but just 
blunt the dangerous bits.

Who was it that said the first thing to do when you find yourself in a 
hole is to stop digging?

The reasonable man adapts himself to the world; the unreasonable man
persists in trying to adapt the world to himself. Therefore all progress
depends on the unreasonable man.
--George Bernard Shaw

More information about the Pdx-pm-list mailing list