From 936f19bca6ceda9da55286672faba4c329a6b45f Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 29 Jun 2022 10:55:47 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Set=20up=20default=20emoji=20lis?= =?UTF-8?q?t=20for=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Inject a tiny sample emoji list into each test so no download function is engaged by default. Add tests for version display. --- bemoji | 2 +- test/bemoji.bats | 20 ++++++++++++++++++++ test/resources/test_emoji.txt | 4 ++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 test/resources/test_emoji.txt diff --git a/bemoji b/bemoji index 92661f1..aadd9a8 100755 --- a/bemoji +++ b/bemoji @@ -40,7 +40,7 @@ usage() { } version() { - echo "v${bm_version}" + printf "v%s" "$bm_version" exit } diff --git a/test/bemoji.bats b/test/bemoji.bats index ad9936d..6229b50 100644 --- a/test/bemoji.bats +++ b/test/bemoji.bats @@ -7,6 +7,14 @@ setup() { # 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 + 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" + mkdir -p "$BEMOJI_DB_LOCATION" "$BEMOJI_CACHE_LOCATION" + cat "$BATS_TEST_DIRNAME/resources/test_emoji.txt" > "$BEMOJI_DB_LOCATION/emoji.txt" } @test "test can run script" { @@ -15,3 +23,15 @@ setup() { run bemoji 3>&- assert_success } + +@test "test receives custom picker mock output" { + run bemoji -e 3>&- + assert_output "❤️" +} + +@test "-v prints correct version number" { + the_version=$(grep 'bm_version=' $(which bemoji)) + + run bemoji -v + assert_output "v${the_version#bm_version=}" +} diff --git a/test/resources/test_emoji.txt b/test/resources/test_emoji.txt new file mode 100644 index 0000000..cdb4060 --- /dev/null +++ b/test/resources/test_emoji.txt @@ -0,0 +1,4 @@ +❤️ red heart +😀 grinning face +😃 grinning face with big eyes +😄 grinning face with smiling eyes