Skip to content

Commit

Permalink
add main_test
Browse files Browse the repository at this point in the history
  • Loading branch information
Chemaclass committed Sep 15, 2024
1 parent 01a3924 commit dba8610
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
8 changes: 0 additions & 8 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
# create-pr
PR_TEMPLATE_PATH=".github/PULL_REQUEST_TEMPLATE.md"
PR_TITLE_TEMPLATE="{{TICKET_KEY}}-{{TICKET_NUMBER}} {{PR_TITLE}}"
PR_TICKET_LINK_PREFIX="https://github.com/Chemaclass/create-pr/issues/"
PR_LINK_PREFIX_TEXT="Closes: "
PR_LABEL_MAPPING="docs:documentation; fix|bug|bugfix|hotfix:bug; default:enhancement"

# bashunit
BASHUNIT_DEFAULT_PATH="tests"
BASHUNIT_TESTS_ENV=.env.tests
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ SRC_SCRIPTS_DIR=src
PRE_COMMIT_SCRIPTS_FILE=./bin/pre-commit

test: $(TEST_SCRIPTS_DIR)
@lib/bashunit tests -e .env.tests
@lib/bashunit tests

pre_commit/install:
@echo "Installing pre-commit hook"
Expand Down
2 changes: 1 addition & 1 deletion src/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -euo pipefail

function main::action() {
local args=("$@")
local args=("${@:-}")

echo "Main Action"

Expand Down
20 changes: 20 additions & 0 deletions tests/unit/main_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

function set_up() {
_CURRENT_DIR="$(dirname "${BASH_SOURCE[0]}")"
source "$_CURRENT_DIR/../../src/main.sh"
}

function test_main_without_args() {
actual=$(main::action)

assert_same "Main Action" "$actual"
}

function test_main_with_args() {
actual=$(main::action arg1 --option="value2")

assert_same "Main Action
arg1
--option=value2" "$actual"
}

0 comments on commit dba8610

Please sign in to comment.