-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlsdirs.bats
More file actions
executable file
·42 lines (38 loc) · 1.03 KB
/
lsdirs.bats
File metadata and controls
executable file
·42 lines (38 loc) · 1.03 KB
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
#!/usr/bin/env bats
#The lsdirs function outputs a reverse sorted list of the
#directories within the directory that is the
#argument to the function. The list of subdirectories
#is one per line. If the number of
#arguments is not 1 or the argument is not
#a directory the function returns 1. Otherwise,
#the function returns 0.
lsdirs() {
if [ "$#" -ne 1 ] || ! [ -d "$1" ]; then
return 1
fi
ls -ld -- "$1"/* | grep "^d" | awk '{print $9}' | sed 's/\//\:/g' | awk -F: '{print $4}' | sort -r
return 0
}
@test "lsdirs" {
#lsdirs with no argument
run lsdirs
#assertions
[ $status -eq 1 ]
}
@test "lsdirs /etc/security" {
#lsdirs with directory argument
run lsdirs /etc/security
echo "$output"
#assertions
[ "${lines[0]}" = "namespace.d" ]
[ "${lines[1]}" = "limits.d" ]
[ "${lines[2]}" = "console.perms.d" ]
[ "${lines[3]}" = "console.apps" ]
[ $status -eq 0 ]
}
@test "lsdirs /etc/default/grub" {
#lsdirs with file argument
run lsdirs /usr/java/default/src.zip
#assertions
[ $status -eq 1 ]
}