test-lib: redirect stdin of tests

We want to run tests in a predictable, sterile environment
so we can get repeatable results.  They should take as
little input as possible from the environment outside the
test script. We already sanitize environment variables, but
leave stdin untouched. This means that scripts can
accidentally be impacted by content on stdin, or whether
stdin isatty().

Furthermore, scripts reading from stdin can be annoying to
outer loops which care about their stdin offset, like:

  while read sha1; do
      make test
  done

A test which accidentally reads stdin would soak up all of
the rest of the input intended for the outer shell loop.

Let's redirect stdin from /dev/null, which solves both
of these problems. It won't detect tests accidentally
reading from stdin, but since doing so now gives a
deterministic result, we don't need to consider that an
error.

We'll also leave file descriptor 6 as a link to the original
stdin. Tests shouldn't need to look at this, but it can be
convenient for inserting interactive commands while
debugging tests (e.g., you could insert "bash <&6 >&3 2>&4"
to run interactive commands in the environment of the test
script).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 file changed
tree: 5873470b30878d48656d8a0d5e96f3cef0651069
  1. block-sha1/
  2. builtin/
  3. compat/
  4. contrib/
  5. Documentation/
  6. git-gui/
  7. git_remote_helpers/
  8. gitk-git/
  9. gitweb/
  10. mergetools/
  11. perl/
  12. po/
  13. ppc/
  14. t/
  15. templates/
  16. vcs-svn/
  17. xdiff/
  18. .gitattributes
  19. .gitignore
  20. .mailmap
  21. abspath.c
  22. aclocal.m4
  23. advice.c
  24. advice.h
  25. alias.c
  26. alloc.c
  27. archive-tar.c
  28. archive-zip.c
  29. archive.c
  30. archive.h
  31. attr.c
  32. attr.h
  33. base85.c
  34. bisect.c
  35. bisect.h
  36. blob.c
  37. blob.h
  38. branch.c
  39. branch.h
  40. builtin.h
  41. bundle.c
  42. bundle.h
  43. cache-tree.c
  44. cache-tree.h
  45. cache.h
  46. check-builtins.sh
  47. check-racy.c
  48. check_bindir
  49. color.c
  50. color.h
  51. combine-diff.c
  52. command-list.txt
  53. commit.c
  54. commit.h
  55. config.c
  56. config.mak.in
  57. configure.ac
  58. connect.c
  59. convert.c
  60. convert.h
  61. copy.c
  62. COPYING
  63. csum-file.c
  64. csum-file.h
  65. ctype.c
  66. daemon.c
  67. date.c
  68. decorate.c
  69. decorate.h
  70. delta.h
  71. diff-delta.c
  72. diff-lib.c
  73. diff-no-index.c
  74. diff.c
  75. diff.h
  76. diffcore-break.c
  77. diffcore-delta.c
  78. diffcore-order.c
  79. diffcore-pickaxe.c
  80. diffcore-rename.c
  81. diffcore.h
  82. dir.c
  83. dir.h
  84. editor.c
  85. entry.c
  86. environment.c
  87. exec_cmd.c
  88. exec_cmd.h
  89. fast-import.c
  90. fetch-pack.h
  91. fixup-builtins
  92. fsck.c
  93. fsck.h
  94. generate-cmdlist.sh
  95. gettext.c
  96. gettext.h
  97. git-add--interactive.perl
  98. git-am.sh
  99. git-archimport.perl
  100. git-bisect.sh
  101. git-compat-util.h
  102. git-cvsexportcommit.perl
  103. git-cvsimport.perl
  104. git-cvsserver.perl
  105. git-difftool--helper.sh
  106. git-difftool.perl
  107. git-filter-branch.sh
  108. git-instaweb.sh
  109. git-lost-found.sh
  110. git-merge-octopus.sh
  111. git-merge-one-file.sh
  112. git-merge-resolve.sh
  113. git-mergetool--lib.sh
  114. git-mergetool.sh
  115. git-parse-remote.sh
  116. git-pull.sh
  117. git-quiltimport.sh
  118. git-rebase--am.sh
  119. git-rebase--interactive.sh
  120. git-rebase--merge.sh
  121. git-rebase.sh
  122. git-relink.perl
  123. git-remote-testgit.py
  124. git-repack.sh
  125. git-request-pull.sh
  126. git-send-email.perl
  127. git-sh-i18n.sh
  128. git-sh-setup.sh
  129. git-stash.sh
  130. git-submodule.sh
  131. git-svn.perl
  132. GIT-VERSION-GEN
  133. git-web--browse.sh
  134. git.c
  135. git.spec.in
  136. graph.c
  137. graph.h
  138. grep.c
  139. grep.h
  140. hash.c
  141. hash.h
  142. help.c
  143. help.h
  144. hex.c
  145. http-backend.c
  146. http-fetch.c
  147. http-push.c
  148. http-walker.c
  149. http.c
  150. http.h
  151. ident.c
  152. imap-send.c
  153. INSTALL
  154. kwset.c
  155. kwset.h
  156. levenshtein.c
  157. levenshtein.h
  158. LGPL-2.1
  159. list-objects.c
  160. list-objects.h
  161. ll-merge.c
  162. ll-merge.h
  163. lockfile.c
  164. log-tree.c
  165. log-tree.h
  166. mailmap.c
  167. mailmap.h
  168. Makefile
  169. match-trees.c
  170. merge-file.c
  171. merge-file.h
  172. merge-recursive.c
  173. merge-recursive.h
  174. name-hash.c
  175. notes-cache.c
  176. notes-cache.h
  177. notes-merge.c
  178. notes-merge.h
  179. notes.c
  180. notes.h
  181. object.c
  182. object.h
  183. pack-check.c
  184. pack-refs.c
  185. pack-refs.h
  186. pack-revindex.c
  187. pack-revindex.h
  188. pack-write.c
  189. pack.h
  190. pager.c
  191. parse-options-cb.c
  192. parse-options.c
  193. parse-options.h
  194. patch-delta.c
  195. patch-ids.c
  196. patch-ids.h
  197. path.c
  198. pkt-line.c
  199. pkt-line.h
  200. preload-index.c
  201. pretty.c
  202. progress.c
  203. progress.h
  204. quote.c
  205. quote.h
  206. reachable.c
  207. reachable.h
  208. read-cache.c
  209. README
  210. reflog-walk.c
  211. reflog-walk.h
  212. refs.c
  213. refs.h
  214. remote-curl.c
  215. remote.c
  216. remote.h
  217. replace_object.c
  218. rerere.c
  219. rerere.h
  220. resolve-undo.c
  221. resolve-undo.h
  222. revision.c
  223. revision.h
  224. run-command.c
  225. run-command.h
  226. send-pack.h
  227. server-info.c
  228. setup.c
  229. sh-i18n--envsubst.c
  230. sha1-array.c
  231. sha1-array.h
  232. sha1-lookup.c
  233. sha1-lookup.h
  234. sha1_file.c
  235. sha1_name.c
  236. shallow.c
  237. shell.c
  238. shortlog.h
  239. show-index.c
  240. sideband.c
  241. sideband.h
  242. sigchain.c
  243. sigchain.h
  244. strbuf.c
  245. strbuf.h
  246. streaming.c
  247. streaming.h
  248. string-list.c
  249. string-list.h
  250. submodule.c
  251. submodule.h
  252. symlinks.c
  253. tag.c
  254. tag.h
  255. tar.h
  256. test-chmtime.c
  257. test-ctype.c
  258. test-date.c
  259. test-delta.c
  260. test-dump-cache-tree.c
  261. test-genrandom.c
  262. test-index-version.c
  263. test-line-buffer.c
  264. test-match-trees.c
  265. test-mktemp.c
  266. test-obj-pool.c
  267. test-parse-options.c
  268. test-path-utils.c
  269. test-run-command.c
  270. test-sha1.c
  271. test-sha1.sh
  272. test-sigchain.c
  273. test-string-pool.c
  274. test-subprocess.c
  275. test-svn-fe.c
  276. test-treap.c
  277. thread-utils.c
  278. thread-utils.h
  279. trace.c
  280. transport-helper.c
  281. transport.c
  282. transport.h
  283. tree-diff.c
  284. tree-walk.c
  285. tree-walk.h
  286. tree.c
  287. tree.h
  288. unimplemented.sh
  289. unpack-trees.c
  290. unpack-trees.h
  291. upload-pack.c
  292. url.c
  293. url.h
  294. usage.c
  295. userdiff.c
  296. userdiff.h
  297. utf8.c
  298. utf8.h
  299. walker.c
  300. walker.h
  301. wrap-for-bin.sh
  302. wrapper.c
  303. write_or_die.c
  304. ws.c
  305. wt-status.c
  306. wt-status.h
  307. xdiff-interface.c
  308. xdiff-interface.h
  309. zlib.c