Bump version to 2.4.2 for development of next release
[gnu-stow.git] / t / chkstow.t
blob6e066c22b1c7fb9ee87796ce25eced13fe023266
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 # Testing cleanup_invalid_links()
22 use strict;
23 use warnings;
25 use testutil;
26 require "chkstow";
28 use Test::More tests => 7;
29 use Test::Output;
30 use English qw(-no_match_vars);
32 init_test_dirs();
33 cd("$TEST_DIR/target");
35 # setup stow directory
36 make_path('stow');
37 make_file('stow/.stow');
38 # perl
39 make_path('stow/perl/bin');
40 make_file('stow/perl/bin/perl');
41 make_file('stow/perl/bin/a2p');
42 make_path('stow/perl/info');
43 make_file('stow/perl/info/perl');
44 make_path('stow/perl/lib/perl');
45 make_path('stow/perl/man/man1');
46 make_file('stow/perl/man/man1/perl.1');
47 # emacs
48 make_path('stow/emacs/bin');
49 make_file('stow/emacs/bin/emacs');
50 make_file('stow/emacs/bin/etags');
51 make_path('stow/emacs/info');
52 make_file('stow/emacs/info/emacs');
53 make_path('stow/emacs/libexec/emacs');
54 make_path('stow/emacs/man/man1');
55 make_file('stow/emacs/man/man1/emacs.1');
57 #setup target directory
58 make_path('bin');
59 make_link('bin/a2p', '../stow/perl/bin/a2p');
60 make_link('bin/emacs', '../stow/emacs/bin/emacs');
61 make_link('bin/etags', '../stow/emacs/bin/etags');
62 make_link('bin/perl', '../stow/perl/bin/perl');
64 make_path('info');
65 make_link('info/emacs', '../stow/emacs/info/emacs');
66 make_link('info/perl', '../stow/perl/info/perl');
68 make_link('lib', 'stow/perl/lib');
69 make_link('libexec', 'stow/emacs/libexec');
71 make_path('man');
72 make_path('man/man1');
73 make_link('man/man1/emacs', '../../stow/emacs/man/man1/emacs.1');
74 make_link('man/man1/perl', '../../stow/perl/man/man1/perl.1');
76 sub run_chkstow() {
77 process_options();
78 check_stow();
81 local @ARGV = ('-t', '.', '-b');
82 stderr_like(
83 \&run_chkstow,
84 qr{\Askipping .*stow.*\z}xms,
85 "Skip directories containing .stow");
87 # squelch warn so that check_stow doesn't carp about skipping .stow all the time
88 $SIG{__WARN__} = sub { };
90 @ARGV = ('-t', '.', '-l');
91 stdout_like(
92 \&run_chkstow,
93 qr{emacs\nperl\nstow\n}xms,
94 "List packages");
96 @ARGV = ('-t', '.', '-b');
97 stdout_like(
98 \&run_chkstow,
99 qr{\A\z}xms,
100 "No bogus links exist");
102 @ARGV = ('-t', '.', '-a');
103 stdout_like(
104 \&run_chkstow,
105 qr{\A\z}xms,
106 "No aliens exist");
108 # Create an alien
109 make_file('bin/alien');
110 @ARGV = ('-t', '.', '-a');
111 stdout_like(
112 \&run_chkstow,
113 qr{Unstowed\ file:\ ./bin/alien}xms,
114 "Aliens exist");
116 make_invalid_link('bin/link', 'ireallyhopethisfiledoesn/t.exist');
117 @ARGV = ('-t', '.', '-b');
118 stdout_like(
119 \&run_chkstow,
120 qr{Bogus\ link:\ ./bin/link}xms,
121 "Bogus links exist");
123 @ARGV = ('-b');
124 process_options();
125 our $Target;
126 ok($Target == q{/usr/local},
127 "Default target is /usr/local/");