From 5f282114b97ce8bdcb4cba65a6c7d4724b2b7a28 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 17 Mar 2026 11:13:28 -0500 Subject: [PATCH 1/3] refactor: extract output funcs to shared lib Move output/display helper functions into a dedicated lib/output_funcs.sh with a standardized interface (output_section, output_line, output_warning, output_stderr, output_indent). --- bin/compile | 1 + lib/misc_funcs.sh | 34 --------------------------- lib/output_funcs.sh | 56 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 34 deletions(-) create mode 100644 lib/output_funcs.sh diff --git a/bin/compile b/bin/compile index 23c4311..44fd555 100755 --- a/bin/compile +++ b/bin/compile @@ -18,6 +18,7 @@ cache_path=$(cd $2 && pwd) env_path=$(cd $3 && pwd) +source ${build_pack_path}/lib/output_funcs.sh source ${build_pack_path}/lib/path_funcs.sh source ${build_pack_path}/lib/misc_funcs.sh source ${build_pack_path}/lib/erlang_funcs.sh diff --git a/lib/misc_funcs.sh b/lib/misc_funcs.sh index 73a08bf..e10a569 100644 --- a/lib/misc_funcs.sh +++ b/lib/misc_funcs.sh @@ -1,37 +1,3 @@ -# Outputs log line -# -# Usage: -# -# output_line "Cloning repository" -# -function output_line() { - local spacing=" " - echo "${spacing} $1" -} - -# Outputs section heading -# -# Usage: -# -# output_section "Application tasks" -# -function output_section() { - local indentation="----->" - echo "${indentation} $1" -} - -function output_warning() { - local spacing=" " - echo -e "${spacing} \e[31m$1\e[0m" -} - -function output_stderr() { - # Outputs to stderr in case it is inside a function so it does not - # disturb the return value. Useful for debugging. - echo "$@" 1>&2; -} - - function assert_elixir_version_set() { custom_config_file=$1 diff --git a/lib/output_funcs.sh b/lib/output_funcs.sh new file mode 100644 index 0000000..308e7d5 --- /dev/null +++ b/lib/output_funcs.sh @@ -0,0 +1,56 @@ +# Outputs section heading +# +# Usage: +# +# output_section "Application tasks" +# +output_section() { + local indentation="----->" + echo "${indentation} $1" +} + +# Outputs log line +# +# Usage: +# +# output_line "Cloning repository" +# +output_line() { + local spacing=" " + echo "${spacing} $1" +} + +# Outputs a warning in red +# +# Usage: +# +# output_warning "Something went wrong" +# +output_warning() { + local spacing=" " + echo -e "${spacing} \e[31m$1\e[0m" +} + +# Outputs to stderr for debugging +# +# Usage: +# +# output_stderr "Debug info" +# +output_stderr() { + # Outputs to stderr in case it is inside a function so it does not + # disturb the return value. Useful for debugging. + echo "$@" 1>&2; +} + +# Pipe processor for indenting command output +# +# Usage: +# +# command | output_indent +# +output_indent() { + while read LINE; do + echo " $LINE" || true + done +} From 2cbcb64ed492752ea68c4432dbc4f8bf17db45f5 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 17 Mar 2026 19:36:58 -0500 Subject: [PATCH 2/3] fix: update test stubs for output_funcs --- test/.test_support.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/test/.test_support.sh b/test/.test_support.sh index 4ed2bb2..77a9f05 100644 --- a/test/.test_support.sh +++ b/test/.test_support.sh @@ -25,10 +25,22 @@ cache_path=${TEST_DIR}/cache_path mkdir -p ${build_path} ${cache_path} -# overridden functions -info() { +# stub output functions to suppress noise in tests +output_section() { true } +output_line() { + true +} +output_warning() { + true +} +output_stderr() { + true +} +output_indent() { + cat > /dev/null +} # helper functions test() { From d19b3c37dc214506593a86d489f5b5661a64a09c Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 17 Mar 2026 21:49:04 -0500 Subject: [PATCH 3/3] refactor: commonize test framework and add Makefile --- .github/workflows/ci.yml | 3 +- Makefile | 7 +++++ test/.test_support.sh | 53 ++--------------------------------- test/test_framework.sh | 60 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 53 deletions(-) create mode 100644 Makefile create mode 100644 test/test_framework.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0369d9d..c0899f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,5 +13,4 @@ jobs: - uses: actions/checkout@v3 - name: run tests - run: | - for tst in test/*.sh; do $tst; done + run: make test diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..19985d2 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +.PHONY: test + +test: + @set -e; for tst in test/*.sh; do \ + [ -x "$$tst" ] || continue; \ + "$$tst"; \ + done diff --git a/test/.test_support.sh b/test/.test_support.sh index 77a9f05..3b52ca2 100644 --- a/test/.test_support.sh +++ b/test/.test_support.sh @@ -1,64 +1,15 @@ #!/usr/bin/env bash +REPO_NAME="gigalixir-buildpack-elixir" +source "$(dirname "${BASH_SOURCE[0]}")/test_framework.sh" -ROOT_DIR=$(dirname "$SCRIPT_DIR") -PASSED_ALL_TESTS=false build_pack_path=$ROOT_DIR -# make a temp dir for test files/directories -TEST_DIR=$(mktemp -d -t gigalixir-buildpack-phoenix-static_XXXXXXXXXX) -ECHO_CONTENT=() -cleanup() { - rm -rf ${TEST_DIR} - if $PASSED_ALL_TESTS; then - /bin/echo -e " \e[0;32mTest Suite PASSED\e[0m" - else - /bin/echo -e " \e[0;31mFAILED\e[0m" - fi - exit -} -trap cleanup EXIT INT TERM - # create directories for test build_path=${TEST_DIR}/build_path cache_path=${TEST_DIR}/cache_path mkdir -p ${build_path} ${cache_path} - -# stub output functions to suppress noise in tests -output_section() { - true -} -output_line() { - true -} -output_warning() { - true -} -output_stderr() { - true -} -output_indent() { - cat > /dev/null -} - -# helper functions -test() { - reset_test - failed=false - ECHO_CONTENT=() - /bin/echo " TEST: $@" -} - exit() { failed=true } - -suite() { - failed=false - /bin/echo -e "\e[0;36mSUITE: $@\e[0m" -} - -reset_test() { - true -} diff --git a/test/test_framework.sh b/test/test_framework.sh new file mode 100644 index 0000000..5b613b2 --- /dev/null +++ b/test/test_framework.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash +# +# Shared test framework for gigalixir buildpack repos. +# +# Prerequisites (must be set before sourcing): +# SCRIPT_DIR - absolute path to the test/ directory +# REPO_NAME - name used in the mktemp template +# + +ROOT_DIR=$(dirname "$SCRIPT_DIR") +PASSED_ALL_TESTS=false +ECHO_CONTENT=() + +# make a temp dir for test files/directories +TEST_DIR=$(mktemp -d -t "${REPO_NAME}_XXXXXXXXXX") + +cleanup() { + rm -rf ${TEST_DIR} + if $PASSED_ALL_TESTS; then + /bin/echo -e " \e[0;32mTest Suite PASSED\e[0m" + else + /bin/echo -e " \e[0;31mFAILED\e[0m" + fi + exit +} +trap cleanup EXIT INT TERM + +# stub output functions to suppress noise in tests +output_section() { + true +} +output_line() { + true +} +output_warning() { + true +} +output_stderr() { + true +} +output_indent() { + cat > /dev/null +} + +# helper functions +test() { + reset_test + failed=false + ECHO_CONTENT=() + /bin/echo " TEST: $@" +} + +suite() { + failed=false + /bin/echo -e "\e[0;36mSUITE: $@\e[0m" +} + +reset_test() { + true +}