From ef67b79c8a20feb018f281dd102d198edf467ed9 Mon Sep 17 00:00:00 2001 From: Steven Skeard Date: Sun, 21 Apr 2024 01:42:45 -0400 Subject: [PATCH] Adjust test formatting, add test numbers, add github action --- .github/workflows/makefile.yml | 18 ++++++ .../input.txt} | 0 .../output.txt} | 0 .../input.txt} | 0 .../output.txt} | 0 test/test.sh | 59 ++++++++----------- 6 files changed, 42 insertions(+), 35 deletions(-) create mode 100644 .github/workflows/makefile.yml rename test/{test-with-config-input.txt => 01-with-config/input.txt} (100%) rename test/{test-with-config-output.txt => 01-with-config/output.txt} (100%) rename test/{test-without-config-input.txt => 02-without-config/input.txt} (100%) rename test/{test-without-config-output.txt => 02-without-config/output.txt} (100%) diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml new file mode 100644 index 0000000..3350abb --- /dev/null +++ b/.github/workflows/makefile.yml @@ -0,0 +1,18 @@ +name: Makefile CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Run make all + run: make all diff --git a/test/test-with-config-input.txt b/test/01-with-config/input.txt similarity index 100% rename from test/test-with-config-input.txt rename to test/01-with-config/input.txt diff --git a/test/test-with-config-output.txt b/test/01-with-config/output.txt similarity index 100% rename from test/test-with-config-output.txt rename to test/01-with-config/output.txt diff --git a/test/test-without-config-input.txt b/test/02-without-config/input.txt similarity index 100% rename from test/test-without-config-input.txt rename to test/02-without-config/input.txt diff --git a/test/test-without-config-output.txt b/test/02-without-config/output.txt similarity index 100% rename from test/test-without-config-output.txt rename to test/02-without-config/output.txt diff --git a/test/test.sh b/test/test.sh index 0409aa7..6995114 100755 --- a/test/test.sh +++ b/test/test.sh @@ -4,18 +4,22 @@ set -eou pipefail SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) SANITIZE_BIN_PATH="${SCRIPT_DIR}/../src/bin/sanitize" -INPUT="input.txt" -OUTPUT="output.txt" SEPARATOR="----------------------------------------------------------" -function check_test_result { +function run_test { local test_name - local actual_result - local expected_result + local config_path test_name=$1 - actual_result=$2 - expected_result=$3 + config_path=$2 + + export SANITIZE_CONFIG_DIR="${config_path}" + + local actual_result + local expected_result + actual_result=$("${SANITIZE_BIN_PATH}" < \ + "${SCRIPT_DIR}/${test_name}/input.txt" ) + expected_result=$(cat "${SCRIPT_DIR}/${test_name}/output.txt") if ! [[ "${actual_result}" == "${expected_result}" ]]; then echo "${SEPARATOR}" @@ -40,44 +44,28 @@ function check_test_result { return 0 } -function test_with_config { +function test_01_with_config { local test_name - test_name="test-with-config" + local config_path - export SANITIZE_CONFIG_DIR="${SCRIPT_DIR}/../src/etc" + test_name="01-with-config" + config_path="${SCRIPT_DIR}/../src/etc" - local actual_result - local expected_result - actual_result=$("${SANITIZE_BIN_PATH}" < \ - "${SCRIPT_DIR}/${test_name}-${INPUT}" ) - expected_result=$(cat "${SCRIPT_DIR}/${test_name}-${OUTPUT}") - - if ! check_test_result \ - "${test_name}" \ - "${actual_result}" \ - "${expected_result}"; then + if ! run_test "${test_name}" "${config_path}"; then return 1 fi return 0 } -function test_without_config { +function test_02_without_config { local test_name - test_name="test-without-config" - - export SANITIZE_CONFIG_DIR="${SCRIPT_DIR}" + local config_path - local actual_result - local expected_result - actual_result=$("${SANITIZE_BIN_PATH}" < \ - "${SCRIPT_DIR}/${test_name}-${INPUT}" ) - expected_result=$(cat "${SCRIPT_DIR}/${test_name}-${OUTPUT}") + test_name="02-without-config" + config_path="${SCRIPT_DIR}" - if ! check_test_result \ - "${test_name}" \ - "${actual_result}" \ - "${expected_result}"; then + if ! run_test "${test_name}" "${config_path}"; then return 1 fi @@ -93,10 +81,10 @@ function main { local result result=0 - if ! test_with_config; then + if ! test_01_with_config; then result=1 fi - if ! test_without_config; then + if ! test_02_without_config; then result=1 fi @@ -107,3 +95,4 @@ function main { } main +exit $?