Skip to content

Instantly share code, notes, and snippets.

@azat
Last active October 11, 2020 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azat/8f01d9c1ff4387d5028b7099d5b1b3ad to your computer and use it in GitHub Desktop.
Save azat/8f01d9c1ff4387d5028b7099d5b1b3ad to your computer and use it in GitHub Desktop.
#!/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