system_cmd.t 2.31 KB
Newer Older
1 2
#!/usr/bin/env perl

3
# Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
nwillhoft's avatar
nwillhoft committed
4
# Copyright [2016-2021] EMBL-European Bioinformatics Institute
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# 
# 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;

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

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

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

Matthieu Muffato's avatar
Matthieu Muffato committed
35
subtest 'The command line is given as a string' => sub
36
{
Matthieu Muffato's avatar
Matthieu Muffato committed
37
    plan tests => 3;
38 39 40
    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
41
};
42

Matthieu Muffato's avatar
Matthieu Muffato committed
43
subtest 'The command line is given as an arrayref' => sub
44
{
Matthieu Muffato's avatar
Matthieu Muffato committed
45
    plan tests => 3;
46 47 48
    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
49
};
50

Matthieu Muffato's avatar
Matthieu Muffato committed
51
subtest 'The command line is given as an arrayref and contains redirections / pipes' => sub
52
{
Matthieu Muffato's avatar
Matthieu Muffato committed
53
    plan tests => 3;
54 55 56
    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
57
};
58

59 60
chdir $orig;

61
done_testing();
62