chkstow.t 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #!/usr/bin/perl
  2. #
  3. # This file is part of GNU Stow.
  4. #
  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.
  9. #
  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.
  14. #
  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/.
  17. #
  18. # Testing cleanup_invalid_links()
  19. #
  20. use strict;
  21. use warnings;
  22. use testutil;
  23. require "chkstow";
  24. use Test::More tests => 7;
  25. use Test::Output;
  26. use English qw(-no_match_vars);
  27. init_test_dirs();
  28. cd("$TEST_DIR/target");
  29. # setup stow directory
  30. make_path('stow');
  31. make_file('stow/.stow');
  32. # perl
  33. make_path('stow/perl/bin');
  34. make_file('stow/perl/bin/perl');
  35. make_file('stow/perl/bin/a2p');
  36. make_path('stow/perl/info');
  37. make_file('stow/perl/info/perl');
  38. make_path('stow/perl/lib/perl');
  39. make_path('stow/perl/man/man1');
  40. make_file('stow/perl/man/man1/perl.1');
  41. # emacs
  42. make_path('stow/emacs/bin');
  43. make_file('stow/emacs/bin/emacs');
  44. make_file('stow/emacs/bin/etags');
  45. make_path('stow/emacs/info');
  46. make_file('stow/emacs/info/emacs');
  47. make_path('stow/emacs/libexec/emacs');
  48. make_path('stow/emacs/man/man1');
  49. make_file('stow/emacs/man/man1/emacs.1');
  50. #setup target directory
  51. make_path('bin');
  52. make_link('bin/a2p', '../stow/perl/bin/a2p');
  53. make_link('bin/emacs', '../stow/emacs/bin/emacs');
  54. make_link('bin/etags', '../stow/emacs/bin/etags');
  55. make_link('bin/perl', '../stow/perl/bin/perl');
  56. make_path('info');
  57. make_link('info/emacs', '../stow/emacs/info/emacs');
  58. make_link('info/perl', '../stow/perl/info/perl');
  59. make_link('lib', 'stow/perl/lib');
  60. make_link('libexec', 'stow/emacs/libexec');
  61. make_path('man');
  62. make_path('man/man1');
  63. make_link('man/man1/emacs', '../../stow/emacs/man/man1/emacs.1');
  64. make_link('man/man1/perl', '../../stow/perl/man/man1/perl.1');
  65. sub run_chkstow() {
  66. process_options();
  67. check_stow();
  68. }
  69. local @ARGV = ('-t', '.', '-b');
  70. stderr_like(
  71. \&run_chkstow,
  72. qr{\Askipping .*stow.*\z}xms,
  73. "Skip directories containing .stow");
  74. # squelch warn so that check_stow doesn't carp about skipping .stow all the time
  75. $SIG{__WARN__} = sub { };
  76. @ARGV = ('-t', '.', '-l');
  77. stdout_like(
  78. \&run_chkstow,
  79. qr{emacs\nperl\nstow\n}xms,
  80. "List packages");
  81. @ARGV = ('-t', '.', '-b');
  82. stdout_like(
  83. \&run_chkstow,
  84. qr{\A\z}xms,
  85. "No bogus links exist");
  86. @ARGV = ('-t', '.', '-a');
  87. stdout_like(
  88. \&run_chkstow,
  89. qr{\A\z}xms,
  90. "No aliens exist");
  91. # Create an alien
  92. make_file('bin/alien');
  93. @ARGV = ('-t', '.', '-a');
  94. stdout_like(
  95. \&run_chkstow,
  96. qr{Unstowed\ file:\ ./bin/alien}xms,
  97. "Aliens exist");
  98. make_invalid_link('bin/link', 'ireallyhopethisfiledoesn/t.exist');
  99. @ARGV = ('-t', '.', '-b');
  100. stdout_like(
  101. \&run_chkstow,
  102. qr{Bogus\ link:\ ./bin/link}xms,
  103. "Bogus links exist");
  104. @ARGV = ('-b');
  105. process_options();
  106. our $Target;
  107. ok($Target == q{/usr/local},
  108. "Default target is /usr/local/");