aboutsummaryrefslogtreecommitdiff
path: root/tests/find.test
blob: 710684ec46c375dbdd0bd1764272939d44f9a70d (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
#!/bin/bash

[ -f testing.sh ] && . testing.sh

mkdir dir
cd dir
touch file
mkfifo fifo
ln -s fifo link
cd ..
touch b

mkdir perm
touch perm/all-read-only
chmod a=r perm/all-read-only

#testing "name" "command" "result" "infile" "stdin"

# Testing operators

testing "find -type l -a -type d -o -type p" \
	"find dir -type l -a -type d -o -type p" "dir/fifo\n" "" ""
testing "find -type l -type d -o -type p" "find dir -type l -type d -o -type p" \
	"dir/fifo\n" "" ""
testing "find -type l -o -type d -a -type p" \
	"find dir -type l -o -type d -a -type p" "dir/link\n" "" ""
testing "find -type l -o -type d -type p" "find dir -type l -o -type d -type p" \
	"dir/link\n" "" ""
testing "find -type l ( -type d -o -type l )" \
	"find dir -type l \( -type d -o -type l \)" "dir/link\n" "" ""
testing "find extra parentheses" \
	"find dir \( \( -type l \) \( -type d -o \( \( -type l \) \) \) \)" \
	"dir/link\n" "" ""
testing "find ( -type p -o -type d ) -type p" \
	"find dir \( -type p -o -type d \) -type p" "dir/fifo\n" "" ""
testing "find -type l -o -type d -type p -o -type f" \
	"find dir -type l -o -type d -type p -o -type f | sort" \
	"dir/file\ndir/link\n" "" ""

# Testing short-circuit evaluations

testing "find -type f -a -print" \
	"find dir -type f -a -print" "dir/file\n" "" ""
testing "find -print -o -print" \
	"find dir -type f -a \( -print -o -print \)" "dir/file\n" "" ""

# these were erroring or segfaulting:
# find -type f -user nobody -exec : \;
# find -type f -user nobody -exec : -exec : \;

# Testing previous failures

testing "find -type f -user -exec" \
  "find dir -type f -user $USER -exec ls {} \\;" "dir/file\n" "" ""
testing "find -type l -newer -exec" \
  "find dir -type l -newer dir/file -exec ls {} \\;" "dir/link\n" "" ""
testing "find -perm (exact success)" \
  "find perm -type f -perm 0444" "perm/all-read-only\n" "" ""
testing "find -perm (exact failure)" \
  "find perm -type f -perm 0400" "" "" ""
testing "find -perm (min success)" \
  "find perm -type f -perm -0400" "perm/all-read-only\n" "" ""
testing "find -perm (min failure)" \
  "find perm -type f -perm -0600" "" "" ""
testing "find -perm (any success)" \
  "find perm -type f -perm -0444" "perm/all-read-only\n" "" ""
testing "find -perm (any failure)" \
  "find perm -type f -perm -0222" "" "" ""

# Still fails

testing "find unterminated -exec {}" \
  "find dir -type f -exec ls {} 2>/dev/null || echo bad" "bad\n" "" ""
testing "find -exec {} +" \
  "find dir -type f -exec ls {} +" "dir/file\n" "" ""

# `find . -iname` was segfaulting
testing "find -name file" \
  "find dir -name file" "dir/file\n" "" ""
testing "find -name FILE" \
  "find dir -name FILE" "" "" ""

testing "find -iname file" \
  "find dir -iname FILE" "dir/file\n" "" ""
testing "find -iname FILE" \
  "find dir -iname FILE" "dir/file\n" "" ""


testing "find -name (no arguments)" \
  "find dir -name 2>&1" "find: '-name' needs 1 arg\n" "" ""
testing "find -iname (no arguments)" \
  "find dir -iname 2>&1" "find: '-iname' needs 1 arg\n" "" ""
rm -rf dir