🧪 Add tests for XDG base directory adherence
Added simple tests for database and cache locations. Moved test PATH setup to new file-level function which should slightly speed up testing and makes more sense conceptually to set the bemoji executable to be in the path once for all tests.
This commit is contained in:
parent
ce17ae58f1
commit
2a17237a96
1 changed files with 24 additions and 7 deletions
|
@ -1,13 +1,15 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
setup_file() {
|
||||||
|
# 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"
|
||||||
|
}
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
load 'test_helper/bats-support/load'
|
load 'test_helper/bats-support/load'
|
||||||
load 'test_helper/bats-assert/load'
|
load 'test_helper/bats-assert/load'
|
||||||
|
|
||||||
# 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"
|
|
||||||
|
|
||||||
# mock out interactive picker for static emoji return
|
# mock out interactive picker for static emoji return
|
||||||
export BEMOJI_PICKER_CMD="echo ❤️"
|
export BEMOJI_PICKER_CMD="echo ❤️"
|
||||||
|
|
||||||
|
@ -18,7 +20,7 @@ setup() {
|
||||||
cat "$BATS_TEST_DIRNAME/resources/test_emoji.txt" > "$BEMOJI_DB_LOCATION/emoji.txt"
|
cat "$BATS_TEST_DIRNAME/resources/test_emoji.txt" > "$BEMOJI_DB_LOCATION/emoji.txt"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "test can run script" {
|
@test "can run script" {
|
||||||
export BEMOJI_CLIP_CMD="echo clip test only"
|
export BEMOJI_CLIP_CMD="echo clip test only"
|
||||||
# closing FD3 manually to prevent hangs, see
|
# 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
|
# https://bats-core.readthedocs.io/en/stable/writing-tests.html#file-descriptor-3-read-this-if-bats-hangs
|
||||||
|
@ -26,7 +28,7 @@ setup() {
|
||||||
assert_success
|
assert_success
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "test receives custom picker mock output" {
|
@test "can receive custom picker mock output" {
|
||||||
run bemoji -e 3>&-
|
run bemoji -e 3>&-
|
||||||
assert_output "❤️"
|
assert_output "❤️"
|
||||||
}
|
}
|
||||||
|
@ -47,7 +49,7 @@ database=$BATS_TEST_TMPDIR/xdb-db/bemoji
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "sets XDG directory for cache by default" {
|
@test "sets XDG directory for history by default" {
|
||||||
unset BEMOJI_CACHE_LOCATION
|
unset BEMOJI_CACHE_LOCATION
|
||||||
export XDG_CACHE_HOME="$BATS_TEST_TMPDIR/xdb-cache"
|
export XDG_CACHE_HOME="$BATS_TEST_TMPDIR/xdb-cache"
|
||||||
run bemoji -v
|
run bemoji -v
|
||||||
|
@ -55,6 +57,21 @@ database=$BATS_TEST_TMPDIR/xdb-db/bemoji
|
||||||
history=$BATS_TEST_TMPDIR/xdb-cache/bemoji-history.txt$"
|
history=$BATS_TEST_TMPDIR/xdb-cache/bemoji-history.txt$"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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" {
|
||||||
|
unset BEMOJI_CACHE_LOCATION
|
||||||
|
run bemoji -v
|
||||||
|
assert_output --regexp "
|
||||||
|
history=$HOME/.cache/bemoji-history.txt$"
|
||||||
|
}
|
||||||
|
|
||||||
@test "BEMOJI_DB_LOCATION sets correct db directory" {
|
@test "BEMOJI_DB_LOCATION sets correct db directory" {
|
||||||
run bemoji -v
|
run bemoji -v
|
||||||
assert_output --regexp "
|
assert_output --regexp "
|
||||||
|
|
Loading…
Reference in a new issue