#!/bin/sh -eu
# When invoked, redo-ood must output targets for which a dependency
# changed and targets for which a dependency of a dependency changed
# and targets for which a dependency of a dependency of a dependency
# changed.

>all.do printf 'redo-ifchange a
'

>a.do cat <<EOF
redo-ifchange b
printf '0
'
EOF

>b.do cat <<EOF
redo-ifchange c
printf '1
'
EOF

>c.do cat <<EOF
redo-ifchange d
printf '2
'
EOF

>d printf '3
'

redo
<a read -r a1
<b read -r b1
<c read -r c1
<d read -r d1

ood1=$(redo-ood)

>d printf '4\n'
<d read -r d2

ood2=$(redo-ood | sed /^all$/d)

test 0 -eq "${a1}"
test 1 -eq "${b1}"
test 2 -eq "${c1}"
test 3 -eq "${d1}"
test 4 -eq "${d2}"

[ "${ood1}" = "all" ]
test -n "${ood2}"

. ../stat_inode.rc

inode_a=$(stat_inode a)
inode_b=$(stat_inode b)
inode_c=$(stat_inode c)
inodes_ood=$(stat_inode ${ood2})

case "${inodes_ood}" in
 *"${inode_a}"*)
 ;;
 *)
  exit 1
 ;;
esac

case "${inodes_ood}" in
 *"${inode_b}"*)
 ;;
 *)
  exit 1
 ;;
esac

case "${inodes_ood}" in
 *"${inode_c}"*)
 ;;
 *)
  exit 1
 ;;
esac
