misc.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/bin/sh
  2. # Miscellaneous tests for "ln".
  3. # Copyright (C) 1998-2018 Free Software Foundation, Inc.
  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 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  15. print_ver_ ln
  16. t=tln-symlink
  17. d=tln-subdir
  18. ld=tln-symlink-to-subdir
  19. f=tln-file
  20. # Create a simple symlink with both source and destination files
  21. # in current directory.
  22. touch $f || framework_failure_
  23. rm -f $t || framework_failure_
  24. ln -s $f $t || fail=1
  25. test -f $t || fail=1
  26. rm $t $f
  27. # Create a symlink with source file and explicit destination directory/file.
  28. touch $f || framework_failure_
  29. rm -rf $d || framework_failure_
  30. mkdir $d || framework_failure_
  31. ln -s ../$f $d/$t || fail=1
  32. test -f $d/$t || fail=1
  33. rm -rf $d $f
  34. # Create a symlink with source file and destination directory.
  35. touch $f || framework_failure_
  36. rm -rf $d || framework_failure_
  37. mkdir $d || framework_failure_
  38. ln -s ../$f $d || fail=1
  39. test -f $d/$f || fail=1
  40. rm -rf $d $f
  41. # See whether a trailing slash is followed too far.
  42. touch $f || framework_failure_
  43. rm -rf $d || framework_failure_
  44. mkdir $d $d/$f || framework_failure_
  45. returns_ 1 ln $f $d/ 2> /dev/null || fail=1
  46. returns_ 1 ln -s $f $d/ 2> /dev/null || fail=1
  47. rm -rf $d $f
  48. # Make sure we get a failure with existing dest without -f option
  49. touch $t || framework_failure_
  50. # FIXME: don't ignore the error message but rather test
  51. # it to make sure it's the right one.
  52. returns_ 1 ln -s $t $t 2> /dev/null || fail=1
  53. rm $t
  54. # Make sure -sf fails when src and dest are the same
  55. touch $t || framework_failure_
  56. returns_ 1 ln -sf $t $t 2> /dev/null || fail=1
  57. rm $t
  58. # Create a symlink with source file and no explicit directory
  59. rm -rf $d || framework_failure_
  60. mkdir $d || framework_failure_
  61. touch $d/$f || framework_failure_
  62. ln -s $d/$f || fail=1
  63. test -f $f || fail=1
  64. rm -rf $d $f
  65. # Create a symlink with source file and destination symlink-to-directory.
  66. rm -rf $d $f $ld || framework_failure_
  67. touch $f || framework_failure_
  68. mkdir $d || framework_failure_
  69. ln -s $d $ld
  70. ln -s ../$f $ld || fail=1
  71. test -f $d/$f || fail=1
  72. rm -rf $d $f $ld
  73. # Create a symlink with source file and destination symlink-to-directory.
  74. # BUT use the new --no-dereference option.
  75. rm -rf $d $f $ld || framework_failure_
  76. touch $f || framework_failure_
  77. mkdir $d || framework_failure_
  78. ln -s $d $ld
  79. af=$(pwd)/$f
  80. ln --no-dereference -fs "$af" $ld || fail=1
  81. test -f $ld || fail=1
  82. rm -rf $d $f $ld
  83. # Try to create a symlink with backup where the destination file exists
  84. # and the backup file name is a hard link to the destination file.
  85. touch a b || framework_failure_
  86. ln b b~ || framework_failure_
  87. ln -f --b=simple a b || fail=1
  88. # ===================================================
  89. # Make sure ln can make simple backups.
  90. # This was fixed in 4.0.34. Broken in 4.0r.
  91. for cmd in ln cp mv ginstall; do
  92. rm -rf a x a.orig
  93. touch a x || framework_failure_
  94. $cmd --backup=simple --suffix=.orig x a || fail=1
  95. test -f a.orig || fail=1
  96. done
  97. # ===================================================
  98. # With coreutils-5.2.1, this would mistakenly access argv[1][-1].
  99. # I'm including it here, in case some day programs like valgrind detect that.
  100. # Purify probably would have done so.
  101. ln foo '' 2> /dev/null
  102. # ===================================================
  103. Exit $fail