Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env bash
# XXX: cannot use expect since we need two clients
# XXX: requires bash 4.4+
function assert()
{
if ! "$@"; then
echo "'$*' failed" >&2
exit 1
fi
}
rm -f replxx_history.txt
coproc client1 { replxx-example-cxx-api >& client1.txt; }
# Will produce warning, but should work:
# warning: execute_coproc: coproc [3418021:client1] still exists
coproc client2 { replxx-example-cxx-api >& client2.txt; }
# save fds, to avoid exec for each echo
exec 10>&${client1[1]}-
exec 20>&${client2[1]}-
# .hist_autosave
echo .hist_autosave >&10
echo .hist_autosave >&20
# regular history
echo first_line >&10
echo second_line >&20
# wait until
# - the replxx_history.txt will be dumped
sleep 0.1
assert grep -F -q first_line replxx_history.txt
assert grep -F -q second_line replxx_history.txt
# dump history
echo .history >&10
echo .history >&20
# wait until
# - client1.txt
# - client2.txt
sleep 0.1
assert test $(grep -c -F second_line client1.txt) -eq 0
assert test $(grep -c -F first_line client2.txt) -eq 0
# quit
echo .quit >&10
echo .quit >&20
wait $client1_PID
wait $client2_PID
echo OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment