added auxiliary module for quick config file creation, etc for tests
authorMatthias Förste <foerste@schlittermann.de>
Wed, 29 Jun 2011 11:42:51 +0200
changeset 143 c26b5fa3f646
parent 142 ae564015b7b0
child 144 be90bcd14ae1
added auxiliary module for quick config file creation, etc for tests
t/00-config.t
t/lib/Aux.pm
--- a/t/00-config.t	Wed Jun 29 10:33:32 2011 +0200
+++ b/t/00-config.t	Wed Jun 29 11:42:51 2011 +0200
@@ -2,8 +2,9 @@
 
 use strict;
 use warnings;
+use lib 't/lib';
 use Test::More qw(no_plan);
-use File::Temp;
+use Aux;
 
 BEGIN {
     use_ok "DNStools::Config" => qw(get_config);
@@ -17,12 +18,12 @@
 my ($tmp, %cf);
 
 # prepare some simple sample config
-$tmp = File::Temp->new();
-print {$tmp} <<__EOF;
+my $c = <<EOF;
 # comment
 abc = xyz
 other =    value with space
-__EOF
+EOF
+$tmp = Aux::make_config $c;
 close($tmp);
 
 # the files is specified, it should find the first 
@@ -35,7 +36,7 @@
 # it should find the file specified in $ENV{DNSTOOLS_CONF}
 $ENV{DNSTOOLS_CONF} = $tmp->filename;
 %cf = ();
-%cf = get_config("xxx|xxx", $tmp->filename);
+%cf = get_config();
 ok(%cf, "got config from \$DNSTOOLS_CONF");
 is($cf{abc} => "xyz", "simple value");
 is($cf{other} => "valuewithspace", "spaced value");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/t/lib/Aux.pm	Wed Jun 29 11:42:51 2011 +0200
@@ -0,0 +1,29 @@
+package Aux;
+
+use strict;
+use warnings;
+
+use File::Temp;
+use base "Exporter";
+
+our $VERSION = 0.0;
+our @EXPORT_OK = qw(make_config);
+
+sub make_config($) {
+
+    my ($c) = @_;
+
+    my $f = File::Temp->new or die "Config file creation failed\n";
+
+    if (ref $c eq 'HASH') {
+        map { print $f "$_ = $c->$_\n" } keys %{$c};
+    } else {
+        # assuming just a string
+        print $f $c;
+    }
+
+    return $f;
+
+}
+
+1;