From ceea79eb3a8a1a15825ce7646bc3b4f8c4b2223f Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 29 Jun 2022 09:25:28 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Add=20simple=20test=20framework?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now that the project is finding a little adoption it is really high time to bring some tests into the code to ensure everything works as it should. This first version will only provide a simple test harness from which tests can slowly be written for other parts of the program. --- .gitmodules | 9 +++++++++ test/bats | 1 + test/bemoji.bats | 17 +++++++++++++++++ test/test_helper/bats-assert | 1 + test/test_helper/bats-support | 1 + 5 files changed, 29 insertions(+) create mode 100644 .gitmodules create mode 160000 test/bats create mode 100644 test/bemoji.bats create mode 160000 test/test_helper/bats-assert create mode 160000 test/test_helper/bats-support diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b7efcb4 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,9 @@ +[submodule "test/bats"] + path = test/bats + url = https://github.com/bats-core/bats-core.git +[submodule "test/test_helper/bats-support"] + path = test/test_helper/bats-support + url = https://github.com/bats-core/bats-support.git +[submodule "test/test_helper/bats-assert"] + path = test/test_helper/bats-assert + url = https://github.com/bats-core/bats-assert.git diff --git a/test/bats b/test/bats new file mode 160000 index 0000000..26c9b18 --- /dev/null +++ b/test/bats @@ -0,0 +1 @@ +Subproject commit 26c9b18983c3ce4cf24c6f6ee942abd8b1c3ee18 diff --git a/test/bemoji.bats b/test/bemoji.bats new file mode 100644 index 0000000..ad9936d --- /dev/null +++ b/test/bemoji.bats @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +setup() { + load 'test_helper/bats-support/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" +} + +@test "test can run script" { + # 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 + run bemoji 3>&- + assert_success +} diff --git a/test/test_helper/bats-assert b/test/test_helper/bats-assert new file mode 160000 index 0000000..ffe84ea --- /dev/null +++ b/test/test_helper/bats-assert @@ -0,0 +1 @@ +Subproject commit ffe84ea5dd43b568851549b3e241db150c12929c diff --git a/test/test_helper/bats-support b/test/test_helper/bats-support new file mode 160000 index 0000000..3c8fadc --- /dev/null +++ b/test/test_helper/bats-support @@ -0,0 +1 @@ +Subproject commit 3c8fadc5097c9acfc96d836dced2bb598e48b009