2
0

self-check-shell-no-trail-bslash.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #! /bin/sh
  2. # Copyright (C) 2012-2017 Free Software Foundation, Inc.
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2, or (at your option)
  7. # any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. # Check that our fake "shell" used to guard against use of trailing
  17. # backslashes in recipes actually complains when those are used.
  18. # Our hack doesn't work with some make implementations (see comments
  19. # in 't/ax/shell-no-trail-bslash.in' for more details).
  20. required=GNUmake
  21. am_create_testdir=empty
  22. . test-init.sh
  23. cat >> Makefile <<'END'
  24. am__backslash = \\ # foo
  25. .PHONY: good bad
  26. good:
  27. @printf '%s\n' OK
  28. .PHONY: bad
  29. bad:
  30. @echo $(am__backslash)
  31. END
  32. SHELL=$am_testaux_builddir/shell-no-trail-bslash
  33. $SHELL -c 'exit 0'
  34. test "$($SHELL -c 'echo is o\k')" = "is ok"
  35. echo 'echo is ok\"' > ok.sh
  36. $SHELL ./ok.sh
  37. test "$($SHELL ./ok.sh)" = "is ok\""
  38. tab=' '
  39. nl='
  40. '
  41. for sfx in \
  42. '\' \
  43. '\\' \
  44. '\\\\\' \
  45. '\ ' \
  46. "\\$tab" \
  47. "\\ $tab$tab " \
  48. "\\$nl" \
  49. "\\ $nl " \
  50. "\\$nl$nl$nl" \
  51. ; do
  52. for pfx in "" "echo bad" ": a${nl}# multine${nl}: text"; do
  53. cmd=${pfx}${sfx}
  54. printf '%s' "$cmd" > bad.sh
  55. for args in '-c "$cmd"' './bad.sh'; do
  56. eval "\$SHELL $args 2>stderr && { cat stderr >&2; exit 1; }; :"
  57. cat stderr >&2
  58. $FGREP "recipe/script ends with backslash character" stderr
  59. cmd="$cmd" $PERL -w -e '
  60. undef $/;
  61. $_ = <>;
  62. index($_, $ENV{cmd}) >= 0 or exit 1;
  63. ' <stderr
  64. $FGREP "$cmd" stderr
  65. done
  66. done
  67. done
  68. $MAKE good
  69. run_make -E -e FAIL bad SHELL="$SHELL"
  70. $FGREP "recipe/script ends with backslash character" stderr
  71. :