Skip to content

Commit

Permalink
scripts: generalize hierarchy searching function
Browse files Browse the repository at this point in the history
Parameterize it so that it works for any given file,
not just the test executable.
  • Loading branch information
matheusmoreira committed Jun 9, 2024
1 parent 19c637f commit ddebdfe
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions scripts/test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,16 @@ test-script() {
return "${code}"
}

find-executable() {
find-file-in-hierarchy() {
local test_case="${1}"
local file="${2}"

while [[ "${test_case}" != "." ]]; do

local executable="${test_case}"/executable
local entry="${test_case}"/"${file}"

if [[ -r "${executable}" && ! -x "${executable}" ]]; then
executable="$(< "${executable}")"
executable="$(type -P "${executable}")"
echo "${executable}"
if [[ -r "${entry}" && ! -x "${entry}" ]]; then
echo "${entry}"
return 0
else
test_case="$(dirname "${test_case}")"
Expand All @@ -90,6 +89,19 @@ find-executable() {
return 1
}

read-file-in-hierarchy() {
local file="$(find-file-in-hierarchy "${@}")"
if [[ "${?}" -eq 0 ]]; then
echo -E "$(< "${file}")"
else
return 1
fi
}

find-executable() {
type -P "$(read-file-in-hierarchy "${1}" executable)"
}

test-executable() {
local name="${1}"
local test="${2}"
Expand Down

0 comments on commit ddebdfe

Please sign in to comment.