redo-whichdo: fix a bug where the last dir was checked twice, and add tests.
When we can't find a .do file, we walk all the way back to the root directory. When that happens, the root directory is actually searched twice. This is harmless (since a .do file doesn't exist there anyway) but causes redo-whichdo to produce the wrong output. Also, add a test, which I forgot to do when writing whichdo in the first place. To make the test work from the root directory, we need a way to initialize redo without actually creating a .redo directory. Add a init_no_state() function for that purpose, and split the necessary path functions into their own module so we can avoid importing builder.py.
This commit is contained in:
parent
f835becde4
commit
e40dc5bad2
10 changed files with 133 additions and 50 deletions
45
t/260-whichdo/nonexists.do
Normal file
45
t/260-whichdo/nonexists.do
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
exec >&2
|
||||
|
||||
# Testing the search path for non-existent do files is a little tricky.
|
||||
# We can't be sure where our current directory is, so we don't know how
|
||||
# far up the stack redo will need to search.
|
||||
#
|
||||
# To dodge the problem, let's "cd /" first so that we're testing a target
|
||||
# relative to a known location (the root directory).
|
||||
|
||||
if [ -e '/default.do' -o \
|
||||
-e '/default.z.do' -o \
|
||||
-e '/default.y.z.do' ]; then
|
||||
echo "Weird: /default.*.do exists; can't run this test."
|
||||
exit 99
|
||||
fi
|
||||
|
||||
# redo-whichdo *should* fail here, so don't abort the script for that.
|
||||
set +e
|
||||
a=$(cd / && redo-whichdo __nonexist/a/x.y.z)
|
||||
rv=$?
|
||||
set -e
|
||||
|
||||
if [ "$rv" -eq 0 ]; then
|
||||
echo "redo-whichdo should return nonzero for a missing .do file."
|
||||
exit 10
|
||||
fi
|
||||
|
||||
b=$(cat <<EOF
|
||||
__nonexist/a/x.y.z.do
|
||||
__nonexist/a/default.y.z.do
|
||||
__nonexist/a/default.z.do
|
||||
__nonexist/a/default.do
|
||||
__nonexist/default.y.z.do
|
||||
__nonexist/default.z.do
|
||||
__nonexist/default.do
|
||||
default.y.z.do
|
||||
default.z.do
|
||||
default.do
|
||||
EOF
|
||||
)
|
||||
|
||||
if [ "$a" != "$b" ]; then
|
||||
printf 'redo-whichdo mismatch.\n\ngot:\n%s\n\nexpected:\n%s\n' "$a" "$b"
|
||||
exit 11
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue