dotfiles.t 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. # Test case for dotfiles special processing
  19. #
  20. use strict;
  21. use warnings;
  22. use testutil;
  23. use Test::More tests => 6;
  24. use English qw(-no_match_vars);
  25. use testutil;
  26. init_test_dirs();
  27. cd("$TEST_DIR/target");
  28. my $stow;
  29. #
  30. # process a dotfile marked with 'dot' prefix
  31. #
  32. $stow = new_Stow(dir => '../stow', dotfiles => 1);
  33. make_path('../stow/dotfiles');
  34. make_file('../stow/dotfiles/dot-foo');
  35. $stow->plan_stow('dotfiles');
  36. $stow->process_tasks();
  37. is(
  38. readlink('.foo'),
  39. '../stow/dotfiles/dot-foo',
  40. => 'processed dotfile'
  41. );
  42. #
  43. # ensure that turning off dotfile processing links files as usual
  44. #
  45. $stow = new_Stow(dir => '../stow', dotfiles => 0);
  46. make_path('../stow/dotfiles');
  47. make_file('../stow/dotfiles/dot-foo');
  48. $stow->plan_stow('dotfiles');
  49. $stow->process_tasks();
  50. is(
  51. readlink('dot-foo'),
  52. '../stow/dotfiles/dot-foo',
  53. => 'unprocessed dotfile'
  54. );
  55. #
  56. # process folder marked with 'dot' prefix
  57. #
  58. $stow = new_Stow(dir => '../stow', dotfiles => 1);
  59. make_path('../stow/dotfiles/dot-emacs');
  60. make_file('../stow/dotfiles/dot-emacs/init.el');
  61. $stow->plan_stow('dotfiles');
  62. $stow->process_tasks();
  63. is(
  64. readlink('.emacs'),
  65. '../stow/dotfiles/dot-emacs',
  66. => 'processed dotfile folder'
  67. );
  68. #
  69. # corner case: paths that have a part in them that's just "$DOT_PREFIX" or
  70. # "$DOT_PREFIX." should not have that part expanded.
  71. #
  72. $stow = new_Stow(dir => '../stow', dotfiles => 1);
  73. make_path('../stow/dotfiles');
  74. make_file('../stow/dotfiles/dot-');
  75. make_path('../stow/dotfiles/dot-.');
  76. make_file('../stow/dotfiles/dot-./foo');
  77. $stow->plan_stow('dotfiles');
  78. $stow->process_tasks();
  79. is(
  80. readlink('dot-'),
  81. '../stow/dotfiles/dot-',
  82. => 'processed dotfile'
  83. );
  84. is(
  85. readlink('dot-.'),
  86. '../stow/dotfiles/dot-.',
  87. => 'unprocessed dotfile'
  88. );
  89. #
  90. # simple unstow scenario
  91. #
  92. $stow = new_Stow(dir => '../stow', dotfiles => 1);
  93. make_path('../stow/dotfiles');
  94. make_file('../stow/dotfiles/dot-bar');
  95. make_link('.bar', '../stow/dotfiles/dot-bar');
  96. $stow->plan_unstow('dotfiles');
  97. $stow->process_tasks();
  98. ok(
  99. $stow->get_conflict_count == 0 &&
  100. -f '../stow/dotfiles/dot-bar' && ! -e '.bar'
  101. => 'unstow a simple dotfile'
  102. );