dev-create-test-filesystem.sh 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. #!/bin/bash
  2. # This script creates a bunch of awkward test case files. It gets
  3. # automatically run as part of Vagrant provisioning.
  4. trap 'exit' ERR
  5. if [[ ! -d "/vagrant" ]]; then
  6. echo "This script should be run in the Vagrant environment"
  7. exit 1
  8. fi
  9. source "/vagrant/devtools/dev-fixtures.sh"
  10. # Delete old testcases if they exist already, then create a
  11. # directory to house new ones.
  12. if [[ -d "$TEST_ROOT" ]]; then
  13. echo -e "\033[1m[ 0/13]\033[0m Deleting existing test cases directory"
  14. sudo rm -rf "$TEST_ROOT"
  15. fi
  16. sudo mkdir "$TEST_ROOT"
  17. sudo chmod 777 "$TEST_ROOT"
  18. sudo mkdir "$TEST_ROOT/empty"
  19. # Awkward file size testcases.
  20. # This needs sudo to set the files’ users at the very end.
  21. mkdir "$TEST_ROOT/files"
  22. echo -e "\033[1m[ 1/13]\033[0m Creating file size testcases"
  23. for i in {1..13}; do
  24. fallocate -l "$i" "$TEST_ROOT/files/$i"_bytes
  25. fallocate -l "$i"KiB "$TEST_ROOT/files/$i"_KiB
  26. fallocate -l "$i"MiB "$TEST_ROOT/files/$i"_MiB
  27. done
  28. touch -t $FIXED_DATE "$TEST_ROOT/files/"*
  29. chmod 644 "$TEST_ROOT/files/"*
  30. sudo chown $FIXED_USER:$FIXED_USER "$TEST_ROOT/files/"*
  31. # File name extension testcases.
  32. # These aren’t tested in details view, but we set timestamps on them to
  33. # test that various sort options work.
  34. mkdir "$TEST_ROOT/file-names-exts"
  35. echo -e "\033[1m[ 2/13]\033[0m Creating file name extension testcases"
  36. touch "$TEST_ROOT/file-names-exts/Makefile"
  37. touch "$TEST_ROOT/file-names-exts/IMAGE.PNG"
  38. touch "$TEST_ROOT/file-names-exts/image.svg"
  39. touch "$TEST_ROOT/file-names-exts/VIDEO.AVI"
  40. touch "$TEST_ROOT/file-names-exts/video.wmv"
  41. touch "$TEST_ROOT/file-names-exts/music.mp3"
  42. touch "$TEST_ROOT/file-names-exts/MUSIC.OGG"
  43. touch "$TEST_ROOT/file-names-exts/lossless.flac"
  44. touch "$TEST_ROOT/file-names-exts/lossless.wav"
  45. touch "$TEST_ROOT/file-names-exts/crypto.asc"
  46. touch "$TEST_ROOT/file-names-exts/crypto.signature"
  47. touch "$TEST_ROOT/file-names-exts/document.pdf"
  48. touch "$TEST_ROOT/file-names-exts/DOCUMENT.XLSX"
  49. touch "$TEST_ROOT/file-names-exts/COMPRESSED.ZIP"
  50. touch "$TEST_ROOT/file-names-exts/compressed.tar.gz"
  51. touch "$TEST_ROOT/file-names-exts/compressed.tgz"
  52. touch "$TEST_ROOT/file-names-exts/compressed.tar.xz"
  53. touch "$TEST_ROOT/file-names-exts/compressed.txz"
  54. touch "$TEST_ROOT/file-names-exts/compressed.deb"
  55. touch "$TEST_ROOT/file-names-exts/backup~"
  56. touch "$TEST_ROOT/file-names-exts/#SAVEFILE#"
  57. touch "$TEST_ROOT/file-names-exts/file.tmp"
  58. touch "$TEST_ROOT/file-names-exts/compiled.class"
  59. touch "$TEST_ROOT/file-names-exts/compiled.o"
  60. touch "$TEST_ROOT/file-names-exts/compiled.js"
  61. touch "$TEST_ROOT/file-names-exts/compiled.coffee"
  62. # File name testcases.
  63. # bash really doesn’t want you to create a file with escaped characters
  64. # in its name, so we have to resort to the echo builtin and touch!
  65. mkdir "$TEST_ROOT/file-names"
  66. echo -e "\033[1m[ 3/13]\033[0m Creating file names testcases"
  67. echo -ne "$TEST_ROOT/file-names/ascii: hello" | xargs -0 touch
  68. echo -ne "$TEST_ROOT/file-names/emoji: [🆒]" | xargs -0 touch
  69. echo -ne "$TEST_ROOT/file-names/utf-8: pâté" | xargs -0 touch
  70. echo -ne "$TEST_ROOT/file-names/bell: [\a]" | xargs -0 touch
  71. echo -ne "$TEST_ROOT/file-names/backspace: [\b]" | xargs -0 touch
  72. echo -ne "$TEST_ROOT/file-names/form-feed: [\f]" | xargs -0 touch
  73. echo -ne "$TEST_ROOT/file-names/new-line: [\n]" | xargs -0 touch
  74. echo -ne "$TEST_ROOT/file-names/return: [\r]" | xargs -0 touch
  75. echo -ne "$TEST_ROOT/file-names/tab: [\t]" | xargs -0 touch
  76. echo -ne "$TEST_ROOT/file-names/vertical-tab: [\v]" | xargs -0 touch
  77. echo -ne "$TEST_ROOT/file-names/escape: [\033]" | xargs -0 touch
  78. echo -ne "$TEST_ROOT/file-names/ansi: [\033[34mblue\033[0m]" | xargs -0 touch
  79. echo -ne "$TEST_ROOT/file-names/invalid-utf8-1: [\xFF]" | xargs -0 touch
  80. echo -ne "$TEST_ROOT/file-names/invalid-utf8-2: [\xc3\x28]" | xargs -0 touch
  81. echo -ne "$TEST_ROOT/file-names/invalid-utf8-3: [\xe2\x82\x28]" | xargs -0 touch
  82. echo -ne "$TEST_ROOT/file-names/invalid-utf8-4: [\xf0\x28\x8c\x28]" | xargs -0 touch
  83. echo -ne "$TEST_ROOT/file-names/new-line-dir: [\n]" | xargs -0 mkdir
  84. echo -ne "$TEST_ROOT/file-names/new-line-dir: [\n]/subfile" | xargs -0 touch
  85. echo -ne "$TEST_ROOT/file-names/new-line-dir: [\n]/another: [\n]" | xargs -0 touch
  86. echo -ne "$TEST_ROOT/file-names/new-line-dir: [\n]/broken" | xargs -0 touch
  87. mkdir "$TEST_ROOT/file-names/links"
  88. ln -s "$TEST_ROOT/file-names/new-line-dir"*/* "$TEST_ROOT/file-names/links"
  89. echo -ne "$TEST_ROOT/file-names/new-line-dir: [\n]/broken" | xargs -0 rm
  90. # Special file testcases.
  91. mkdir "$TEST_ROOT/specials"
  92. echo -e "\033[1m[ 4/13]\033[0m Creating special file kind testcases"
  93. sudo mknod "$TEST_ROOT/specials/block-device" b 3 60
  94. sudo mknod "$TEST_ROOT/specials/char-device" c 14 40
  95. sudo mknod "$TEST_ROOT/specials/named-pipe" p
  96. sudo touch -t $FIXED_DATE "$TEST_ROOT/specials/"*
  97. # Awkward symlink testcases.
  98. mkdir "$TEST_ROOT/links"
  99. echo -e "\033[1m[ 5/13]\033[0m Creating symlink testcases"
  100. ln -s / "$TEST_ROOT/links/root"
  101. ln -s /usr "$TEST_ROOT/links/usr"
  102. ln -s nowhere "$TEST_ROOT/links/broken"
  103. ln -s /proc/1/root "$TEST_ROOT/links/forbidden"
  104. touch "$TEST_ROOT/links/some_file"
  105. ln -s "$TEST_ROOT/links/some_file" "$TEST_ROOT/links/some_file_absolute"
  106. (cd "$TEST_ROOT/links"; ln -s "some_file" "some_file_relative")
  107. (cd "$TEST_ROOT/links"; ln -s "." "current_dir")
  108. (cd "$TEST_ROOT/links"; ln -s ".." "parent_dir")
  109. (cd "$TEST_ROOT/links"; ln -s "itself" "itself")
  110. # Awkward passwd testcases.
  111. # sudo is needed for these because we technically aren’t a member
  112. # of the groups (because they don’t exist), and chown and chgrp
  113. # are smart enough to disallow it!
  114. mkdir "$TEST_ROOT/passwd"
  115. echo -e "\033[1m[ 6/13]\033[0m Creating user and group testcases"
  116. touch -t $FIXED_DATE "$TEST_ROOT/passwd/unknown-uid"
  117. chmod 644 "$TEST_ROOT/passwd/unknown-uid"
  118. sudo chown $FIXED_BAD_UID:$FIXED_USER "$TEST_ROOT/passwd/unknown-uid"
  119. touch -t $FIXED_DATE "$TEST_ROOT/passwd/unknown-gid"
  120. chmod 644 "$TEST_ROOT/passwd/unknown-gid"
  121. sudo chown $FIXED_USER:$FIXED_BAD_GID "$TEST_ROOT/passwd/unknown-gid"
  122. # Awkward permission testcases.
  123. # Differences in the way ‘chmod’ handles setting ‘setuid’ and ‘setgid’
  124. # when you don’t already own the file mean that we need to use ‘sudo’
  125. # to change permissions to those.
  126. mkdir "$TEST_ROOT/permissions"
  127. echo -e "\033[1m[ 7/13]\033[0m Creating file permission testcases"
  128. mkdir "$TEST_ROOT/permissions/forbidden-directory"
  129. chmod 000 "$TEST_ROOT/permissions/forbidden-directory"
  130. touch -t $FIXED_DATE "$TEST_ROOT/permissions/forbidden-directory"
  131. sudo chown $FIXED_USER:$FIXED_USER "$TEST_ROOT/permissions/forbidden-directory"
  132. for perms in 000 001 002 004 010 020 040 100 200 400 644 755 777 1000 1001 2000 2010 4000 4100 7666 7777; do
  133. touch "$TEST_ROOT/permissions/$perms"
  134. sudo chown $FIXED_USER:$FIXED_USER "$TEST_ROOT/permissions/$perms"
  135. sudo chmod $perms "$TEST_ROOT/permissions/$perms"
  136. sudo touch -t $FIXED_DATE "$TEST_ROOT/permissions/$perms"
  137. done
  138. # Awkward date and time testcases.
  139. mkdir "$TEST_ROOT/dates"
  140. echo -e "\033[1m[ 8/13]\033[0m Creating date and time testcases"
  141. # created dates
  142. # there’s no way to touch the created date of a file...
  143. # so we have to do this the old-fashioned way!
  144. # (and make sure these don't actually get listed)
  145. touch -t $FIXED_OLD_DATE "$TEST_ROOT/dates/peach"; sleep 1
  146. touch -t $FIXED_MED_DATE "$TEST_ROOT/dates/plum"; sleep 1
  147. touch -t $FIXED_NEW_DATE "$TEST_ROOT/dates/pear"
  148. # modified dates
  149. touch -t $FIXED_OLD_DATE -m "$TEST_ROOT/dates/pear"
  150. touch -t $FIXED_MED_DATE -m "$TEST_ROOT/dates/peach"
  151. touch -t $FIXED_NEW_DATE -m "$TEST_ROOT/dates/plum"
  152. # accessed dates
  153. touch -t $FIXED_OLD_DATE -a "$TEST_ROOT/dates/plum"
  154. touch -t $FIXED_MED_DATE -a "$TEST_ROOT/dates/pear"
  155. touch -t $FIXED_NEW_DATE -a "$TEST_ROOT/dates/peach"
  156. sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/dates"
  157. mkdir "$TEST_ROOT/far-dates"
  158. touch -t $FIXED_PAST_DATE "$TEST_ROOT/far-dates/the-distant-past"
  159. touch -t $FIXED_FUTURE_DATE "$TEST_ROOT/far-dates/beyond-the-future"
  160. # Awkward extended attribute testcases.
  161. # We need to test combinations of various numbers of files *and*
  162. # extended attributes in directories. Turns out, the easiest way to
  163. # do this is to generate all combinations of files with “one-xattr”
  164. # or “two-xattrs” in their name and directories with “empty” or
  165. # “one-file” in their name, then just give the right number of
  166. # xattrs and children to those.
  167. mkdir "$TEST_ROOT/attributes"
  168. echo -e "\033[1m[ 9/13]\033[0m Creating extended attribute testcases"
  169. mkdir "$TEST_ROOT/attributes/files"
  170. touch "$TEST_ROOT/attributes/files/"{no-xattrs,one-xattr,two-xattrs}{,_forbidden}
  171. mkdir "$TEST_ROOT/attributes/dirs"
  172. mkdir "$TEST_ROOT/attributes/dirs/"{no-xattrs,one-xattr,two-xattrs}_{empty,one-file,two-files}{,_forbidden}
  173. setfattr -n user.greeting -v hello "$TEST_ROOT/attributes"/**/*{one-xattr,two-xattrs}*
  174. setfattr -n user.another_greeting -v hi "$TEST_ROOT/attributes"/**/*two-xattrs*
  175. for dir in "$TEST_ROOT/attributes/dirs/"*one-file*; do
  176. touch $dir/file-in-question
  177. done
  178. for dir in "$TEST_ROOT/attributes/dirs/"*two-files*; do
  179. touch $dir/this-file
  180. touch $dir/that-file
  181. done
  182. find "$TEST_ROOT/attributes" -exec touch {} -t $FIXED_DATE \;
  183. # I want to use the following to test,
  184. # but it only works on macos:
  185. #chmod +a "$FIXED_USER deny readextattr" "$TEST_ROOT/attributes"/**/*_forbidden
  186. sudo chmod 000 "$TEST_ROOT/attributes"/**/*_forbidden
  187. sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/attributes"
  188. # A sample Git repository
  189. # This uses cd because it's easier than telling Git where to go each time
  190. echo -e "\033[1m[10/13]\033[0m Creating Git testcases (1/3)"
  191. mkdir "$TEST_ROOT/git"
  192. cd "$TEST_ROOT/git"
  193. git init >/dev/null
  194. mkdir edits additions moves
  195. echo "original content" | tee edits/{staged,unstaged,both} >/dev/null
  196. echo "this file gets moved" > moves/hither
  197. git add edits moves
  198. git config --global user.email "exa@exa.exa"
  199. git config --global user.name "Exa Exa"
  200. git commit -m "Automated test commit" >/dev/null
  201. echo "modifications!" | tee edits/{staged,both} >/dev/null
  202. touch additions/{staged,edited}
  203. mv moves/{hither,thither}
  204. git add edits moves additions
  205. echo "more modifications!" | tee edits/unstaged edits/both additions/edited >/dev/null
  206. touch additions/unstaged
  207. find "$TEST_ROOT/git" -exec touch {} -t $FIXED_DATE \;
  208. sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/git"
  209. # A second Git repository
  210. # for testing two at once
  211. echo -e "\033[1m[11/13]\033[0m Creating Git testcases (2/3)"
  212. mkdir -p "$TEST_ROOT/git2/deeply/nested/directory"
  213. cd "$TEST_ROOT/git2"
  214. git init >/dev/null
  215. touch "deeply/nested/directory/upd8d"
  216. git add "deeply/nested/directory/upd8d"
  217. git commit -m "Automated test commit" >/dev/null
  218. echo "Now with contents" > "deeply/nested/directory/upd8d"
  219. touch "deeply/nested/directory/l8st"
  220. echo -e "target\n*.mp3" > ".gitignore"
  221. mkdir "ignoreds"
  222. touch "ignoreds/music.mp3"
  223. touch "ignoreds/music.m4a"
  224. mkdir "ignoreds/nested"
  225. touch "ignoreds/nested/70s grove.mp3"
  226. touch "ignoreds/nested/funky chicken.m4a"
  227. mkdir "target"
  228. touch "target/another ignored file"
  229. mkdir "deeply/nested/repository"
  230. cd "deeply/nested/repository"
  231. git init >/dev/null
  232. touch subfile
  233. # This file, ‘subfile’, should _not_ be marked as a new file by exa, because
  234. # it’s in the sub-repository but hasn’t been added to it. Were the sub-repo not
  235. # present, it would be marked as a new file, as the top-level repo knows about
  236. # the ‘deeply’ directory.
  237. find "$TEST_ROOT/git2" -exec touch {} -t $FIXED_DATE \;
  238. sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/git2"
  239. # A third Git repository
  240. # Regression test for https://github.com/ogham/exa/issues/526
  241. echo -e "\033[1m[12/13]\033[0m Creating Git testcases (3/3)"
  242. mkdir -p "$TEST_ROOT/git3"
  243. cd "$TEST_ROOT/git3"
  244. git init >/dev/null
  245. # Create a symbolic link pointing to a non-existing file
  246. ln -s aaa/aaa/a b
  247. # This normally fails with:
  248. find "$TEST_ROOT/git3" -exec touch {} -h -t $FIXED_DATE \;
  249. sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/git3"
  250. # Hidden and dot file testcases.
  251. # We need to set the permissions of `.` and `..` because they actually
  252. # get displayed in the output here, so this has to come last.
  253. echo -e "\033[1m[13/13]\033[0m Creating hidden and dot file testcases"
  254. shopt -u dotglob
  255. GLOBIGNORE=".:.."
  256. mkdir "$TEST_ROOT/hiddens"
  257. cd "$TEST_ROOT/hiddens"
  258. touch "$TEST_ROOT/hiddens/visible"
  259. touch "$TEST_ROOT/hiddens/.hidden"
  260. touch "$TEST_ROOT/hiddens/..extra-hidden"
  261. # ./hiddens/
  262. touch -t $FIXED_DATE "$TEST_ROOT/hiddens/"*
  263. chmod 644 "$TEST_ROOT/hiddens/"*
  264. sudo chown $FIXED_USER:$FIXED_USER "$TEST_ROOT/hiddens/"*
  265. # .
  266. touch -t $FIXED_DATE "$TEST_ROOT/hiddens"
  267. chmod 755 "$TEST_ROOT/hiddens"
  268. sudo chown $FIXED_USER:$FIXED_USER "$TEST_ROOT/hiddens"
  269. # ..
  270. sudo touch -t $FIXED_DATE "$TEST_ROOT"
  271. sudo chmod 755 "$TEST_ROOT"
  272. sudo chown $FIXED_USER:$FIXED_USER "$TEST_ROOT"