diff --git a/minimal/do b/minimal/do index 3f20bc2..b64734e 100755 --- a/minimal/do +++ b/minimal/do @@ -33,6 +33,7 @@ dirname() _dirsplit "$0" export REDO=$(cd "${dir:-.}" && echo "$PWD/$base") +if [ "$base" = "redo-ifchange" ]; then ifchange=1; else ifchange=; fi DO_TOP= if [ -z "$DO_BUILT" ]; then @@ -107,7 +108,7 @@ _run_dofile() _do() { local dir="$1" target="$2" tmp="$3" - if [ ! -e "$target" ] || [ -d "$target" -a ! -e "$target.did" ]; then + if [ -z "$ifchange" ] || ( [ ! -e "$target" -o -d "$target" ] && [ ! -e "$target.did" ] ); then printf '%sdo %s%s%s%s\n' \ "$green" "$DO_DEPTH" "$bold" "$dir$target" "$plain" >&2 echo "$PWD/$target" >>"$DO_BUILT" diff --git a/t/102-empty/clean.do b/t/102-empty/clean.do index d8246d9..799f5f4 100644 --- a/t/102-empty/clean.do +++ b/t/102-empty/clean.do @@ -1 +1 @@ -rm -f touch1 *~ .*~ +rm -f touch1 touch1-ran *~ .*~ diff --git a/t/102-empty/touchtest.do b/t/102-empty/touchtest.do index 2b60d8f..2f3d5ca 100644 --- a/t/102-empty/touchtest.do +++ b/t/102-empty/touchtest.do @@ -2,12 +2,40 @@ # between "real" redo and minimal/do, so clean it up. rm -f touch1 +# simply create touch1 echo 'echo hello' >touch1.do redo touch1 [ -e touch1 ] || exit 55 +[ "$(cat touch1)" = "hello" ] || exit 56 + +# ensure that 'redo touch1' always re-runs touch1.do even if we have +# already built touch1 in this session, and even if touch1 already exists. +echo 'echo hello2' >touch1.do +redo touch1 +[ "$(cat touch1)" = "hello2" ] || exit 57 + +# ensure that touch1 is rebuilt even if it got deleted after the last redo +# inside the same session. Also ensure that we can produce a zero-byte +# output file explicitly. rm -f touch1 echo 'touch $3' >touch1.do redo touch1 [ -e touch1 ] || exit 66 -[ -z "$(cat touch1)" ] || exit 77 +[ -z "$(cat touch1)" ] || exit 67 + +# Also test that zero bytes of output does not create the file at all, as +# opposed to creating a zero-byte file. +rm -f touch1 +echo 'touch touch1-ran' >touch1.do +redo touch1 +[ -e touch1 ] && exit 75 +[ -e touch1-ran ] || exit 76 +rm -f touch1-ran + +# Make sure that redo-ifchange *won't* rebuild touch1 if we have already +# built it, even if building it did not produce an output file. +redo-ifchange touch1 +[ -e touch1 ] && exit 77 +[ -e touch1-ran ] && exit 78 + rm -f touch1.do