apenwarr-redo/t/370-logs/all.do
Avery Pennarun 4edb6f78e0 redo-log: add automated tests, and fix some path bugs revealed by them.
When a log for X was saying it wanted to refer to Y, we used a relative
path, but it was sometimes relative to the wrong starting location, so
redo-log couldn't find it later.

Two examples:

 - if default.o.do is handling builds for a/b/x.o, and default.o.do
   does 'redo a/b/x.h', the log for x.o should refer to ./x.h, not
   a/b/x.h.

 - if foo.do is handling builds for foo, and it does
   "cd a/b && redo x", the log for foo should refer to a/b/x, not just
   x.
2018-11-19 18:58:36 -05:00

52 lines
1.6 KiB
Text

exec >&2
rm -f x pid
pid=$$
echo "$pid" >pid
xout=$(redo x)
[ "$(printf "$xout" | wc -l)" -eq 0 ] || exit 2
if [ -n "$REDO_LOG" ]; then
# redo has redo-log support enabled, so check that it saves logs.
# recursive log dump should show both x and y stderr.
redo-log -ru x | grep -q "^$pid x stderr" || exit 10
redo-log -ru x | grep -q "^$pid y stderr" || exit 11
# stdout captured by redo into the files x and y, *not* to log
redo-log -ru x | grep -q "^$pid x stdout" && exit 20
redo-log -ru x | grep -q "^$pid y stdout" && exit 21
[ "$(cat x)" = "$pid x stdout" ] || exit 22
[ "$(cat y)" = "$pid y stdout" ] || exit 23
# non-recursive log dump of x should *not* include y
redo-log x | grep -q "^$pid y stdout" && exit 30
redo-log x | grep -q "^$pid y stderr" && exit 31
redo a/b/xlog
(cd a && redo b/xlog)
# Test retrieval from a different $PWD.
(
cd a/b || exit 40
redo-log -ru ../../x | grep -q "^$pid x stderr" || exit 41
redo-log -ru ../../x | grep -q "^$pid y stderr" || exit 42
) || exit
fi
# whether or not redo-log is available, redirecting stderr should work.
pid=$$-bork
rm -f x pid
echo "$pid" >pid
out=$(redo x 2>&1)
# x's stderr should obviously go where we sent it
echo "$out" | grep -q "^$pid x stderr" || exit 50
# This one is actually tricky: with redo-log, x's call to 'redo y' would
# normally implicitly redirect y's stderr to a new log. redo needs to
# detect that we've already redirected it where we want, and not take it
# away.
echo "$out" | grep -q "^$pid y stderr" || exit 51
exit 0