Exheredludis/paludis/util/process_TEST_setup.sh
Saleem Abdulrasool b20013e387 test: fix tests with bash 4.3
bash 4.3 changes the semantics of the read builtin.  It will now silently ignore
NUL characters in the input stream.  This is problematic since the paludis pipe
command protocol uses the NUL character as an indicator for end of message.
Passing read an explicit delimiter of a NUL char ($'\0') ensures that it treats
the NUL character as valid input.  This avoids the hang during the process
tests.

The delimiter option has existed prior to 4.3 (and explicitly tested against
4.2p45) and should not break compatibility with older releases of bash.
2014-04-06 16:41:54 -07:00

61 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# vim: set ft=sh sw=4 sts=4 et :
mkdir process_TEST_dir || exit 2
cd process_TEST_dir || exit 3
cat <<'END' > pipe_test.bash
#!/usr/bin/env bash
echo "$1" | tr "\n" "\0" 1>&$PALUDIS_PIPE_COMMAND_WRITE_FD
response1=
while true ; do
read -d $'\0' -n 1 -u $PALUDIS_PIPE_COMMAND_READ_FD c
[[ "$c" == $'\0' ]] && break
response1="${response1}${c}"
done
echo "$2" | tr "\n" "\0" 1>&$PALUDIS_PIPE_COMMAND_WRITE_FD
response2=
while true ; do
read -d $'\0' -n 1 -u $PALUDIS_PIPE_COMMAND_READ_FD c
[[ "$c" == $'\0' ]] && break
response2="${response2}${c}"
done
exit $response1$response2
END
cat <<'END' > captured_pipe_test.bash
#!/usr/bin/env bash
echo "$1" | tr "\n" "\0" 1>&$PALUDIS_PIPE_COMMAND_WRITE_FD
response1=
while true ; do
read -d $'\0' -n 1 -u $PALUDIS_PIPE_COMMAND_READ_FD c
[[ "$c" == $'\0' ]] && break
response1="${response1}${c}"
done
echo "$2" | tr "\n" "\0" 1>&$PALUDIS_PIPE_COMMAND_WRITE_FD
response2=
while true ; do
read -d $'\0' -n 1 -u $PALUDIS_PIPE_COMMAND_READ_FD c
[[ "$c" == $'\0' ]] && break
response2="${response2}${c}"
done
echo "$3" | tr "\n" "\0" 1>&$PALUDIS_PIPE_COMMAND_WRITE_FD
response3=
while true ; do
read -d $'\0' -n 1 -u $PALUDIS_PIPE_COMMAND_READ_FD c
[[ "$c" == $'\0' ]] && break
response3="${response3}${c}"
done
echo $response2
exit $response1$response3
END