Permalink
Browse files

added test

  • Loading branch information...
1 parent c05d369 commit de48cf2e1ad0439a7e84f4deb35402fca4c63d5c @xaicron committed Jul 9, 2011
Showing with 64 additions and 0 deletions.
  1. +64 −0 t/03_run.t
View
@@ -0,0 +1,64 @@
+use strict;
+use warnings;
+use Test::More;
+
+BEGIN {
+ # capture system()
+ *CORE::GLOBAL::system = sub {
+ my @args = @_;
+ my $pid = open my $pipe, '-|';
+ if ($pid) {
+ my $buf;
+ while (defined (my $line = readline $pipe)) {
+ $buf .= $line;
+ }
+ close $pipe or die $!;
+ return $buf;
+ }
+ else {
+ exec @args or die $!;
+ }
+ };
+}
+
+use App::envfile;
+
+sub test_run {
+ my %specs = @_;
+ my ($input, $expects, $desc) = @specs{qw/input expects desc/};
+ my ($envfile, $envmap) = @$input;
+
+ local %ENV = %ENV;
+
+ {
+ no warnings 'redefine';
+ *App::envfile::load_envfile = sub {
+ my ($self, $file) = @_;
+ is $file, $envfile, 'load_envfile ok';
+ for my $key (sort keys %$envmap) {
+ $ENV{$key} = $envmap->{$key};
+ }
+ };
+ }
+
+ my $command = join ',', map { "\$ENV{$_}" } sort keys %$envmap;
+
+ subtest $desc => sub {
+ my $envf = App::envfile->new;
+ $envf->run($envfile, $^X, '-e', "print qq|$command|");
+ };
+}
+
+test_run(
+ input => [file => { FOO => 'bar' }],
+ expects => 'bar',
+ desc => 'with FOO',
+);
+
+test_run(
+ input => [file => { FOO => 'bar', BAR => 'baz' }],
+ expects => 'baz,bar',
+ desc => 'with FOO, BAR',
+);
+
+done_testing;

0 comments on commit de48cf2

Please sign in to comment.