• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
9TST_CNT=6
10TST_TESTFUNC=do_test
11TST_SETUP=setup
12TST_NEEDS_TMPDIR=1
13
14setup()
15{
16	ROD mkdir -p dir/subdir
17	ROD echo "LTP" > file
18	ROD touch dir/file
19}
20
21check_dir_link()
22{
23	local dname="$1"
24	local lname="$2"
25
26	ROD ls "$lname" > lname.out
27	ROD ls "$dname" > dname.out
28
29	if diff lname.out dname.out; then
30		tst_res TPASS "Directory and link content is equal"
31	else
32		tst_res TFAIL "Directory and link content differs"
33		cat lname.out
34		echo
35		cat dname.out
36	fi
37}
38
39check_file_link()
40{
41	local fname="$1"
42	local lname="$2"
43
44	if diff $fname $lname; then
45		tst_res TPASS "File and link content is equal"
46	else
47		tst_res TFAIL "File and link content differs"
48	fi
49}
50
51ln_test()
52{
53	local args="$1"
54	local src="$2"
55	local link="$3"
56
57	EXPECT_PASS ln $args $src $link
58
59	if [ -f $src ]; then
60		check_file_link $src $link
61	else
62		check_dir_link $src $link
63	fi
64
65	ROD rm $link
66}
67
68do_test()
69{
70	case $1 in
71	1) ln_test ""   "file"      "file_link";;
72	2) ln_test "-s" "file"      "file_link";;
73	3) ln_test "-s" "dir"       "dir_link";;
74	4) ln_test ""   "$PWD/file" "file_link";;
75	5) ln_test "-s" "$PWD/file" "file_link";;
76	6) ln_test "-s" "$PWD/dir"  "dir_link";;
77	esac
78}
79
80. tst_test.sh
81tst_run
82