Skip to content

Commit

Permalink
Merge pull request #1 from fontivan/sskeard/test-github-action
Browse files Browse the repository at this point in the history
Adjust test formatting, add test numbers, add github action
  • Loading branch information
fontivan authored Apr 21, 2024
2 parents bd802c4 + ef67b79 commit 791db80
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 35 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/makefile.yml
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
59 changes: 24 additions & 35 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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

Expand All @@ -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

Expand All @@ -107,3 +95,4 @@ function main {
}

main
exit $?

0 comments on commit 791db80

Please sign in to comment.