]> Cypherpunks.ru repositories - goredo.git/blob - t/redo-sh.tests/whichdo_relative_1/test
Import tests from apenwarr/redo and redo.sh
[goredo.git] / t / redo-sh.tests / whichdo_relative_1 / test
1 #!/bin/sh -eu
2 # When invoked with a relative path name as an argument, redo-whichdo
3 # must output non-existent dofiles in the same directory until it
4 # outputs one that exists.
5
6 dofiles="default.do default.c.do default.b.c.do a.b.c.do"
7
8 for dofile in ${dofiles}; do
9  if test -e "${dofile}"; then
10   rm -- "${dofile}"
11  fi
12 done
13
14 for dofile in ${dofiles}; do
15  >"${dofile}" cat <<EOF
16 printf '${dofile}\n'
17 EOF
18
19  whichdo_dofiles=$(
20   redo-whichdo a.b.c \
21    |tr '\0' '\n'
22  )
23
24  whichdo_dofiles_nonexistent=$(
25   printf '%s\n' "${whichdo_dofiles}" \
26    |sed '$d'  # BusyBox v.1.19.3 has no “head -n-1”
27  )
28  for whichdo_dofile_nonexistent in ${whichdo_dofiles_nonexistent}; do
29   if test -e "${whichdo_dofile_nonexistent}"; then
30    >&2 printf 'redo-whichdo prints %s as nonexistent dofile, but it exists.\n' \
31     "${whichdo_dofile_nonexistent}"
32    exit 1
33   fi
34  done
35
36  whichdo_dofile_existent=$(
37   printf '%s\n' "${whichdo_dofiles}" \
38    |tail -n1
39  )
40  if ! test -e "${whichdo_dofile_existent}"; then
41   >&2 printf 'redo-whichdo prints %s as existent dofile, but it does not exist.\n' \
42    "${whichdo_dofile_existent}"
43   exit 1
44  fi
45
46 done