cli_options.t 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 processing of CLI options.
  19. #
  20. use strict;
  21. use warnings;
  22. use Test::More tests => 10;
  23. use testutil;
  24. require 'stow';
  25. init_test_dirs();
  26. local @ARGV = (
  27. '-v',
  28. '-d', "$TEST_DIR/stow",
  29. '-t', "$TEST_DIR/target",
  30. 'dummy'
  31. );
  32. my ($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();
  33. is($options->{verbose}, 1, 'verbose option');
  34. is($options->{dir}, "$TEST_DIR/stow", 'stow dir option');
  35. my $stow = new_Stow(%$options);
  36. is($stow->{stow_path}, "../stow" => 'stow dir');
  37. is_deeply($pkgs_to_stow, [ 'dummy' ] => 'default to stow');
  38. #
  39. # Check mixed up package options
  40. #
  41. local @ARGV = (
  42. '-v',
  43. '-D', 'd1', 'd2',
  44. '-S', 's1',
  45. '-R', 'r1',
  46. '-D', 'd3',
  47. '-S', 's2', 's3',
  48. '-R', 'r2',
  49. );
  50. ($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();
  51. is_deeply($pkgs_to_delete, [ 'd1', 'd2', 'r1', 'd3', 'r2' ] => 'mixed deletes');
  52. is_deeply($pkgs_to_stow, [ 's1', 'r1', 's2', 's3', 'r2' ] => 'mixed stows');
  53. #
  54. # Check setting deferred paths
  55. #
  56. local @ARGV = (
  57. '--defer=man',
  58. '--defer=info',
  59. 'dummy'
  60. );
  61. ($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();
  62. is_deeply($options->{defer}, [ qr(\Aman), qr(\Ainfo) ] => 'defer man and info');
  63. #
  64. # Check setting override paths
  65. #
  66. local @ARGV = (
  67. '--override=man',
  68. '--override=info',
  69. 'dummy'
  70. );
  71. ($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();
  72. is_deeply($options->{override}, [qr(\Aman), qr(\Ainfo)] => 'override man and info');
  73. #
  74. # Check setting ignored paths
  75. #
  76. local @ARGV = (
  77. '--ignore=~',
  78. '--ignore=\.#.*',
  79. 'dummy'
  80. );
  81. ($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();
  82. is_deeply($options->{ignore}, [ qr(~\z), qr(\.#.*\z) ] => 'ignore temp files');
  83. #
  84. # Check that expansion not applied.
  85. #
  86. local @ARGV = (
  87. "--target=$TEST_DIR/".'$HOME',
  88. 'dummy'
  89. );
  90. make_path("$TEST_DIR/".'$HOME');
  91. ($options, $pkgs_to_delete, $pkgs_to_stow) = process_options();
  92. is($options->{target}, "$TEST_DIR/".'$HOME', 'no expansion');
  93. remove_dir("$TEST_DIR/".'$HOME');
  94. # vim:ft=perl