1# TODO(ninja/test2|test4|test5) ninja: multiple problems
2# ninja: find . finds ninja temporary files
3# ninja: escaping ! doesn't seem to be working
4# ninja: stderr gets reordered
5
6ifeq ($(shell uname),Darwin)
7USE_GNU_FIND:=
8else
9USE_GNU_FIND:=1
10endif
11
12define run_find
13@echo $$ '$(strip $(1))'
14@echo $(shell $(1))
15endef
16
17test1:
18 mkdir testdir
19 touch testdir/file1
20 touch testdir/file2
21 mkdir testdir/dir1
22 touch testdir/dir1/file1
23 touch testdir/dir1/file2
24 touch testdir/dir1/file3
25 mkdir testdir/dir2
26 touch testdir/dir2/file1
27 touch testdir/dir2/file2
28 touch testdir/dir2/file3
29 ln -s ../dir1/file1 testdir/dir2/link1
30 ln -s ../../testdir/dir1 testdir/dir2/link2
31 ln -s broken testdir/dir2/link3
32 mkdir -p build/tools
33 cp ../../../testcase/tools/findleaves.py build/tools
34
35 mkdir -p testdir3/b/c/d
36 ln -s b testdir3/a
37 touch testdir3/b/c/d/e
38
39 mkdir -p testdir4/a/b
40 ln -s self testdir4/self
41 ln -s .. testdir4/a/b/c
42 ln -s b testdir4/a/l
43
44 mkdir -p testdir5
45 ln -s a testdir5/a
46 ln -s b testdir5/c
47 ln -s c testdir5/b
48
49test2:
50 @echo no options
51 $(call run_find, find testdir)
52 $(call run_find, find .)
53ifeq ($(USE_GNU_FIND),1)
54 $(call run_find, find ./)
55 $(call run_find, find .///)
56 $(call run_find, find )
57 $(call run_find, find ./.)
58 $(call run_find, find ././)
59endif
60 $(call run_find, find testdir/../testdir)
61 @echo print
62 $(call run_find, find testdir -print)
63 @echo conditiions
64 $(call run_find, find testdir -name foo)
65 $(call run_find, find testdir -name file1)
66 $(call run_find, find testdir -name "file1")
67 $(call run_find, find testdir -name "file1")
68 $(call run_find, find testdir -name "*1")
69 $(call run_find, find testdir -name "*1" -name "file*")
70 $(call run_find, find testdir -name "*1" -and -name "file*")
71 $(call run_find, find testdir -name "*1" -or -name "file*")
72 $(call run_find, find testdir -name "*1" -or -type f)
73 $(call run_find, find testdir -name "*1" -or -not -type f)
74 $(call run_find, find testdir -name "*1" -or \! -type f)
75 $(call run_find, find testdir -name "*1" -or -type d)
76 $(call run_find, find testdir -name "*1" -or -type l)
77 $(call run_find, find testdir -name "*1" -a -type l -o -name "dir*")
78 $(call run_find, find testdir -name "dir*" -o -name "*1" -a -type l)
79 $(call run_find, find testdir \( -name "dir*" -o -name "*1" \) -a -type f)
80 @echo cd
81 $(call run_find, cd testdir && find)
82 $(call run_find, cd testdir/// && find .)
83 $(call run_find, cd testdir///dir1// && find .///)
84 $(call run_find, cd testdir && find ../testdir)
85 @echo test
86 $(call run_find, test -d testdir && find testdir)
87 $(call run_find, if [ -d testdir ] ; then find testdir ; fi)
88 $(call run_find, if [ -d testdir ]; then find testdir; fi)
89 $(call run_find, if [ -d testdir ]; then cd testdir && find .; fi)
90 $(call run_find, test -d testdir//dir1/// && find testdir///dir1///)
91 $(call run_find, test -d testdir//.///dir1/// && find testdir//.///dir1///)
92 @echo prune
93 $(call run_find, find testdir -name dir2 -prune -o -name file1)
94 @echo multi
95 $(call run_find, find testdir testdir)
96 @echo symlink
97 $(call run_find, find -L testdir -type f)
98 $(call run_find, find -L testdir -type d)
99 $(call run_find, find -L testdir -type l)
100 $(call run_find, cd testdir; find -L . -type f)
101 $(call run_find, cd testdir; find -L . -type d)
102 $(call run_find, cd testdir; find -L . -type l)
103 @echo maxdepth
104 $(call run_find, find testdir -maxdepth 1)
105 $(call run_find, find testdir -maxdepth 2)
106 $(call run_find, find testdir -maxdepth 0)
107 $(call run_find, find testdir -maxdepth hoge)
108 $(call run_find, find testdir -maxdepth 1hoge)
109 $(call run_find, find testdir -maxdepth -1)
110 @echo findleaves
111 $(call run_find, build/tools/findleaves.py testdir file1)
112 $(call run_find, build/tools/findleaves.py testdir file3)
113 $(call run_find, build/tools/findleaves.py --prune=dir1 testdir file3)
114 $(call run_find, build/tools/findleaves.py --prune=dir1 --prune=dir2 testdir file3)
115 $(call run_find, build/tools/findleaves.py --mindepth=1 testdir file1)
116 $(call run_find, build/tools/findleaves.py --mindepth=2 testdir file1)
117 $(call run_find, build/tools/findleaves.py --mindepth=3 testdir file1)
118 $(call run_find, build/tools/findleaves.py --mindepth=2 testdir file1)
119 $(call run_find, build/tools/findleaves.py --prune=dir1 --dir=testdir file1)
120 $(call run_find, build/tools/findleaves.py --prune=dir1 --dir=testdir file3 link3)
121 @echo missing chdir / testdir
122 $(call run_find, cd xxx && find .)
123 $(call run_find, if [ -d xxx ]; then find .; fi)
124
125test3:
126 $(call run_find, find testdir3/a/c)
127 $(call run_find, if [ -d testdir3/a/c ]; then find testdir3/a/c; fi)
128 $(call run_find, cd testdir3/a/c && find .)
129 $(call run_find, build/tools/findleaves.py testdir3 e)
130
131test4:
132 $(call run_find, find -L testdir4)
133
134test5:
135 $(call run_find, find -L testdir5)
136 $(call run_find, build/tools/findleaves.py testdir5 x)