hishtory/client/lib/test_config.sh
David Dworken dc6fb6a47b Refactor tests to make them non-flakey and pass on actions
This required adding the ability to have hishtory run synchronously to avoid reconditions. I also added additional waiting code. Also a whole bunch of new tests and disabled gorm's default logger which also caued flakeyness
2022-04-14 20:18:49 -07:00

30 lines
853 B
Bash

# This script should be sourced inside of .bashrc to integrate bash with hishtory
# This is the same as config.sh, except it doesn't run the save process in the background. This is crucial to making tests reproducible.
# Implementation of PreCommand and PostCommand based on https://jichu4n.com/posts/debug-trap-and-prompt_command-in-bash/
function PreCommand() {
if [ -z "$HISHTORY_AT_PROMPT" ]; then
return
fi
unset HISHTORY_AT_PROMPT
# Run before every command
HISHTORY_START_TIME=`date +%s%N`
}
trap "PreCommand" DEBUG
HISHTORY_FIRST_PROMPT=1
function PostCommand() {
EXIT_CODE=$?
HISHTORY_AT_PROMPT=1
if [ -n "$HISHTORY_FIRST_PROMPT" ]; then
unset HISHTORY_FIRST_PROMPT
return
fi
# Run after every prompt
hishtory saveHistoryEntry $EXIT_CODE "`history 1`" $HISHTORY_START_TIME
}
PROMPT_COMMAND="PostCommand"