blob: c3e8a079fd2872c0398c6642d6366feeb088bdbd [file] [log] [blame]
Shinichiro Hamaji9c5ec1d2015-10-15 15:20:14 +09001# TODO(go|ninja): This test is only for ckati. ninja: multiple problems
2# go: symlink support isn't enough.
Dan Willemsen48d6e8c2015-08-05 14:38:34 -07003# ninja: find . finds ninja temporary files
4# ninja: escaping ! doesn't seem to be working
5# ninja: stderr gets reordered
Shinichiro Hamaji5f57a992015-06-30 19:39:39 +09006
Shinichiro Hamaji40c856e2015-07-13 20:48:24 -07007ifeq ($(shell uname),Darwin)
8USE_GNU_FIND:=
9else
10USE_GNU_FIND:=1
11endif
12
Shinichiro Hamaji5f57a992015-06-30 19:39:39 +090013define run_find
14@echo $$ '$(strip $(1))'
Dan Willemsen48d6e8c2015-08-05 14:38:34 -070015@echo $(shell $(1))
Shinichiro Hamaji5f57a992015-06-30 19:39:39 +090016endef
17
18test1:
19 mkdir testdir
20 touch testdir/file1
21 touch testdir/file2
22 mkdir testdir/dir1
23 touch testdir/dir1/file1
24 touch testdir/dir1/file2
Shinichiro Hamajie7a68222015-08-06 17:07:29 +090025 touch testdir/dir1/file3
Shinichiro Hamaji5f57a992015-06-30 19:39:39 +090026 mkdir testdir/dir2
27 touch testdir/dir2/file1
28 touch testdir/dir2/file2
Shinichiro Hamajie7a68222015-08-06 17:07:29 +090029 touch testdir/dir2/file3
Shinichiro Hamaji5f57a992015-06-30 19:39:39 +090030 ln -s ../dir1/file1 testdir/dir2/link1
31 ln -s ../../testdir/dir1 testdir/dir2/link2
32 ln -s broken testdir/dir2/link3
Shinichiro Hamajie7a68222015-08-06 17:07:29 +090033 mkdir -p build/tools
34 cp ../../testcase/tools/findleaves.py build/tools
Shinichiro Hamaji5f57a992015-06-30 19:39:39 +090035
Shinichiro Hamajibd3bb232015-10-09 16:35:54 +090036 mkdir -p testdir3/b/c/d
37 ln -s b testdir3/a
Shinichiro Hamajib7175612015-10-13 16:15:34 +090038 touch testdir3/b/c/d/e
39
40 mkdir -p testdir4/a/b
41 ln -s self testdir4/self
42 ln -s .. testdir4/a/b/c
43 ln -s b testdir4/a/l
44
45 mkdir -p testdir5
46 ln -s a testdir5/a
47 ln -s b testdir5/c
48 ln -s c testdir5/b
Shinichiro Hamajibd3bb232015-10-09 16:35:54 +090049
Shinichiro Hamaji5f57a992015-06-30 19:39:39 +090050test2:
51 @echo no options
52 $(call run_find, find testdir)
53 $(call run_find, find .)
Shinichiro Hamaji40c856e2015-07-13 20:48:24 -070054ifeq ($(USE_GNU_FIND),1)
Shinichiro Hamaji5f57a992015-06-30 19:39:39 +090055 $(call run_find, find ./)
56 $(call run_find, find .///)
57 $(call run_find, find )
58 $(call run_find, find ./.)
59 $(call run_find, find ././)
Shinichiro Hamaji40c856e2015-07-13 20:48:24 -070060endif
Shinichiro Hamaji5f57a992015-06-30 19:39:39 +090061 $(call run_find, find testdir/../testdir)
62 @echo print
63 $(call run_find, find testdir -print)
64 @echo conditiions
65 $(call run_find, find testdir -name foo)
66 $(call run_find, find testdir -name file1)
67 $(call run_find, find testdir -name "file1")
68 $(call run_find, find testdir -name "file1")
69 $(call run_find, find testdir -name "*1")
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 .)
Shinichiro Hamaji68013972015-08-07 15:28:19 +090083 $(call run_find, cd testdir///dir1// && find .///)
Shinichiro Hamaji5f57a992015-06-30 19:39:39 +090084 $(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)
Shinichiro Hamaji68013972015-08-07 15:28:19 +090090 $(call run_find, test -d testdir//dir1/// && find testdir///dir1///)
91 $(call run_find, test -d testdir//.///dir1/// && find testdir//.///dir1///)
Shinichiro Hamaji5f57a992015-06-30 19:39:39 +090092 @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)
Shinichiro Hamajid45a09d2015-07-02 00:35:57 +0900103 @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)
Shinichiro Hamaji68013972015-08-07 15:28:19 +0900110 @echo findleaves
Shinichiro Hamajib7175612015-10-13 16:15:34 +0900111 $(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)
Shinichiro Hamajie7a68222015-08-06 17:07:29 +0900118 $(call run_find, build/tools/findleaves.py --mindepth=2 testdir file1)
Shinichiro Hamajic15a8242016-05-30 16:11:14 +0900119 $(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)
Shinichiro Hamaji3498f342015-08-11 14:23:12 +0900121 @echo missing chdir / testdir
122 $(call run_find, cd xxx && find .)
123 $(call run_find, if [ -d xxx ]; then find .; fi)
Shinichiro Hamajibd3bb232015-10-09 16:35:54 +0900124
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 .)
Shinichiro Hamajib7175612015-10-13 16:15:34 +0900129 $(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)