ln_tests.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. # Copyright (c) International Business Machines Corp., 2001
  4. # Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
  5. # Author: Manoj Iyer <manjo@mail.utexas.edu>
  6. #
  7. # Basic test for ln
  8. TST_CNT=6
  9. TST_TESTFUNC=do_test
  10. TST_SETUP=setup
  11. TST_NEEDS_TMPDIR=1
  12. . tst_test.sh
  13. setup()
  14. {
  15. ROD mkdir -p dir/subdir
  16. ROD echo "LTP" > file
  17. ROD touch dir/file
  18. }
  19. check_dir_link()
  20. {
  21. local dname="$1"
  22. local lname="$2"
  23. ROD ls "$lname" > lname.out
  24. ROD ls "$dname" > dname.out
  25. if diff lname.out dname.out; then
  26. tst_res TPASS "Directory and link content is equal"
  27. else
  28. tst_res TFAIL "Directory and link content differs"
  29. cat lname.out
  30. echo
  31. cat dname.out
  32. fi
  33. }
  34. check_file_link()
  35. {
  36. local fname="$1"
  37. local lname="$2"
  38. if diff $fname $lname; then
  39. tst_res TPASS "File and link content is equal"
  40. else
  41. tst_res TFAIL "File and link content differs"
  42. fi
  43. }
  44. ln_test()
  45. {
  46. local args="$1"
  47. local src="$2"
  48. local link="$3"
  49. EXPECT_PASS ln $args $src $link
  50. if [ -f $src ]; then
  51. check_file_link $src $link
  52. else
  53. check_dir_link $src $link
  54. fi
  55. ROD rm $link
  56. }
  57. do_test()
  58. {
  59. case $1 in
  60. 1) ln_test "" "file" "file_link";;
  61. 2) ln_test "-s" "file" "file_link";;
  62. 3) ln_test "-s" "dir" "dir_link";;
  63. 4) ln_test "" "$PWD/file" "file_link";;
  64. 5) ln_test "-s" "$PWD/file" "file_link";;
  65. 6) ln_test "-s" "$PWD/dir" "dir_link";;
  66. esac
  67. }
  68. tst_run