system_cmd.t 2.3 KB
Newer Older
1
# Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
nwillhoft's avatar
nwillhoft committed
2
# Copyright [2016-2021] EMBL-European Bioinformatics Institute
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#      http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


use strict;
use warnings;

20
use Cwd;
Matthieu Muffato's avatar
Matthieu Muffato committed
21
use Test::More tests => 4;
22
use Data::Dumper;
23
use File::Temp qw{tempdir};
24 25 26 27 28 29

BEGIN {
    use_ok( 'Bio::EnsEMBL::Hive::Utils', 'join_command_args' );
}
#########################

30
my $dir = tempdir CLEANUP => 1;
31
my $orig = Cwd::getcwd;
32 33
chdir $dir;

Matthieu Muffato's avatar
Matthieu Muffato committed
34
subtest 'The command line is given as a string' => sub
35
{
Matthieu Muffato's avatar
Matthieu Muffato committed
36
    plan tests => 3;
37 38 39
    is_deeply([join_command_args("ls")], [0,"ls"], "String: the executable name");
    is_deeply([join_command_args("ls cpanfile")], [0,"ls cpanfile"], "String: the executable name and an argument");
    is_deeply([join_command_args("ls | cat")], [0,"ls | cat"], "String: two executables piped");
Matthieu Muffato's avatar
Matthieu Muffato committed
40
};
41

Matthieu Muffato's avatar
Matthieu Muffato committed
42
subtest 'The command line is given as an arrayref' => sub
43
{
Matthieu Muffato's avatar
Matthieu Muffato committed
44
    plan tests => 3;
45 46 47
    is_deeply([join_command_args(["ls"])], [0,"ls"], "Array with 1 element: the executable name");
    is_deeply([join_command_args(["ls", "cpanfile"])], [0,"ls cpanfile"], "Array with 2 elements: the executable and an argument");
    is_deeply([join_command_args(["ls", "file space"])], [0,"ls 'file space'"], "Array with 2 elements: the executable and an argument that contains a space");
Matthieu Muffato's avatar
Matthieu Muffato committed
48
};
49

Matthieu Muffato's avatar
Matthieu Muffato committed
50
subtest 'The command line is given as an arrayref and contains redirections / pipes' => sub
51
{
Matthieu Muffato's avatar
Matthieu Muffato committed
52
    plan tests => 3;
53 54 55
    is_deeply([join_command_args(["ls", ">", "file space"])], [1, "ls > 'file space'"], "Array with a redirection");
    is_deeply([join_command_args(["ls", "|", "cat"])], [1, "ls | cat"], "Array with a pipe");
    is_deeply([join_command_args(["ls", "|", "cat", ">", "file space"])], [1, "ls | cat > 'file space'"], "Array with a pipe and a redirection");
Matthieu Muffato's avatar
Matthieu Muffato committed
56
};
57

58 59
chdir $orig;

60
done_testing();