From 28aa2aa5224b3fcc2e125d8703b61a11b080d79a Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 6 Aug 2022 09:42:48 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Add=20tests=20for=20clipping,=20?= =?UTF-8?q?echo=20and=20typing=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added a simple test for each of the base command options: echo, type, clip. It uses custom commands set through environment options so does not yet test the actual default command logic (finding a typer, clipper), that is still a TODO. Also split tests into tests concerning commands of the program and tests concerning the directory settings and options of the program, to avoid ending up with a single test file spanning hundreds of lines. --- test/bemoji_cmds.bats | 48 +++++++++++++++++++ test/{bemoji.bats => bemoji_directories.bats} | 12 ----- 2 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 test/bemoji_cmds.bats rename test/{bemoji.bats => bemoji_directories.bats} (88%) diff --git a/test/bemoji_cmds.bats b/test/bemoji_cmds.bats new file mode 100644 index 0000000..ac1c3a4 --- /dev/null +++ b/test/bemoji_cmds.bats @@ -0,0 +1,48 @@ +#!/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() { + load 'test_helper/bats-support/load' + load 'test_helper/bats-assert/load' + + # 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 "-v prints correct version number" { + the_version=$(grep 'bm_version=' "$(which bemoji)") + + run bemoji -v + assert_output --partial "v${the_version#bm_version=}" +} + +@test "Runs clipping command by default" { + BEMOJI_CLIP_CMD="echo clipping default" run bemoji 3>&- + assert_output "clipping default" +} + +@test "Runs echo command on -e option" { + run bemoji -e 3>&- + assert_output "❤️" +} + +@test "Runs clipping command on -c option" { + BEMOJI_CLIP_CMD="echo clipping result" run bemoji -c 3>&- + assert_output "clipping result" +} + +@test "Runs typing command on -t option" { + BEMOJI_TYPE_CMD="echo typing result" run bemoji -t 3>&- + assert_output "typing result" +} diff --git a/test/bemoji.bats b/test/bemoji_directories.bats similarity index 88% rename from test/bemoji.bats rename to test/bemoji_directories.bats index cff3af6..28068e1 100644 --- a/test/bemoji.bats +++ b/test/bemoji_directories.bats @@ -28,18 +28,6 @@ setup() { assert_success } -@test "can receive 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 --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"