aboutsummaryrefslogtreecommitdiff
path: root/tests/builtin/ln.testscript
blob: ed4ca677c5c379ec2c44ec0cf01149ba5fdd1aa5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# file      : tests/builtin/ln.testscript
# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
# license   : MIT; see accompanying LICENSE file

test.arguments = "ln"
test.options += -c

: unknown-option
:
$* -u >'option -u' 2>"ln: unknown option '-u'" == 1

: args
:
{
  : -s-option
  :
  $* 2>"ln: missing -s|--symbolic option" == 1

  : none
  :
  $* -s 2>"ln: missing arguments" == 1

  : no-target
  :
  $* -s a 2>"ln: missing target path" == 1

  : no-trailing-sep
  :
  $* -s a b c 2>"ln: multiple target paths with non-directory link path" == 1

  : empty
  :
  {
    : link
    :
    $* -s '' 2>"ln: invalid path ''" == 1

    : target1
    :
    $* -s '' a 2>"ln: invalid path ''" == 1

    : target2
    :
    $* -s '' a b/ 2>"ln: invalid path ''" == 1
  }
}

: file
:
: Test creating a file symlink.
:
{
  : non-existing-link-path
  :
  {
    touch a;

    $* -s a b >>/~%EOO% &b;
      %create .+/b true%
      %create .+/b false%
      EOO

    test -f b
  }

  : existing-link
  :
  {
    : file
    :
    {
      touch a b;

      $* -s a b >>/~%EOO% 2>>/~%EOE% != 0
        %create .+/b true%
        EOO
        %(
        %ln: unable to create .+link '.+/b' to '.+/a': .+%|
        %ln: unable to copy file '.+/a' to '.+/b': .+%
        %)
        EOE
    }

    : dir
    :
    {
      touch a;
      mkdir b;

      $* -s a b >>/~%EOO% 2>>/~%EOE% != 0
        %create .+/b true%
        EOO
        %(
        %ln: unable to create .+link '.+/b' to '.+/a': .+%|
        %ln: unable to copy file '.+/a' to '.+/b': .+%
        %)
        EOE
    }
  }

  : non-existing
  {
    : target
    :
    {
      $* -s a b 2>>/~%EOE% != 0
        %ln: unable to create symlink to '.+/a': no such file or directory%
        EOE
    }

    : link-dir
    :
    {
      touch a;

      $* -s a b/c >>/~%EOO% 2>>/~%EOE% != 0
        %create .+/b/c true%
        EOO
        %(
        %ln: unable to create .+link '.+/b/c' to '.+/a': .+%|
        %ln: unable to copy file '.+/a' to '.+/b/c': .+%
        %)
        EOE
    }
  }
}

: dir
:
: Test creating a directory symlink.
:
{
  : non-existing-link-path
  :
  {
    mkdir a;
    touch a/b;

    $* -s a c >>/~%EOO% &c;
      %create .+/c true%
      %create .+/c false%
      EOO

    test -f c/b
  }

  : existing-link
  :
  {
    : dir
    :
    {
      mkdir a b;

      $* -s a b >>/~%EOO% 2>>/~%EOE% != 0
        %create .+/b true%
        EOO
        %(
        %ln: unable to create .+link '.+/b' to '.+/a': .+%|
        %ln: unable to copy directory '.+/a' to '.+/b': .+%
        %)
        EOE
    }

    : file
    :
    {
      mkdir a;
      touch b;

      $* -s a b >>/~%EOO% 2>>/~%EOE% != 0
        %create .+/b true%
        EOO
        %(
        %ln: unable to create .+link '.+/b' to '.+/a': .+%|
        %ln: unable to copy directory '.+/a' to '.+/b': .+%
        %)
        EOE
    }
  }

  : non-existing
  {
    : link-dir
    :
    {
      mkdir a;

      $* -s a b/c >>/~%EOO% 2>>/~%EOE% != 0
        %create .+/b/c true%
        EOO
        %(
        %ln: unable to create .+link '.+/b/c' to '.+/a': .+%|
        %ln: unable to copy directory '.+/a' to '.+/b/c': .+%
        %)
        EOE
    }
  }
}

: multiple-targets
:
: Test creating links for multiple targets in the specified directory.
:
{
  touch a;
  mkdir b c;

  $* -s a b c/ >>/~%EOO% &c/a &c/b;
    %create .+/c/a true%
    %create .+/c/a false%
    %create .+/c/b true%
    %create .+/c/b false%
    EOO

  test -f c/a && test -d c/b
}