clipmenu-spmenu/tests/test-clipmenu

94 lines
2 KiB
Plaintext
Raw Normal View History

2018-10-31 09:12:09 +01:00
#!/usr/bin/env bash
2017-01-15 10:48:04 +01:00
2017-02-17 18:02:02 +01:00
set -x
2017-01-15 10:48:04 +01:00
set -e
set -o pipefail
dir=$(./clipctl cache-dir)
cache_file=$dir/line_cache
2017-01-15 10:48:04 +01:00
if [[ $0 == /* ]]; then
location=${0%/*}
else
location=$PWD/${0#./}
location=${location%/*}
fi
cat - "$location/../clipmenu" > /tmp/clipmenu << 'EOF'
2018-10-31 09:12:09 +01:00
#!/usr/bin/env bash
2017-01-15 10:48:04 +01:00
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
}
# Cannot be an alias due to expansion order with $CM_LAUNCHER
dmenu() {
2017-03-19 10:54:47 +01:00
SHIM_STDOUT="Selected text. (2 lines)" shim dmenu "$@"
}
rofi() {
SHIM_STDOUT="Selected text. (2 lines)" shim rofi "$@"
}
2017-01-15 10:48:04 +01:00
alias xsel='shim xsel'
alias xclip='shim xclip'
alias clipctl='./clipctl'
2017-01-15 10:48:04 +01:00
EOF
chmod a+x /tmp/clipmenu
rm -rf "$dir"
mkdir -p "$dir"
cat > "$cache_file" << 'EOF'
2018-02-20 12:30:07 +01:00
1234 Selected text. (2 lines)
1235 Selected text 2. (2 lines)
2017-01-15 10:48:04 +01:00
EOF
cat > "$dir/$(cksum <<< 'Selected text. (2 lines)')" << 'EOF'
Selected text.
Yes, it's selected text.
EOF
### TESTS ###
temp=$(mktemp)
2017-02-17 18:02:02 +01:00
trap 'cat "$temp"' EXIT
2017-03-19 10:54:56 +01:00
/tmp/clipmenu --foo bar > "$temp" 2>&1
2017-01-15 10:48:04 +01:00
# Arguments are transparently passed to dmenu
grep -Fxq 'dmenu args: -l 8 --foo bar' "$temp"
2017-01-15 10:48:04 +01:00
# Output from cache file should get to dmenu, reversed
grep -Fxq 'dmenu line 1 stdin: Selected text 2. (2 lines)' "$temp"
grep -Fxq 'dmenu line 2 stdin: Selected text. (2 lines)' "$temp"
2017-01-15 10:48:04 +01:00
# xsel should copy both to clipboard *and* primary
grep -Fxq 'xsel args: --logfile /dev/null -i --clipboard' "$temp"
grep -Fxq 'xsel args: --logfile /dev/null -i --primary' "$temp"
2017-01-15 10:48:04 +01:00
grep -Fxq 'xsel line 1 stdin: Selected text.' "$temp"
grep -Fxq "xsel line 2 stdin: Yes, it's selected text." "$temp"
2017-03-19 10:54:56 +01:00
CM_LAUNCHER=rofi /tmp/clipmenu --foo bar > "$temp" 2>&1
# We have a special case to add -dmenu for rofi
grep -Fxq 'rofi args: -l 8 -dmenu -p clipmenu --foo bar' "$temp"