-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrealpath-test.sh
executable file
·117 lines (83 loc) · 2.04 KB
/
realpath-test.sh
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
#!/usr/bin/env roundup
describe "realpath"
before() {
touch tmp
}
after() {
rm tmp
}
it_displays_usage() {
out="$(./realpath -h | head -n 1)"
test "$out" = "Usage: realpath [options] path [...]"
}
it_converts_absolute_paths_without_change() {
rel_path="/usr/local/bin"
out_path="$(./realpath "$rel_path")"
test "$out_path" = "$rel_path"
}
it_converts_root_path_without_change() {
rel_path="/"
out_path="$(./realpath "$rel_path")"
test "$out_path" = "$rel_path"
}
it_converts_dotted_relative_paths() {
cwd="$(pwd)"
cur_dir="$(basename "$cwd")"
rel_path="../${cur_dir}/"
abs_path="$cwd"
out_path="$(./realpath "$rel_path")"
test "$out_path" = "$abs_path"
}
it_converts_dot_path_to_cwd() {
rel_path="."
abs_path="$(pwd)"
out_path="$(./realpath "$rel_path")"
test "$out_path" = "$abs_path"
}
it_converts_local_paths() {
cwd="$(pwd)"
rel_path="README.md"
abs_path="${cwd}/README.md"
out_path="$(./realpath "$rel_path")"
test "$out_path" = "$abs_path"
}
it_converts_local_paths_which_exist_in_root_path() {
cwd="$(pwd)"
rel_path="tmp"
abs_path="${cwd}/${rel_path}"
out_path="$(./realpath "$rel_path")"
test "$out_path" = "$abs_path"
}
it_fails_for_nonexistent_paths() {
rel_path="/usr/local/mojo-jojo/but_first--i_must_attend_to_the_dishes_that_i_have_soiled_with_the_food_that_i_have_eaten"
out=$(set +e ; ./realpath "$rel_path" >/dev/null ; echo $?)
test $out -gt 0
}
it_fails_for_relative_home_paths() {
user="$(whoami)"
rel_path="~/Desktop/"
abs_path="${HOME}/Desktop/"
out=$(set +e ; ./realpath "$rel_path" >/dev/null ; echo $?)
test $out -gt 0
}
it_converts_file_symlinks() {
cwd="$(pwd)"
ln -s tmp stmp
rel_path="stmp"
abs_path="${cwd}/$(readlink "$rel_path")"
out_path="$(./realpath "$rel_path")"
rm stmp
test "$out_path" = "$abs_path"
}
it_converts_symlinks_in_paths() {
cwd="$(pwd)"
mkdir tmpdir
touch tmpdir/tmp
ln -s tmpdir stmpdir
rel_path="stmpdir/tmp"
abs_path="${cwd}/tmpdir/tmp"
out_path="$(./realpath "$rel_path")"
rm stmpdir
rm -r tmpdir
test "$out_path" = "$abs_path"
}