🦊 Add display for directory config to -v option

Added a quick way to see if directories have been set up correctly. This
also eases testing for future ways of setting directories through
environment variables or options.
This commit is contained in:
Marty Oehme 2022-06-29 11:44:15 +02:00
parent 0b255413d0
commit 31550448f0
Signed by: Marty
GPG key ID: B7538B8F50A1C800
2 changed files with 34 additions and 3 deletions

4
bemoji
View file

@ -33,14 +33,14 @@ usage() {
echo " -e Only echo out the picked emoji." echo " -e Only echo out the picked emoji."
echo " -D <choice> Choose specific default lists to download if none found locally." echo " -D <choice> Choose specific default lists to download if none found locally."
echo " Valid choices: all|none|emoji|math." echo " Valid choices: all|none|emoji|math."
echo " -v Display current program version." echo " -v Display current program version and directory configuration."
echo " -h Show this help." echo " -h Show this help."
echo echo
exit "$1" exit "$1"
} }
version() { version() {
printf "v%s" "$bm_version" printf "v%s\ndatabase=%s\nhistory=%s\n" "$bm_version" "$bm_db_location" "$bm_history_file"
exit exit
} }

View file

@ -10,6 +10,7 @@ setup() {
# 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 ❤️"
# set up small default set of test emoji for each test # set up small default set of test emoji for each test
export BEMOJI_DB_LOCATION="$BATS_TEST_TMPDIR/database" export BEMOJI_DB_LOCATION="$BATS_TEST_TMPDIR/database"
export BEMOJI_CACHE_LOCATION="$BATS_TEST_TMPDIR/cache" export BEMOJI_CACHE_LOCATION="$BATS_TEST_TMPDIR/cache"
@ -34,5 +35,35 @@ setup() {
the_version=$(grep 'bm_version=' $(which bemoji)) the_version=$(grep 'bm_version=' $(which bemoji))
run bemoji -v run bemoji -v
assert_output "v${the_version#bm_version=}" assert_output --partial "v${the_version#bm_version=}"
}
@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
"
}
@test "sets XDG directory for cache by default" {
unset BEMOJI_CACHE_LOCATION
export XDG_CACHE_HOME="$BATS_TEST_TMPDIR/xdb-cache"
run bemoji -v
assert_output --regexp "
history=$BATS_TEST_TMPDIR/xdb-cache/bemoji-history.txt$"
}
@test "BEMOJI_DB_LOCATION sets correct db directory" {
run bemoji -v
assert_output --regexp "
database=$BATS_TEST_TMPDIR/database
"
}
@test "BEMOJI_CACHE_LOCATION sets correct cache directory" {
run bemoji -v
assert_output --regexp "
history=$BATS_TEST_TMPDIR/cache/bemoji-history.txt$"
} }