mirror of
https://github.com/dandavison/delta.git
synced 2024-09-19 20:28:46 +03:00
ab77bff0fc
This change makes git and delta believe that they are writing to a tty so that they invoke their child pager processes, as is required for the test. However, output is actually redirected to /dev/null. TODO: implement for the Linux version of script also. https://stackoverflow.com/a/1402389/583763
66 lines
1.5 KiB
Bash
Executable File
66 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
cleanup() {
|
|
rm -r "$TEMPDIR"
|
|
}
|
|
|
|
die() {
|
|
echo "$1" 1>&2
|
|
cleanup
|
|
exit 1
|
|
}
|
|
|
|
DELTA="${1:-./target/release/delta} --no-gitconfig --navigate"
|
|
|
|
# Trick delta into thinking that its pager is less, when really it is cat.
|
|
unset DELTA_PAGER
|
|
TEMPDIR="$(mktemp -d)"
|
|
export PAGER="$TEMPDIR/less"
|
|
cat >"$PAGER" <<-EOF
|
|
#!/bin/sh
|
|
cat
|
|
EOF
|
|
chmod 755 $PAGER
|
|
|
|
test_delta_less_hist_file_created () {
|
|
DELTA_HIST_FILE="${XDG_DATA_HOME:-$HOME/.local/share}/delta/lesshst"
|
|
rm -f ~/.lesshst "$DELTA_HIST_FILE"
|
|
[ -e "$DELTA_HIST_FILE" ] && die "Expected \"$DELTA_HIST_FILE\" not to exist"
|
|
if [[ "$OSTYPE" = darwin* ]]; then
|
|
# Trick git and delta into invoking their pager child processes, despite
|
|
# output not being a tty.
|
|
script -q /dev/null git -c pager.log="$DELTA" log -p HEAD~2...HEAD > /dev/null
|
|
else
|
|
git -c pager.log="$DELTA" log -p HEAD~2...HEAD
|
|
fi
|
|
[ -e "$DELTA_HIST_FILE" ] || die "Expected \"$DELTA_HIST_FILE\" to exist"
|
|
}
|
|
|
|
# Basic test
|
|
test_delta_less_hist_file_created
|
|
|
|
# Test it works with a custom LESSHISTFILE
|
|
export LESSHISTFILE=$TEMPDIR/delta.lesshst
|
|
test_delta_less_hist_file_created
|
|
|
|
# Test histfile sections other than `.search` at the end of the file (#1)
|
|
cat >$LESSHISTFILE <<-EOF
|
|
.shell
|
|
"pwd
|
|
"ls -Al ../data/
|
|
EOF
|
|
test_delta_less_hist_file_created
|
|
|
|
# Test histfile sections other than `.search` at the end of the file (#2)
|
|
cat >>$LESSHISTFILE <<-EOF
|
|
.mark
|
|
m a 1 7740 /etc/gitconfig
|
|
m b 1 4221 /etc/profile
|
|
EOF
|
|
test_delta_less_hist_file_created
|
|
|
|
# Cleanup
|
|
cleanup
|