From a570e9ab512ead8e709ca9e561505ec31edf5d61 Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Wed, 6 Dec 2023 09:03:01 +0100 Subject: [PATCH 1/5] chore: Remove example make scripts -n --- Makefile | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Makefile b/Makefile index c0509ff7..3ae282a6 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,6 @@ help: @echo " test Run the test" @echo " test/list List all the test under the tests directory" @echo " test/watch Automatically run the test every second" - @echo " test/example Run test from the example directory" @echo " env/example Makes a copy of the keys on your .env file" @echo " pre_commit/install Installs the pre-commit hook" @echo " pre_commit/run Function that will be called when the pre-commit runs" @@ -90,10 +89,3 @@ ifndef LINTER_CHECKER else @ec -config .editorconfig && printf "\e[1m\e[32m%s\e[0m\n" "editorconfig-check: OK!" endif - -test/example: - @./bashunit $(EXAMPLE_TEST_SCRIPTS) - -test/watch/example: - @./bashunit $(EXAMPLE_TEST_SCRIPTS) - @fswatch -m poll_monitor -or $(EXAMPLE_TEST_SCRIPTS) | xargs -n1 ./bashunit $(EXAMPLE_TEST_SCRIPTS) From a255fa70f9415f4077c43de594d2f5dd3e86cdca Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Wed, 6 Dec 2023 09:05:11 +0100 Subject: [PATCH 2/5] chore: Delete example/logic tests Because we have them already duplicated under tests/functional dir --- example/logic.sh | 3 -- example/logic_test.sh | 117 ------------------------------------------ 2 files changed, 120 deletions(-) delete mode 100755 example/logic.sh delete mode 100755 example/logic_test.sh diff --git a/example/logic.sh b/example/logic.sh deleted file mode 100755 index 883a77ac..00000000 --- a/example/logic.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -echo "expected $1" diff --git a/example/logic_test.sh b/example/logic_test.sh deleted file mode 100755 index 951b227c..00000000 --- a/example/logic_test.sh +++ /dev/null @@ -1,117 +0,0 @@ -#!/bin/bash - -ROOT_DIR="$(dirname "${BASH_SOURCE[0]}")/.." -SCRIPT="$ROOT_DIR/example/logic.sh" - -function test_text_should_be_equal() { - assert_equals "expected 123" "$($SCRIPT "123")" -} - -function test_text_should_contain() { - assert_contains "expect" "$($SCRIPT "123")" -} - -function test_text_should_not_contain() { - assert_not_contains "expecs" "$($SCRIPT "123")" -} - -function test_text_should_match_a_regular_expression() { - assert_matches ".*xpec*" "$($SCRIPT "123")" -} - -function test_text_should_not_match_a_regular_expression() { - assert_not_matches ".*xpes.*" "$($SCRIPT "123")" -} - -function test_should_validate_an_ok_exit_code() { - function fake_function() { - return 0 - } - - fake_function - - assert_exit_code "0" -} - - -function test_should_validate_a_non_ok_exit_code() { - function fake_function() { - return 1 - } - - fake_function - - assert_exit_code "1" -} - -function test_other_way_of_using_the_exit_code() { - function fake_function() { - return 1 - } - - assert_exit_code "1" "$(fake_function)" -} - -function test_successful_exit_code() { - function fake_function() { - return 0 - } - - assert_successful_code "$(fake_function)" -} - -function test_other_way_of_using_the_successful_exit_code() { - function fake_function() { - return 0 - } - - fake_function - - assert_successful_code -} - -function test_general_error() { - function fake_function() { - return 1 - } - - assert_general_error "$(fake_function)" -} - -function test_other_way_of_using_the_general_error() { - function fake_function() { - return 1 - } - - fake_function - - assert_general_error -} - -function test_should_assert_exit_code_of_a_non_existing_command() { - assert_command_not_found "$(a_non_existing_function > /dev/null 2>&1)" -} - -function test_should_assert_that_an_array_contains_1234() { - local distros=(Ubuntu 1234 Linux\ Mint) - - assert_array_contains "1234" "${distros[@]}" -} - -function test_should_assert_that_an_array_not_contains_1234() { - local distros=(Ubuntu 1234 Linux\ Mint) - - assert_array_not_contains "a_non_existing_element" "${distros[@]}" -} - -function provider_existing_directories() { - local directories=(/*) - echo "${directories[@]}" -} - -# data_provider provider_existing_directories -function test_should_directory_exists_from_data_provider() { - local directory=$1 - - assert_directory_exists "$directory" -} From 1363c278d559cae80a6bffcfbed0b266092c9522 Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Wed, 6 Dec 2023 09:05:45 +0100 Subject: [PATCH 3/5] chore: Add example/custom-functions --- example/custom-functions.sh | 5 +++++ example/custom-functions_test.sh | 10 ++++++++++ 2 files changed, 15 insertions(+) create mode 100755 example/custom-functions.sh create mode 100755 example/custom-functions_test.sh diff --git a/example/custom-functions.sh b/example/custom-functions.sh new file mode 100755 index 00000000..cfc7500e --- /dev/null +++ b/example/custom-functions.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +function say_hi(){ + echo "Hi, $1!" +} diff --git a/example/custom-functions_test.sh b/example/custom-functions_test.sh new file mode 100755 index 00000000..58faa181 --- /dev/null +++ b/example/custom-functions_test.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +function set_up_before_script() { + ROOT_DIR="$(dirname "${BASH_SOURCE[0]}")/.." + source "$ROOT_DIR/example/custom-functions.sh" +} + +function test_say_hi() { + assert_equals "Hi, Juan!" "$(say_hi "Juan")" +} From b517f5cfe510e3aa136b115e701e8e40b53ae329 Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Wed, 6 Dec 2023 09:05:57 +0100 Subject: [PATCH 4/5] chore: Add example/script-logic --- example/README.md | 4 ++-- example/script-logic.sh | 3 +++ example/script-logic_test.sh | 10 ++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100755 example/script-logic.sh create mode 100755 example/script-logic_test.sh diff --git a/example/README.md b/example/README.md index 63c5a078..7627328b 100644 --- a/example/README.md +++ b/example/README.md @@ -4,9 +4,9 @@ An example using this **bashunit** testing library. ## Demo usage -This demo uses **bashunit** itself. There, you'll find various tests showcasing the file and different **bashunit** functionalities. +This demo uses **bashunit** itself. You will find various tests showcasing the file and different **bashunit** functionalities. To run the tests from this example, simply execute the following command from the project root folder. ```bash -make test/example +./bashunit example/*_test.sh ``` diff --git a/example/script-logic.sh b/example/script-logic.sh new file mode 100755 index 00000000..883a77ac --- /dev/null +++ b/example/script-logic.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "expected $1" diff --git a/example/script-logic_test.sh b/example/script-logic_test.sh new file mode 100755 index 00000000..7b9638e8 --- /dev/null +++ b/example/script-logic_test.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +function set_up() { + ROOT_DIR="$(dirname "${BASH_SOURCE[0]}")/.." + SCRIPT="$ROOT_DIR/example/script-logic.sh" +} + +function test_script() { + assert_equals "expected 123" "$($SCRIPT "123")" +} From 214797ad9490b4f39ec2e52347f7f169d48fdc02 Mon Sep 17 00:00:00 2001 From: antonio-gg-dev Date: Wed, 6 Dec 2023 09:56:56 +0100 Subject: [PATCH 5/5] lint file casing and add more examples --- example/README.md | 2 +- example/custom-functions_test.sh | 10 ---------- .../{custom-functions.sh => custom_functions.sh} | 0 example/custom_functions_test.sh | 14 ++++++++++++++ example/script-logic_test.sh | 10 ---------- example/{script-logic.sh => script_logic.sh} | 0 example/script_logic_test.sh | 14 ++++++++++++++ 7 files changed, 29 insertions(+), 21 deletions(-) delete mode 100755 example/custom-functions_test.sh rename example/{custom-functions.sh => custom_functions.sh} (100%) create mode 100755 example/custom_functions_test.sh delete mode 100755 example/script-logic_test.sh rename example/{script-logic.sh => script_logic.sh} (100%) create mode 100755 example/script_logic_test.sh diff --git a/example/README.md b/example/README.md index 7627328b..db465b3b 100644 --- a/example/README.md +++ b/example/README.md @@ -8,5 +8,5 @@ This demo uses **bashunit** itself. You will find various tests showcasing the f To run the tests from this example, simply execute the following command from the project root folder. ```bash -./bashunit example/*_test.sh +./bashunit example ``` diff --git a/example/custom-functions_test.sh b/example/custom-functions_test.sh deleted file mode 100755 index 58faa181..00000000 --- a/example/custom-functions_test.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -function set_up_before_script() { - ROOT_DIR="$(dirname "${BASH_SOURCE[0]}")/.." - source "$ROOT_DIR/example/custom-functions.sh" -} - -function test_say_hi() { - assert_equals "Hi, Juan!" "$(say_hi "Juan")" -} diff --git a/example/custom-functions.sh b/example/custom_functions.sh similarity index 100% rename from example/custom-functions.sh rename to example/custom_functions.sh diff --git a/example/custom_functions_test.sh b/example/custom_functions_test.sh new file mode 100755 index 00000000..33097b93 --- /dev/null +++ b/example/custom_functions_test.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +function set_up() { + ROOT_DIR="$(dirname "${BASH_SOURCE[0]}")/.." + source "$ROOT_DIR/example/custom_functions.sh" +} + +function test_say_hi_Alice() { + assert_equals "Hi, Alice!" "$(say_hi "Alice")" +} + +function test_say_hi_Bob() { + assert_equals "Hi, Bob!" "$(say_hi "Bob")" +} diff --git a/example/script-logic_test.sh b/example/script-logic_test.sh deleted file mode 100755 index 7b9638e8..00000000 --- a/example/script-logic_test.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -function set_up() { - ROOT_DIR="$(dirname "${BASH_SOURCE[0]}")/.." - SCRIPT="$ROOT_DIR/example/script-logic.sh" -} - -function test_script() { - assert_equals "expected 123" "$($SCRIPT "123")" -} diff --git a/example/script-logic.sh b/example/script_logic.sh similarity index 100% rename from example/script-logic.sh rename to example/script_logic.sh diff --git a/example/script_logic_test.sh b/example/script_logic_test.sh new file mode 100755 index 00000000..32306748 --- /dev/null +++ b/example/script_logic_test.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +function set_up() { + ROOT_DIR="$(dirname "${BASH_SOURCE[0]}")/.." + SCRIPT="$ROOT_DIR/example/script_logic.sh" +} + +function test_script_123() { + assert_equals "expected 123" "$($SCRIPT "123")" +} + +function test_script_456() { + assert_equals "expected 456" "$($SCRIPT "456")" +}