From e85c7691e2b47a9f8dd916666f9966c561fb6c99 Mon Sep 17 00:00:00 2001 From: Chris Down Date: Sun, 15 Jan 2017 09:48:04 +0000 Subject: [PATCH] tests: Add clipmenu test --- .travis.yml | 1 + tests/test-clipmenu | 76 +++++++++++++++++++++++++++++++++++++++ {test => tests}/test-perf | 0 3 files changed, 77 insertions(+) create mode 100755 tests/test-clipmenu rename {test => tests}/test-perf (100%) diff --git a/.travis.yml b/.travis.yml index ec0f110..6b793dd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ before_script: script: - shellcheck -s bash clipmenu clipmenud + - tests/test-clipmenu matrix: fast_finish: true diff --git a/tests/test-clipmenu b/tests/test-clipmenu new file mode 100755 index 0000000..fcc4a0b --- /dev/null +++ b/tests/test-clipmenu @@ -0,0 +1,76 @@ +#!/bin/bash + +set -e +set -o pipefail + +dir=/tmp/clipmenu.$USER +cache_file=$dir/line_cache + +if [[ $0 == /* ]]; then + location=${0%/*} +else + location=$PWD/${0#./} + location=${location%/*} +fi + +cat - "$location/../clipmenu" > /tmp/clipmenu << 'EOF' +#!/bin/bash + +shopt -s expand_aliases + +shim() { + printf '%s args:' "$1" >&2 + printf ' %q' "${@:2}" >&2 + printf '\n' >&2 + + i=0 + + while IFS= read -r line; do + let i++ + printf '%s line %d stdin: %s\n' "$1" "$i" "$line" >&2 + done + + if [[ -v SHIM_STDOUT ]]; then + printf '%s\n' "$SHIM_STDOUT" + fi +} + +alias dmenu='SHIM_STDOUT="Selected text. (2 lines)" shim dmenu' +alias xsel='shim xsel' +alias xclip='shim xclip' +EOF + +chmod a+x /tmp/clipmenu + +rm -rf "$dir" +mkdir -p "$dir" + +cat > "$cache_file" << 'EOF' +Selected text. (2 lines) +Selected text 2. (2 lines) +EOF + +cat > "$dir/$(cksum <<< 'Selected text. (2 lines)')" << 'EOF' +Selected text. +Yes, it's selected text. +EOF + +### TESTS ### + +output=$(/tmp/clipmenu --foo bar 2>&1) + +printf '%s\n' "$output" > /tmp/qq + +# Arguments are transparently passed to dmenu +grep -Fxq 'dmenu args: -l 8 --foo bar' <<< "$output" + +# Output from cache file should get to dmenu, reversed +grep -Fxq 'dmenu line 1 stdin: Selected text 2. (2 lines)' <<< "$output" +grep -Fxq 'dmenu line 2 stdin: Selected text. (2 lines)' <<< "$output" + +# xsel should copy both to clipboard *and* primary +grep -Fxq 'xsel args: --logfile /dev/null -i --clipboard' <<< "$output" +grep -Fxq 'xsel args: --logfile /dev/null -i --primary' <<< "$output" + +grep -Fxq 'xsel line 1 stdin: Selected text.' <<< "$output" +grep -Fxq "xsel line 2 stdin: Yes, it's selected text." <<< "$output" diff --git a/test/test-perf b/tests/test-perf similarity index 100% rename from test/test-perf rename to tests/test-perf