Shell-EnvImporter
view release on metacpan or search on metacpan
t/Shell-EnvImporter.t view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
no warnings 'uninitialized';
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl Shell-EnvImporter.t'
#########################
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 744;
BEGIN { use_ok('Shell::EnvImporter') };
#########################
# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.
##############################################################################
# Config variables
#
my $file = 't/test_script';
my $sh_script = "ADD_VAR=1;MOD_VAR=1;unset DEL_VAR;export ADD_VAR MOD_VAR DEL_VAR";
my $csh_script = "setenv ADD_VAR 1; setenv MOD_VAR 1; unsetenv DEL_VAR";
my $perl_script = '$ENV{"MOD_VAR"}=1;$ENV{"ADD_VAR"}=1;delete $ENV{"DEL_VAR"};';
my %scripts = (
sh => $sh_script,
bash => $sh_script,
zsh => $sh_script,
# ksh => $sh_script, # Untested, as I don't have ksh
csh => $csh_script,
tcsh => $csh_script,
perl => $perl_script, # just for grins :)
);
##############################################################################
# Just Do Me
#
# 1. The simplest case: source a Bourne-shell script and auto-import
# added or modified environment variables
&run_test(
'sh script auto-import' => {
setup => sub {
open(FILE, ">$file") or die "Couldn't create $file: $!";
print FILE "$sh_script\n";
close(FILE);
},
run => sub {
my $importer = Shell::EnvImporter->new(
file => $file,
);
return $importer;
},
cleanup => sub {
unlink($file);
},
modified => {
MOD_VAR => 1,
},
added => {
ADD_VAR => 1,
},
removed => {
DEL_VAR => undef,
},
imported => [qw(MOD_VAR ADD_VAR)],
},
);
# 2. The next simplest case: run some Bourne-shell commands and auto-import
# added or modified environment variables
&run_test(
'sh command auto-import' => {
setup => sub { },
run => sub {
my $importer = Shell::EnvImporter->new(
command => $sh_script,
( run in 0.622 second using v1.01-cache-2.11-cpan-39bf76dae61 )