• 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_softlink" "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_softlinks" "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 -rf file dir slink
48
49touch file1 file2 && mkdir dir
50testing "create_multiple_hardlinks" "ln file* dir/ &&
51   [ file1 -ef dir/file1 -a file2 -ef dir/file2 ] && echo 'yes'" "yes\n" "" ""
52rm -rf file* dir
53
54touch file1 file2 && mkdir dir
55testing "create_multiple_softlinks" "ln -s file* dir/ &&
56          [ -L dir/file1 -a -L dir/file2 ] && readlink dir/file1 &&
57          readlink dir/file2" "file1\nfile2\n" "" ""
58rm -rf file* dir
59
60echo file1 > file
61testing "create_softlink_and_remove_sourcefile" "ln -s file slink &&
62          [ -L slink ] && rm file && cat slink 2>/dev/null || echo 'yes' " \
63          "yes\n" "" ""
64rm -f file slink
65
66echo file1 > file
67testing "create_hardlink_and_remove_sourcefile" "ln file hlink &&
68          [ file -ef hlink ] && rm file && [ -f hlink ] && echo 'yes'" \
69          "yes\n" "" ""
70rm -f file hlink
71