-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_find.sh
64 lines (45 loc) · 1.51 KB
/
test_find.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
#!/bin/sh
# shellcheck disable=SC2317
beforeAll() {
find() { # find mock
case "$1" in
'error') echo "find mock returned error" >&2; return 1 ;;
*) printf '<mock:%s>' "$1"; return 0 ;;
esac
}
}
afterAll() {
unset -f find
}
test_arg_empty() {
result=$(unittest__test_files 2>&1)
test $? -eq 0 && test "${result}" = '<mock:./>' # default substition of first argument in implementation
}
test_arg_directory() {
result=$(unittest__test_files 'some_dir/' 2>&1)
test $? -eq 0 && test "${result}" = '<mock:some_dir/>'
}
test_args_directories() {
result=$(unittest__test_files 'some_dir/' 'some_other_dir/' 2>&1)
test $? -eq 0 && test "${result}" = '<mock:some_dir/><mock:some_other_dir/>'
}
test_arg_invalid_directory() {
result=$(unittest__test_files 'error' 2>&1)
test $? -eq 1 && test -n "${result}"
}
test_args_invalid_directory() {
result=$(unittest__test_files 'some_dir/' 'error' 'some_other_dir/' 2>&1)
test $? -eq 1 && test -n "${result}"
}
test_stdin_directory() {
result=$(printf 'some_dir/\n' | unittest__test_files - 2>&1)
test $? -eq 0 && test "${result}" = '<mock:some_dir/>'
}
test_stdin_directories() {
result=$(printf 'some_dir/\nsome_other_dir/\n' | unittest__test_files - 2>&1)
test $? -eq 0 && test "${result}" = '<mock:some_dir/><mock:some_other_dir/>'
}
test_stdin_invalid_directory() {
result=$(printf 'some_dir/\nerror\nsome_other_dir/\n' | unittest__test_files - 2>&1)
test $? -eq 1 && test -n "${result}"
}