Bump version to 2.4.2 for development of next release
[gnu-stow.git] / t / cli_options.t
blob7c8a25357ad34901773a3c48018519f0cc244a95
1 #!/usr/bin/perl
3 # This file is part of GNU Stow.
5 # GNU Stow is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # GNU Stow is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see https://www.gnu.org/licenses/.
19 # Test processing of CLI options.
22 use strict;
23 use warnings;
25 use Test::More tests => 10;
27 use testutil;
29 require 'stow';
31 init_test_dirs();
33 local @ARGV = (
34 '-v',
35 '-d', "$TEST_DIR/stow",
36 '-t', "$TEST_DIR/target",
37 'dummy'
40 my ($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();
42 is($options->{verbose}, 1, 'verbose option');
43 is($options->{dir}, "$TEST_DIR/stow", 'stow dir option');
45 my $stow = new_Stow(%$options);
47 is($stow->{stow_path}, "../stow" => 'stow dir');
48 is_deeply($pkgs_to_stow, [ 'dummy' ] => 'default to stow');
51 # Check mixed up package options
53 local @ARGV = (
54 '-v',
55 '-D', 'd1', 'd2',
56 '-S', 's1',
57 '-R', 'r1',
58 '-D', 'd3',
59 '-S', 's2', 's3',
60 '-R', 'r2',
63 ($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();
64 is_deeply($pkgs_to_delete, [ 'd1', 'd2', 'r1', 'd3', 'r2' ] => 'mixed deletes');
65 is_deeply($pkgs_to_stow, [ 's1', 'r1', 's2', 's3', 'r2' ] => 'mixed stows');
68 # Check setting deferred paths
70 local @ARGV = (
71 '--defer=man',
72 '--defer=info',
73 'dummy'
75 ($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();
76 is_deeply($options->{defer}, [ qr{\A(man)}, qr{\A(info)} ] => 'defer man and info');
79 # Check setting override paths
81 local @ARGV = (
82 '--override=man',
83 '--override=info',
84 'dummy'
86 ($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();
87 is_deeply($options->{override}, [qr{\A(man)}, qr{\A(info)}] => 'override man and info');
90 # Check setting ignored paths
92 local @ARGV = (
93 '--ignore=~',
94 '--ignore=\.#.*',
95 'dummy'
97 ($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();
98 is_deeply($options->{ignore}, [ qr{(~)\z}, qr{(\.#.*)\z} ] => 'ignore temp files');
101 # Check that expansion not applied.
103 local @ARGV = (
104 "--target=$TEST_DIR/".'$HOME',
105 'dummy'
107 make_path("$TEST_DIR/".'$HOME');
108 ($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();
109 is($options->{target}, "$TEST_DIR/".'$HOME', 'no expansion');
110 remove_dir("$TEST_DIR/".'$HOME');
112 # vim:ft=perl