summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2021-03-10 10:05:09 -0500
committerGitHub <noreply@github.com>2021-03-10 10:05:09 -0500
commit0eeb822d0e9e9f340866a8047a0403407acc52d8 (patch)
treeb69535a4949a01fa96ae298c8b0eb7c5b3f828a8
parenta872caa31cf38770448583944960963620625e15 (diff)
parentbf04c7b602a3ea2576749cc378cd4c8129592d11 (diff)
Merge pull request #536 from dandavison/navigate-less-integration-tests
Add navigate/less integration test
-rw-r--r--Makefile1
-rw-r--r--src/bat_utils/output.rs2
-rwxr-xr-xtests/test_navigate_less_history_file59
3 files changed, 61 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 6c586645..c534338f 100644
--- a/Makefile
+++ b/Makefile
@@ -15,6 +15,7 @@ unit-test:
end-to-end-test: build
./tests/test_raw_output_matches_git_on_full_repo_history
./tests/test_deprecated_options > /dev/null
+ ./test/test_navigate_less_history_file
release:
@make -f release.Makefile release
diff --git a/src/bat_utils/output.rs b/src/bat_utils/output.rs
index 8e959eb7..26cd4e21 100644
--- a/src/bat_utils/output.rs
+++ b/src/bat_utils/output.rs
@@ -132,7 +132,7 @@ delta is not an appropriate value for $PAGER \
p.args(args);
p
};
- if config.navigate {
+ if is_less && config.navigate {
if let Ok(hist_file) =
navigate::copy_less_hist_file_and_append_navigate_regexp(config)
{
diff --git a/tests/test_navigate_less_history_file b/tests/test_navigate_less_history_file
new file mode 100755
index 00000000..7ec5a95f
--- /dev/null
+++ b/tests/test_navigate_less_history_file
@@ -0,0 +1,59 @@
+#!/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"
+ git -c pager.log="$DELTA" log -p HEAD~2...HEAD
+ [ -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