2022-06-29 07:25:28 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2022-06-29 09:58:51 +00:00
|
|
|
setup_file() {
|
2022-06-29 07:25:28 +00:00
|
|
|
# make bemoji executable from anywhere relative to current testfile
|
|
|
|
TEST_DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
|
|
|
|
PATH="$TEST_DIR/..:$PATH"
|
2022-06-29 09:58:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
load 'test_helper/bats-support/load'
|
|
|
|
load 'test_helper/bats-assert/load'
|
2022-06-29 08:55:47 +00:00
|
|
|
|
|
|
|
# mock out interactive picker for static emoji return
|
|
|
|
export BEMOJI_PICKER_CMD="echo ❤️"
|
2022-06-29 09:44:15 +00:00
|
|
|
|
2022-06-29 08:55:47 +00:00
|
|
|
# set up small default set of test emoji for each test
|
|
|
|
export BEMOJI_DB_LOCATION="$BATS_TEST_TMPDIR/database"
|
2022-11-03 14:23:39 +00:00
|
|
|
export BEMOJI_HISTORY_LOCATION="$BATS_TEST_TMPDIR/history"
|
|
|
|
mkdir -p "$BEMOJI_DB_LOCATION" "$BEMOJI_HISTORY_LOCATION"
|
2022-06-29 08:55:47 +00:00
|
|
|
cat "$BATS_TEST_DIRNAME/resources/test_emoji.txt" > "$BEMOJI_DB_LOCATION/emoji.txt"
|
2022-06-29 07:25:28 +00:00
|
|
|
}
|
|
|
|
|
2022-06-29 09:58:51 +00:00
|
|
|
@test "can run script" {
|
2022-06-29 08:08:01 +00:00
|
|
|
export BEMOJI_CLIP_CMD="echo clip test only"
|
2022-06-29 07:25:28 +00:00
|
|
|
# closing FD3 manually to prevent hangs, see
|
|
|
|
# https://bats-core.readthedocs.io/en/stable/writing-tests.html#file-descriptor-3-read-this-if-bats-hangs
|
|
|
|
run bemoji 3>&-
|
|
|
|
assert_success
|
|
|
|
}
|
2022-06-29 08:55:47 +00:00
|
|
|
|
2022-06-29 09:44:15 +00:00
|
|
|
@test "sets XDG directory for db by default" {
|
|
|
|
unset BEMOJI_DB_LOCATION
|
|
|
|
export XDG_DATA_HOME="$BATS_TEST_TMPDIR/xdb-db"
|
|
|
|
run bemoji -v
|
|
|
|
assert_output --regexp "
|
|
|
|
database=$BATS_TEST_TMPDIR/xdb-db/bemoji
|
|
|
|
"
|
|
|
|
}
|
|
|
|
|
2022-06-29 09:58:51 +00:00
|
|
|
@test "sets XDG directory for history by default" {
|
2022-11-03 14:23:39 +00:00
|
|
|
unset BEMOJI_HISTORY_LOCATION
|
2022-10-12 14:56:15 +00:00
|
|
|
export XDG_STATE_HOME="$BATS_TEST_TMPDIR/xdb-cache"
|
2022-06-29 09:44:15 +00:00
|
|
|
run bemoji -v
|
|
|
|
assert_output --regexp "
|
|
|
|
history=$BATS_TEST_TMPDIR/xdb-cache/bemoji-history.txt$"
|
|
|
|
}
|
|
|
|
|
2022-06-29 09:58:51 +00:00
|
|
|
@test "falls back to default db directory if no XDG found" {
|
|
|
|
unset BEMOJI_DB_LOCATION
|
|
|
|
run bemoji -v
|
|
|
|
assert_output --regexp "
|
|
|
|
database=$HOME/.local/share/bemoji
|
|
|
|
"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "falls back to default history location if no XDG found" {
|
2022-11-03 14:23:39 +00:00
|
|
|
unset BEMOJI_HISTORY_LOCATION
|
2022-06-29 09:58:51 +00:00
|
|
|
run bemoji -v
|
|
|
|
assert_output --regexp "
|
2022-10-12 14:56:15 +00:00
|
|
|
history=$HOME/.local/state/bemoji-history.txt$"
|
2022-06-29 09:58:51 +00:00
|
|
|
}
|
|
|
|
|
2022-06-29 09:44:15 +00:00
|
|
|
@test "BEMOJI_DB_LOCATION sets correct db directory" {
|
|
|
|
run bemoji -v
|
|
|
|
assert_output --regexp "
|
|
|
|
database=$BATS_TEST_TMPDIR/database
|
|
|
|
"
|
|
|
|
}
|
|
|
|
|
2022-11-03 14:23:39 +00:00
|
|
|
@test "BEMOJI_HISTORY_LOCATION sets correct history directory" {
|
2022-06-29 09:44:15 +00:00
|
|
|
run bemoji -v
|
|
|
|
assert_output --regexp "
|
2022-11-03 14:23:39 +00:00
|
|
|
history=$BATS_TEST_TMPDIR/history/bemoji-history.txt$"
|
2022-06-29 08:55:47 +00:00
|
|
|
}
|