Permalink
Browse files

Fix failing tests when system has env vars set.

Just need to make sure we unset them before running the tests.
  • Loading branch information...
1 parent 544bf9d commit 0e010476a95dacf4f32cb6f6289d724a1ad21fb9 @theory committed May 29, 2012
Showing with 13 additions and 9 deletions.
  1. +13 −9 t/pg.t
View
22 t/pg.t
@@ -56,17 +56,21 @@ is_deeply [$pg->psql], [$client, @std_opts],
##############################################################################
# Test other configs for the target.
-for my $env (qw(PGDATABASE PGUSER USER)) {
- my $pg = $CLASS->new(sqitch => $sqitch);
- local $ENV{$env} = "\$ENV=whatever";
- is $pg->target, "\$ENV=whatever", "Target should read \$$env";
-}
-
ENV: {
- my $pg = $CLASS->new(sqitch => $sqitch, username => 'hi');
- is $pg->target, 'hi', 'Target shoul read username';
+ # Make sure we override system-set vars.
+ local $ENV{PGDATABASE};
+ local $ENV{PGUSER};
+ local $ENV{USER};
+ for my $env (qw(PGDATABASE PGUSER USER)) {
+ my $pg = $CLASS->new(sqitch => $sqitch);
+ local $ENV{$env} = "\$ENV=whatever";
+ is $pg->target, "\$ENV=whatever", "Target should read \$$env";
+ }
+
+ $pg = $CLASS->new(sqitch => $sqitch, username => 'hi');
+ is $pg->target, 'hi', 'Target should read username';
- local $ENV{PGDATABASE} = 'mydb';
+ $ENV{PGDATABASE} = 'mydb';
$pg = $CLASS->new(sqitch => $sqitch, username => 'hi');
is $pg->target, 'mydb', 'Target should prefer $PGDATABASE to username';
}

0 comments on commit 0e01047

Please sign in to comment.