summaryrefslogtreecommitdiff
path: root/tests/file_name.at
blob: e263ce3260dec57f27c728704542b1c0c4a377f2 (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
AT_BANNER([test dir_name and base_name functions])

m4_define([CHECK_FILE_NAME],
  [AT_SETUP([components of "$1" are "$2", "$3"])
   AT_SKIP_IF([test "$IS_WIN32" = "yes"])
   AT_KEYWORDS([dir_name base_name])
   AT_CHECK([ovstest test-util file_name "AS_ESCAPE($1)"], [0], [$2
$3
])
   AT_CLEANUP])

# These are the test cases given in POSIX for dirname() and basename().
CHECK_FILE_NAME([/usr/lib], [/usr], [lib])
CHECK_FILE_NAME([/usr/], [/], [usr])
CHECK_FILE_NAME([usr], [.], [usr])
CHECK_FILE_NAME([/], [/], [/])
CHECK_FILE_NAME([.], [.], [.])
CHECK_FILE_NAME([..], [.], [..])
CHECK_FILE_NAME([//], [//], [//])       # / is also allowed
CHECK_FILE_NAME([//foo], [//], [foo])   # / is also allowed for dirname
CHECK_FILE_NAME([], [.], [.])

# Additional test cases.
CHECK_FILE_NAME([dir/file], [dir], [file])
CHECK_FILE_NAME([dir/file/], [dir], [file])
CHECK_FILE_NAME([dir/file//], [dir], [file])
CHECK_FILE_NAME([///foo], [/], [foo])

AT_BANNER([test follow_symlinks function])

m4_define([CHECK_FOLLOW],
  [echo "check $1 -> $2"
   AT_CHECK_UNQUOTED([ovstest test-util follow-symlinks "$1"], [0], [$2
])
   echo])

AT_SETUP([follow_symlinks - relative symlinks])
: > target
ln -s target source
AT_SKIP_IF([test ! -h source])
CHECK_FOLLOW([source], [target])

mkdir dir
ln -s target2 dir/source2
CHECK_FOLLOW([dir/source2], [dir/target2])

mkdir dir/dir2
ln -s dir/b a
ln -s c dir/b
ln -s dir2/d dir/c
CHECK_FOLLOW([a], [dir/dir2/d])
AT_CLEANUP

AT_SETUP([follow_symlinks - absolute symlinks])
: > target
ln -s "`pwd`/target" source
AT_SKIP_IF([test ! -h source])
CHECK_FOLLOW([source], [`pwd`/target])

mkdir dir
ln -s "`pwd`/dir/target2" dir/source2
CHECK_FOLLOW([dir/source2], [`pwd`/dir/target2])

mkdir dir/dir2
ln -s "`pwd`/dir/b" a
ln -s "`pwd`/dir/c" dir/b
ln -s "`pwd`/dir/dir2/d" dir/c
CHECK_FOLLOW([a], [`pwd`/dir/dir2/d])
AT_CLEANUP

AT_SETUP([follow_symlinks - symlinks to directories])
mkdir target
ln -s target source
AT_SKIP_IF([test ! -h source])
ln -s target/ source2
CHECK_FOLLOW([source], [target])
CHECK_FOLLOW([source2], [target/])

# follow_symlinks() doesn't expand symlinks in the middle of a name.
: > source/x
CHECK_FOLLOW([source/x], [source/x])
AT_CLEANUP

AT_SETUP([follow_symlinks - nonexistent targets])
ln -s target source
AT_SKIP_IF([test ! -h source])
CHECK_FOLLOW([source], [target])
CHECK_FOLLOW([target], [target])
CHECK_FOLLOW([target], [target])
AT_CLEANUP

AT_SETUP([follow_symlinks - regular files])
touch x
CHECK_FOLLOW([x], [x])
AT_CLEANUP

AT_SETUP([follow_symlinks - device targets])
AT_SKIP_IF([test ! -e /dev/null])
AT_SKIP_IF([test ! -e /dev/full])
ln -s /dev/null x
ln -s /dev/full y
CHECK_FOLLOW([x], [/dev/null])
CHECK_FOLLOW([y], [/dev/full])
AT_CLEANUP

AT_SETUP([follow_symlinks - nonexistent files])
AT_SKIP_IF([test "$IS_WIN32" = "yes"])
CHECK_FOLLOW([nonexistent], [nonexistent])
CHECK_FOLLOW([a/b/c], [a/b/c])
CHECK_FOLLOW([/a/b/c], [/a/b/c])
CHECK_FOLLOW([//a/b/c], [//a/b/c])
AT_CLEANUP

AT_SETUP([follow_symlinks - symlink loop])
ln -s a b
AT_SKIP_IF([test ! -h b])
ln -s b a
AT_SKIP_IF([test ! -h a])

AT_CHECK([ovstest test-util follow-symlinks a], [0], [a
], [stderr])
AT_CHECK([sed 's/^[[^|]]*|//' stderr], [0],
  [00001|util|WARN|a: too many levels of symlinks
])
AT_CLEANUP