More fixes for converting missing targets -> sources.

I attempted to fix this in commit c06d1fba40, but it was apparently
incomplete and not all cases were covered by tests.

Let's add a much more thorough test by going through every possible
combination and making sure redo-{sources,targets,ood} all work as
expected, that the "you modified it" warning does or does not show up
when expected, and that dependencies are rebuilt the number of times we
expect.
This commit is contained in:
Avery Pennarun 2018-12-02 16:53:05 -05:00
commit 2b0d34f0ed
12 changed files with 282 additions and 66 deletions

View file

@ -1,6 +1,7 @@
bork
bork.do
bork.log
sub
sub.log
targets.out
sub.warn
silent.out
want

View file

@ -1,55 +1,211 @@
exec >&2
rm -f bork.do bork bork.log sub sub.log targets.out
rm -f want silent.out bork bork.log sub sub.log sub.warn
# Run a command without displaying its output.
# We are intentionally generating some redo errors, and
# we don't want the log to look scary.
# In case we need the output to debug a failed test,
# we leave the most recent command output in silent.out.
silent() {
"$@" >silent.out 2>&1
}
# like "grep -q", but portable.
qgrep() {
# like "grep -q", but portable
grep "$@" >/dev/null
}
cp bork.do.in bork.do
redo bork
[ "$(cat bork.log)" = "x" ] || exit 2
redo bork
[ "$(cat bork.log)" = "xx" ] || exit 3
# Returns true if bork is marked as a redo-source.
is_source() {
redo-sources | qgrep '^bork$'
}
redo-ifchange sub
[ "$(cat bork.log)" = "xx" ] || exit 10
[ "$(cat sub.log)" = "y" ] || exit 11
. ../skip-if-minimal-do.sh
redo-sources | qgrep '^bork$' && exit 12
redo-targets | tee targets.out | qgrep '^bork$' || exit 13
# Returns true if bork is marked as a redo-target.
is_target() {
redo-targets | qgrep '^bork$'
}
# Might as well test redo-ood while we're here
../flush-cache
redo bork
redo-targets | qgrep '^bork$' || exit 15
redo-targets | qgrep '^sub$' || exit 16
redo-ood | qgrep '^sub$' || exit 17
# Returns true if bork is marked as an out-of-date redo-target.
is_ood() {
redo-ood | qgrep '^bork$'
}
redo-ifchange sub
[ "$(cat bork.log)" = "xxx" ] || exit 18
[ "$(cat sub.log)" = "yy" ] || exit 19
rm -f bork
../flush-cache
redo-ifchange sub # rebuilds, and sub.do drops dependency on bork
[ "$(cat bork.log)" = "xxx" ] || exit 20
[ "$(cat sub.log)" = "yyy" ] || exit 21
redo-sources | qgrep '^bork$' && exit 22 # nonexistent, so not a source
redo-targets | qgrep '^bork$' && exit 23 # deleted; not a target anymore
# The table for our table-driven test.
# Column meanings are:
# pre: the state of the 'bork' file at test start
# src = 'bork' is a redo-source
# nil = 'bork' is a redo-target that produced nil (ie. a virtual target)
# add = 'bork' is a redo-target that produced a file
# update: the override to perform after 'pre'
# nop = do nothing
# del = delete 'bork', if it exists
# add = create/override a new 'bork'
# post: the behaviour requested from bork.do after 'pre' and 'update' finish
# err = bork.do exits with an error
# nil = bork.do produces nil (ie. a virtual target)
# add = bork.do produces a file
# subran: 'ran' if sub.do is expected to pass, else 'skip'
# ran: 'ran' if bork.do is expected to run at all, else 'skip'
# warn: 'warn' if 'redo bork' is expected to warn about overrides, else 'no'
# src/targ/ood: 1 if bork should show up in source/target/ood output, else 0
truth="
# File was initially a source file
src nop err skip skip no 1 0 0
src nop nil skip skip no 1 0 0
src nop add skip skip no 1 0 0
echo static >bork
../flush-cache
redo-ifchange sub # doesn't depend on bork anymore, so doesn't rebuild
[ "$(cat bork.log)" = "xxx" ] || exit 30
[ "$(cat sub.log)" = "yyy" ] || exit 31
src del err skip ran no 0 0 0 # content deleted
src del nil ran ran no 0 1 0
src del add ran ran no 0 1 0
# bork should now be considered static, so no warning or need to rebuild.
# It should now be considered a source, not a target.
redo sub # force rebuild; sub.do now declares dependency on bork
[ "$(cat bork.log)" = "xxx" ] || exit 40
[ "$(cat sub.log)" = "yyyy" ] || exit 41
redo-sources | qgrep '^bork$' || exit 42
redo-targets | qgrep '^bork$' && exit 43
src add err skip skip no 1 0 0 # source updated
src add nil skip skip no 1 0 0
src add add skip skip no 1 0 0
# File was initially a target that produced nil
nil nop err skip ran no 0 0 0 # content forgotten
nil nop nil ran ran no 0 1 0
nil nop add ran ran no 0 1 0
nil del err skip ran no 0 0 0 # content nonexistent
nil del nil ran ran no 0 1 0
nil del add ran ran no 0 1 0
nil add err skip skip warn 1 0 0 # content overridden
nil add nil skip skip warn 1 0 0
nil add add skip skip warn 1 0 0
# File was initially a target that produced output
add nop err skip ran no 0 1 1 # update failed
add nop nil ran ran no 0 1 0
add nop add ran ran no 0 1 0
add del err skip ran no 0 0 0 # content nonexistent
add del nil ran ran no 0 1 0
add del add ran ran no 0 1 0
add add err skip skip warn 1 0 0 # content overridden
add add nil skip skip warn 1 0 0
add add add skip skip warn 1 0 0
"
echo "$truth" |
while read pre update post subran ran warn src targ ood XX; do
[ "$pre" != "" -a "$pre" != "#" ] || continue
# add some helpful vertical whitespace between rows when
# using 'redo -x'
:
:
:
:
echo "test: $pre $update $post"
rm -f bork
# Step 1 does the requested 'pre' operation.
: STEP 1
../flush-cache
case $pre in
src)
# This is a little convoluted because we need to convince
# redo to forget 'bork' may have previously been known as a
# target. To make it work, we have to let redo see the file
# at least once as "should be existing, but doesn't." That
# will mark is as no longer a target. Then we can create the
# file from outside redo.
rm -f bork
echo err >want
# Now redo will ack the nonexistent file, but *not* create
# it, because bork.do will exit with an error.
silent redo-ifchange bork || true
# Make sure redo is really sure the file is not a target
! is_target || exit 13
# Manually create the source file and ensure redo knows it's
# a source, and hasn't magically turned back into a target.
echo src >>bork
is_source || exit 11
! is_target || exit 12
;;
nil)
echo nil >want
redo bork
! is_source || exit 11
is_target || exit 12
;;
add)
echo add >want
redo bork
! is_source || exit 11
is_target || exit 12
;;
*) exit 90 ;;
esac
# Step 2 does the requested 'update' operation.
: STEP 2
skip=
case $update in
nop) ;;
del) rm -f bork; skip=1 ;;
add) echo override >>bork ;;
*) exit 91 ;;
esac
../flush-cache
if [ -z "$skip" ]; then
silent redo sub
fi
# Step 3 does the requested 'post' operation.
: STEP 3
../flush-cache
: >bork.log
: >sub.log
echo "$post" >want
redo-ifchange sub >sub.warn 2>&1 || true
read blog <bork.log || true
case $ran in
skip) want_blog='' ;;
ran) want_blog='x' ;;
esac
[ "$blog" = "$want_blog" ] || exit 21
read slog <sub.log || true
case $subran in
skip) want_slog='' ;;
ran) want_slog='y' ;;
esac
[ "$slog" = "$want_slog" ] || exit 22
if [ "$src" = 1 ]; then
is_source || exit 31
else
! is_source || exit 32
fi
if [ "$targ" = 1 ]; then
is_target || exit 33
else
! is_target || exit 34
fi
if [ "$ood" = 1 ]; then
is_ood || exit 35
else
! is_ood || exit 36
fi
# FIXME: I'd like to not depend on the specific wording of warning
# messages here. However, the whole point of the warning message
# is that it doesn't affect behaviour (or else it would be an error,
# not a warning).
if [ "$warn" = "warn" ]; then
qgrep "you modified it" sub.warn || exit 51
else
! qgrep "you modified it" sub.warn || exit 52
fi
done
exit 0

11
t/351-deps-forget/bork.do Normal file
View file

@ -0,0 +1,11 @@
printf x >>$1.log
redo-always
read want <want
case $want in
err) exit 10 ;;
nil) exit 0 ;;
add) printf x >>$3; exit 0 ;;
*) exit 80 ;;
esac

View file

@ -1,2 +0,0 @@
echo bork
printf x >>$1.log

View file

@ -1,2 +1 @@
rm -f *~ .*~ bork bork.do bork.log sub sub.log targets.out
rm -f *~ .*~ want bork bork.log sub sub.log sub.warn silent.out

View file

@ -1,3 +1,4 @@
[ -e bork ] && redo-ifchange bork
redo-ifchange bork
echo sub
echo sub >&2
printf y >>$1.log