dev-create-test-filesystem.sh 13 KB

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