• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3# Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
4# Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
5
6[ -f testing.sh ] && . testing.sh
7
8#testing "name" "command" "result" "infile" "stdin"
9#set -x
10
11echo file1 > file
12testing "create_hardlink" "ln file hlink && [ file -ef hlink ] &&
13          echo 'yes'" "yes\n" "" ""
14testing "create_softlink" "ln -s file slink && [ -L slink ] &&
15          readlink slink" "file\n" "" ""
16rm slink hlink
17
18echo hlink1 > hlink
19testing "force_create_hardlink" "ln -f file hlink &&
20          [ file -ef hlink ] && cat hlink 2>/dev/null" "file1\n" "" ""
21
22echo slink1 > slink
23testing "force_create_symlink" "ln -f -s file slink &&
24          [ -L slink ] && readlink slink" "file\n" "" ""
25rm slink hlink
26
27echo hlink1 > hlink
28set +e
29testing "preserves_hardlinks" "ln file hlink 2>/dev/null || echo 'yes'" \
30          "yes\n" "" ""
31
32echo slink1 > slink
33set +e
34testing "preserves_symlinks" "ln -s file slink 2>/dev/null || echo 'yes'" \
35          "yes\n" "" ""
36rm slink hlink
37
38mkdir dir
39testing "multilevel_symbolic_links" "ln -s dir slink &&
40          ln -s file slink && [ -L slink -a -L slink/file ] &&
41          readlink slink && readlink slink/file" "dir\nfile\n" "" ""
42rm slink
43
44testing "no_dereference" "ln -s dir slink &&
45          ln -n -s file slink 2>/dev/null || [ -L slink ] && readlink slink" \
46          "dir\n" "" ""
47rm slink
48
49testing "-T acts like -n" "ln -s dir slink &&
50          ln -Tsf file slink || [ -L slink ] && readlink slink" "file\n" "" ""
51rm slink
52
53testing "-T with dir" "ln -Ts file dir 2>/dev/null || echo yes" "yes\n" "" ""
54rm -rf file dir slink
55
56testing "-t" "ln -st . one/two three && readlink two three" "one/two\nthree\n" \
57  "" ""
58rm -f two three
59
60touch file1 file2 && mkdir dir
61testing "create_multiple_hardlinks" "ln file* dir/ &&
62   [ file1 -ef dir/file1 -a file2 -ef dir/file2 ] && echo 'yes'" "yes\n" "" ""
63rm -rf file* dir
64
65touch file1 file2 && mkdir dir
66testing "create_multiple_softlinks" "ln -s file* dir/ &&
67          [ -L dir/file1 -a -L dir/file2 ] && readlink dir/file1 &&
68          readlink dir/file2" "file1\nfile2\n" "" ""
69rm -rf file* dir
70
71echo file1 > file
72testing "create_softlink_and_remove_sourcefile" "ln -s file slink &&
73          [ -L slink ] && rm file && cat slink 2>/dev/null || echo 'yes' " \
74          "yes\n" "" ""
75rm -f file slink
76
77echo file1 > file
78testing "create_hardlink_and_remove_sourcefile" "ln file hlink &&
79          [ file -ef hlink ] && rm file && [ -f hlink ] && echo 'yes'" \
80          "yes\n" "" ""
81rm -f file hlink
82
83mkdir -p one/two
84ln -s . circular
85mkdir -p three
86echo hello > three/four
87testing "ln -r" \
88  "ln -sr circular/three/../three/four one/two/five && cat one/two/five" \
89  "hello\n" "" ""
90rm -rf one three circular
91