cli.t 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 File::Basename;
  23. use Test::More tests => 3;
  24. use testutil;
  25. #init_test_dirs();
  26. # Since here we're doing black-box testing on the stow executable,
  27. # this looks like it should be robust:
  28. #
  29. #my $STOW = dirname(__FILE__) . '/../bin/stow';
  30. #
  31. # but unfortunately it breaks things like "make distcheck", which
  32. # builds the stow script into a separate path like
  33. #
  34. # stow-2.3.0/_build/sub/bin
  35. #
  36. # before cd'ing to something like
  37. #
  38. # stow-2.3.0/_build/sub
  39. #
  40. # and then running the tests via:
  41. #
  42. # make check-TESTS
  43. # make[2]: Entering directory '/path/to/stow/src/stow-2.3.0/_build/sub'
  44. # dir=../../t; \
  45. # /usr/bin/perl -Ibin -Ilib -I../../t -MTest::Harness -e 'runtests(@ARGV)' "${dir#./}"/*.t
  46. #
  47. # So the simplest solution is to hardcode an assumption that we run
  48. # tests either from somewhere like this during distcheck:
  49. #
  50. # stow-2.3.0/_build/sub
  51. #
  52. # or from the top of the source tree during development. This can be done
  53. # via the following, which also follows the KISS principle:
  54. my $STOW = "$^X bin/stow";
  55. `$STOW --help`;
  56. is($?, 0, "--help should return 0 exit code");
  57. my $err = `$STOW --foo 2>&1`;
  58. is($? >> 8, 1, "unrecognised option should return 1 exit code");
  59. like($err, qr/^Unknown option: foo$/m, "unrecognised option should be listed");
  60. # vim:ft=perl