Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Setting up a test db with MakeMaker

by choroba (Cardinal)
on Feb 23, 2013 at 09:46 UTC ( [id://1020293]=note: print w/replies, xml ) Need Help??


in reply to Setting up a test db with MakeMaker

If you need a code to be called from each .t file, what about wrapping it into a module? You can even place it into the t/ directory and just add the following to each .t file:
use TestSetup;
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Setting up a test db with MakeMaker
by danmcb (Monk) on Feb 25, 2013 at 14:10 UTC

    indeed, this works fine. Some code for those that are curious:

    in t/test_setup.pm:

    package test_setup; sub setup { # setup your db or whatever here } 1;

    In a test module

    require t::test_setup; test_setup::setup();

    Rather simple in fact. Works fine on 5.10

    UPDATE: in fact - I am using this.

    package test_setup; sub setup { # ... } BEGIN { # must be after the sub definition setup(); $ENV{USE_TEST_DB} = 1; } 1;

    And in my Catalyst MyApp.pm class:

    if ( $ENV{USE_TEST_DB} ) { __PACKAGE__->config( 'Plugin::ConfigLoader' => { file => 'myapp_test +.yml'} ); }

    Now it is only necessary to "use" test_setup.pm. The setup is executed automatically, and the ENV variable causes the Catalyst app to use another config, which in turn connects to the test database in place of the normal development one.

Re^2: Setting up a test db with MakeMaker
by tmharish (Friar) on Feb 23, 2013 at 10:08 UTC
    what about wrapping it into a module? You can even place it into the t/ directory and just add the following to each .t file: use TestSetup;

    Does that work on 5.6?

      Does that work on 5.6?

      Why should it not work? Why don't you try it?

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        Why should it not work?

        Because I assumed that this will require BUILD_REQUIRES to be set and the default ExtUtils::MakeMaker version that shipped with 5.6 dint have it.

        Why don't you try it?

        I did and am yet to get it to work ( even on higher versions ) - Will reply once I find a way to get it to work or I give up, meanwhile - Did you?

        Update: I Managed it with a require 't/tests.pm'. I am not sure that thats what choroba meant though.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1020293]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2025-04-17 21:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.