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