From 31550448f00e8f4d024508533962485567de1068 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 29 Jun 2022 11:44:15 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=8A=20Add=20display=20for=20directory?= =?UTF-8?q?=20config=20to=20-v=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- bemoji | 4 ++-- test/bemoji.bats | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/bemoji b/bemoji index 4619e30..e468965 100755 --- a/bemoji +++ b/bemoji @@ -33,14 +33,14 @@ usage() { echo " -e Only echo out the picked emoji." echo " -D Choose specific default lists to download if none found locally." 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 exit "$1" } version() { - printf "v%s" "$bm_version" + printf "v%s\ndatabase=%s\nhistory=%s\n" "$bm_version" "$bm_db_location" "$bm_history_file" exit } diff --git a/test/bemoji.bats b/test/bemoji.bats index a7621a3..0a87288 100644 --- a/test/bemoji.bats +++ b/test/bemoji.bats @@ -10,6 +10,7 @@ setup() { # mock out interactive picker for static emoji return export BEMOJI_PICKER_CMD="echo ❤️" + # set up small default set of test emoji for each test export BEMOJI_DB_LOCATION="$BATS_TEST_TMPDIR/database" export BEMOJI_CACHE_LOCATION="$BATS_TEST_TMPDIR/cache" @@ -34,5 +35,35 @@ setup() { the_version=$(grep 'bm_version=' $(which bemoji)) 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$" }