1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#!perl
## no critic (Subroutines::ProtectPrivateSubs)
use strict;
use warnings;
use Test2::V0;
use Env::Dot::ScriptFunctions qw( );
subtest 'Private Subroutine _convert_var_to_sh()' => sub {
{
my %var = (
name => 'THIS_VAR',
value => 'this var value',
opts => { 'export' => 1, 'allow_interpolate' => 0, },
);
my $expect = q{THIS_VAR='this var value'; export THIS_VAR};
my $cmdline = Env::Dot::ScriptFunctions::_convert_var_to_sh( \%var );
is( $cmdline, $expect, 'Correct Bourne Shell command' );
}
{
my %var = (
name => 'THIS_VAR',
value => 'this var value',
opts => { 'export' => 0, 'allow_interpolate' => 1, },
);
my $expect = q{THIS_VAR="this var value"};
my $cmdline = Env::Dot::ScriptFunctions::_convert_var_to_sh( \%var );
is( $cmdline, $expect, 'Correct Bourne Shell command' );
}
{
my %var = (
name => 'THIS_VAR',
value => 'this var value',
opts => { 'export' => 0, 'allow_interpolate' => 1, },
);
my $expect = q{THIS_VAR="this var value"};
my $cmdline = Env::Dot::ScriptFunctions::_convert_var_to_sh( \%var );
is( $cmdline, $expect, 'Correct Bourne Shell command' );
}
done_testing;
};
subtest 'Private Subroutine _convert_var_to_csh()' => sub {
{
my %var = (
name => 'THIS_VAR',
value => 'this var value',
opts => { 'export' => 1, 'allow_interpolate' => 0, },
);
my $expect = q{setenv THIS_VAR 'this var value'};
my $cmdline = Env::Dot::ScriptFunctions::_convert_var_to_csh( \%var );
is( $cmdline, $expect, 'Correct C Shell command' );
}
{
my %var = (
name => 'THIS_VAR',
value => 'this var value',
opts => { 'export' => 1, 'allow_interpolate' => 1, },
);
my $expect = q{setenv THIS_VAR "this var value"};
my $cmdline = Env::Dot::ScriptFunctions::_convert_var_to_csh( \%var );
is( $cmdline, $expect, 'Correct Bourne Shell command' );
}
{
my %var = (
name => 'THIS_VAR',
value => 'this var value',
opts => { 'export' => 0, 'allow_interpolate' => 1, },
);
my $expect = q{set THIS_VAR "this var value"};
my $cmdline = Env::Dot::ScriptFunctions::_convert_var_to_csh( \%var );
is( $cmdline, $expect, 'Correct Bourne Shell command' );
}
done_testing;
};
subtest 'Private Subroutine convert_variables_into_commands()' => sub {
{
my @vars = (
{
name => 'THIS_VAR',
value => 'this var value',
opts => { 'export' => 1, 'allow_interpolate' => 0, },
},
{
name => 'THAT_VAR',
value => 'that var value',
opts => { 'export' => 1, 'allow_interpolate' => 0, },
},
);
my $expect = <<'END_OF_TEXT';
THIS_VAR='this var value'; export THIS_VAR
THAT_VAR='that var value'; export THAT_VAR
END_OF_TEXT
my $out = Env::Dot::ScriptFunctions::convert_variables_into_commands( 'sh', @vars );
is( $out, $expect, 'Correct Bourne Shell command' );
}
{
my @vars = (
{
name => 'THAT_VAR',
value => 'that var value',
opts => { 'export' => 0, 'allow_interpolate' => 0, },
},
{
name => 'THIS_VAR',
value => 'this var value',
opts => { 'export' => 1, 'allow_interpolate' => 1, },
},
);
my $expect = <<'END_OF_TEXT';
THAT_VAR='that var value'
THIS_VAR="this var value"; export THIS_VAR
END_OF_TEXT
my $out = Env::Dot::ScriptFunctions::convert_variables_into_commands( 'sh', @vars );
is( $out, $expect, 'Correct Bourne Shell command' );
}
done_testing;
};
done_testing;
|