Debian Codegraph @

tests/test_navigate_less_history_file

raw symbols SCIP
1 #!/bin/bash
2
3 set -e
4
5 cleanup() {
6 rm -r "$TEMPDIR"
7 }
8
9 die() {
10 echo "$1" 1>&2
11 cleanup
12 exit 1
13 }
14
15 DELTA="${1:-./target/release/delta} --no-gitconfig --navigate"
16
17 # Trick delta into thinking that its pager is less, when really it is cat.
18 unset DELTA_PAGER
19 TEMPDIR="$(mktemp -d)"
20 export PAGER="$TEMPDIR/less"
21 cat >"$PAGER" <<-EOF
22 #!/bin/sh
23 cat
24 EOF
25 chmod 755 $PAGER
26
27 test_delta_less_hist_file_created () {
28 DELTA_HIST_FILE="${XDG_DATA_HOME:-$HOME/.local/share}/delta/lesshst"
29 rm -f ~/.lesshst "$DELTA_HIST_FILE"
30 [ -e "$DELTA_HIST_FILE" ] && die "Expected \"$DELTA_HIST_FILE\" not to exist"
31 if [[ "$OSTYPE" = darwin* ]]; then
32 # Trick git and delta into invoking their pager child processes, despite
33 # output not being a tty.
34 script -q /dev/null git -c pager.log="$DELTA" log -p HEAD~2...HEAD > /dev/null
35 else
36 git -c pager.log="$DELTA" log -p HEAD~2...HEAD
37 fi
38 [ -e "$DELTA_HIST_FILE" ] || die "Expected \"$DELTA_HIST_FILE\" to exist"
39 }
40
41 # Basic test
42 test_delta_less_hist_file_created
43
44 # Test it works with a custom LESSHISTFILE
45 export LESSHISTFILE=$TEMPDIR/delta.lesshst
46 test_delta_less_hist_file_created
47
48 # Test histfile sections other than `.search` at the end of the file (#1)
49 cat >$LESSHISTFILE <<-EOF
50 .shell
51 "pwd
52 "ls -Al ../data/
53 EOF
54 test_delta_less_hist_file_created
55
56 # Test histfile sections other than `.search` at the end of the file (#2)
57 cat >>$LESSHISTFILE <<-EOF
58 .mark
59 m a 1 7740 /etc/gitconfig
60 m b 1 4221 /etc/profile
61 EOF
62 test_delta_less_hist_file_created
63
64 # Cleanup
65 cleanup