dev-create-test-filesystem.sh 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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 $OLD_DATE "$TEST_ROOT/dates/peach"; sleep 1
  146. touch -t $MED_DATE "$TEST_ROOT/dates/plum"; sleep 1
  147. touch -t $NEW_DATE "$TEST_ROOT/dates/pear"
  148. # modified dates
  149. touch -t $OLD_DATE -m "$TEST_ROOT/dates/pear"
  150. touch -t $MED_DATE -m "$TEST_ROOT/dates/peach"
  151. touch -t $NEW_DATE -m "$TEST_ROOT/dates/plum"
  152. # accessed dates
  153. touch -t $OLD_DATE -a "$TEST_ROOT/dates/plum"
  154. touch -t $MED_DATE -a "$TEST_ROOT/dates/pear"
  155. touch -t $NEW_DATE -a "$TEST_ROOT/dates/peach"
  156. sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/dates"
  157. # Awkward extended attribute testcases.
  158. # We need to test combinations of various numbers of files *and*
  159. # extended attributes in directories. Turns out, the easiest way to
  160. # do this is to generate all combinations of files with “one-xattr”
  161. # or “two-xattrs” in their name and directories with “empty” or
  162. # “one-file” in their name, then just give the right number of
  163. # xattrs and children to those.
  164. mkdir "$TEST_ROOT/attributes"
  165. echo -e "\033[1m[ 9/13]\033[0m Creating extended attribute testcases"
  166. mkdir "$TEST_ROOT/attributes/files"
  167. touch "$TEST_ROOT/attributes/files/"{no-xattrs,one-xattr,two-xattrs}{,_forbidden}
  168. mkdir "$TEST_ROOT/attributes/dirs"
  169. mkdir "$TEST_ROOT/attributes/dirs/"{no-xattrs,one-xattr,two-xattrs}_{empty,one-file,two-files}{,_forbidden}
  170. setfattr -n user.greeting -v hello "$TEST_ROOT/attributes"/**/*{one-xattr,two-xattrs}*
  171. setfattr -n user.another_greeting -v hi "$TEST_ROOT/attributes"/**/*two-xattrs*
  172. for dir in "$TEST_ROOT/attributes/dirs/"*one-file*; do
  173. touch $dir/file-in-question
  174. done
  175. for dir in "$TEST_ROOT/attributes/dirs/"*two-files*; do
  176. touch $dir/this-file
  177. touch $dir/that-file
  178. done
  179. find "$TEST_ROOT/attributes" -exec touch {} -t $FIXED_DATE \;
  180. # I want to use the following to test,
  181. # but it only works on macos:
  182. #chmod +a "$FIXED_USER deny readextattr" "$TEST_ROOT/attributes"/**/*_forbidden
  183. sudo chmod 000 "$TEST_ROOT/attributes"/**/*_forbidden
  184. sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/attributes"
  185. # A sample Git repository
  186. # This uses cd because it's easier than telling Git where to go each time
  187. echo -e "\033[1m[10/13]\033[0m Creating Git testcases (1/3)"
  188. mkdir "$TEST_ROOT/git"
  189. cd "$TEST_ROOT/git"
  190. git init >/dev/null
  191. mkdir edits additions moves
  192. echo "original content" | tee edits/{staged,unstaged,both} >/dev/null
  193. echo "this file gets moved" > moves/hither
  194. git add edits moves
  195. git config --global user.email "exa@exa.exa"
  196. git config --global user.name "Exa Exa"
  197. git commit -m "Automated test commit" >/dev/null
  198. echo "modifications!" | tee edits/{staged,both} >/dev/null
  199. touch additions/{staged,edited}
  200. mv moves/{hither,thither}
  201. git add edits moves additions
  202. echo "more modifications!" | tee edits/unstaged edits/both additions/edited >/dev/null
  203. touch additions/unstaged
  204. find "$TEST_ROOT/git" -exec touch {} -t $FIXED_DATE \;
  205. sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/git"
  206. # A second Git repository
  207. # for testing two at once
  208. echo -e "\033[1m[11/13]\033[0m Creating Git testcases (2/3)"
  209. mkdir -p "$TEST_ROOT/git2/deeply/nested/directory"
  210. cd "$TEST_ROOT/git2"
  211. git init >/dev/null
  212. touch "deeply/nested/directory/upd8d"
  213. git add "deeply/nested/directory/upd8d"
  214. git commit -m "Automated test commit" >/dev/null
  215. echo "Now with contents" > "deeply/nested/directory/upd8d"
  216. touch "deeply/nested/directory/l8st"
  217. echo -e "target\n*.mp3" > ".gitignore"
  218. mkdir "ignoreds"
  219. touch "ignoreds/music.mp3"
  220. touch "ignoreds/music.m4a"
  221. mkdir "ignoreds/nested"
  222. touch "ignoreds/nested/70s grove.mp3"
  223. touch "ignoreds/nested/funky chicken.m4a"
  224. mkdir "target"
  225. touch "target/another ignored file"
  226. mkdir "deeply/nested/repository"
  227. cd "deeply/nested/repository"
  228. git init >/dev/null
  229. touch subfile
  230. # This file, ‘subfile’, should _not_ be marked as a new file by exa, because
  231. # it’s in the sub-repository but hasn’t been added to it. Were the sub-repo not
  232. # present, it would be marked as a new file, as the top-level repo knows about
  233. # the ‘deeply’ directory.
  234. find "$TEST_ROOT/git2" -exec touch {} -t $FIXED_DATE \;
  235. sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/git2"
  236. # A third Git repository
  237. # Regression test for https://github.com/ogham/exa/issues/526
  238. echo -e "\033[1m[12/13]\033[0m Creating Git testcases (3/3)"
  239. mkdir -p "$TEST_ROOT/git3"
  240. cd "$TEST_ROOT/git3"
  241. git init >/dev/null
  242. # Create a symbolic link pointing to a non-existing file
  243. ln -s aaa/aaa/a b
  244. # This normally fails with:
  245. find "$TEST_ROOT/git3" -exec touch {} -h -t $FIXED_DATE \;
  246. sudo chown $FIXED_USER:$FIXED_USER -R "$TEST_ROOT/git3"
  247. # Hidden and dot file testcases.
  248. # We need to set the permissions of `.` and `..` because they actually
  249. # get displayed in the output here, so this has to come last.
  250. echo -e "\033[1m[13/13]\033[0m Creating hidden and dot file testcases"
  251. shopt -u dotglob
  252. GLOBIGNORE=".:.."
  253. mkdir "$TEST_ROOT/hiddens"
  254. cd "$TEST_ROOT/hiddens"
  255. touch "$TEST_ROOT/hiddens/visible"
  256. touch "$TEST_ROOT/hiddens/.hidden"
  257. touch "$TEST_ROOT/hiddens/..extra-hidden"
  258. # ./hiddens/
  259. touch -t $FIXED_DATE "$TEST_ROOT/hiddens/"*
  260. chmod 644 "$TEST_ROOT/hiddens/"*
  261. sudo chown $FIXED_USER:$FIXED_USER "$TEST_ROOT/hiddens/"*
  262. # .
  263. touch -t $FIXED_DATE "$TEST_ROOT/hiddens"
  264. chmod 755 "$TEST_ROOT/hiddens"
  265. sudo chown $FIXED_USER:$FIXED_USER "$TEST_ROOT/hiddens"
  266. # ..
  267. sudo touch -t $FIXED_DATE "$TEST_ROOT"
  268. sudo chmod 755 "$TEST_ROOT"
  269. sudo chown $FIXED_USER:$FIXED_USER "$TEST_ROOT"