dev-create-test-filesystem.sh 13 KB

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