Stow directory now defaults to STOW_DIR environment variable if set.
[gnu-stow.git] / t / chkstow.t
blobf38de57906d2f30b7e21c444cd309c297b2c7b6a
1 #!/usr/local/bin/perl
4 # Testing cleanup_invalid_links()
7 # load as a library
8 BEGIN {
9 use lib qw(.);
10 require "t/util.pm";
11 require "chkstow";
14 use Test::More tests => 7;
15 use Test::Output;
16 use English qw(-no_match_vars);
18 ### setup
19 eval { remove_dir('t/target'); };
20 make_dir('t/target');
22 chdir 't/target';
24 # setup stow directory
25 make_dir('stow');
26 make_file('stow/.stow');
27 # perl
28 make_dir('stow/perl/bin');
29 make_file('stow/perl/bin/perl');
30 make_file('stow/perl/bin/a2p');
31 make_dir('stow/perl/info');
32 make_file('stow/perl/info/perl');
33 make_dir('stow/perl/lib/perl');
34 make_dir('stow/perl/man/man1');
35 make_file('stow/perl/man/man1/perl.1');
36 # emacs
37 make_dir('stow/emacs/bin');
38 make_file('stow/emacs/bin/emacs');
39 make_file('stow/emacs/bin/etags');
40 make_dir('stow/emacs/info');
41 make_file('stow/emacs/info/emacs');
42 make_dir('stow/emacs/libexec/emacs');
43 make_dir('stow/emacs/man/man1');
44 make_file('stow/emacs/man/man1/emacs.1');
46 #setup target directory
47 make_dir('bin');
48 make_link('bin/a2p', '../stow/perl/bin/a2p');
49 make_link('bin/emacs', '../stow/emacs/bin/emacs');
50 make_link('bin/etags', '../stow/emacs/bin/etags');
51 make_link('bin/perl', '../stow/perl/bin/perl');
53 make_dir('info');
54 make_link('info/emacs', '../stow/emacs/info/emacs');
55 make_link('info/perl', '../stow/perl/info/perl');
57 make_link('lib', 'stow/perl/lib');
58 make_link('libexec', 'stow/emacs/libexec');
60 make_dir('man');
61 make_dir('man/man1');
62 make_link('man/man1/emacs', '../../stow/emacs/man/man1/emacs.1');
63 make_link('man/man1/perl', '../../stow/perl/man/man1/perl.1');
65 sub run_chkstow() {
66 process_options();
67 check_stow();
70 local @ARGV = ('-t', '.', '-b',);
71 stderr_like(
72 \&run_chkstow,
73 qr{\Askipping .*stow.*\z}xms,
74 "Skip directories containing .stow");
76 # squelch warn so that check_stow doesn't carp about skipping .stow all the time
77 $SIG{'__WARN__'} = sub { };
79 @ARGV = ('-t', '.', '-l',);
80 stdout_like(
81 \&run_chkstow,
82 qr{emacs\nperl\nstow\n}xms,
83 "List packages");
85 @ARGV = ('-t', '.', '-b',);
86 stdout_like(
87 \&run_chkstow,
88 qr{\A\z}xms,
89 "No bogus links exist");
91 @ARGV = ('-t', '.', '-a',);
92 stdout_like(
93 \&run_chkstow,
94 qr{\A\z}xms,
95 "No aliens exist");
97 # Create an alien
98 make_file('bin/alien');
99 @ARGV = ('-t', '.', '-a',);
100 stdout_like(
101 \&run_chkstow,
102 qr{Unstowed\ file:\ ./bin/alien}xms,
103 "Aliens exist");
105 make_link('bin/link', 'ireallyhopethisfiledoesn/t.exist');
106 @ARGV = ('-t', '.', '-b',);
107 stdout_like(
108 \&run_chkstow,
109 qr{Bogus\ link:\ ./bin/link}xms,
110 "Bogus links exist");
112 @ARGV = ('-b',);
113 process_options();
114 ok($::Target == q{/usr/local},
115 "Default target is /usr/local/");