diff --git a/VERSION b/VERSION index 3eefcb9..6e8bf73 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0 +0.1.0 diff --git a/auto b/project similarity index 100% rename from auto rename to project diff --git a/project.toml b/project.toml index 26024d5..0df7080 100644 --- a/project.toml +++ b/project.toml @@ -1,13 +1,13 @@ [project] -name = structured-shell -maintainer = Kyle Smith -description = ''' -Structured Shell (STSH) is a script execution framework extending the power of - BASH Shell scripting with safer programming paradigms. -''' +name = "structured-shell" +maintainer = "Kyle Smith " +# description = ''' +# Structured Shell (STSH) is a script execution framework extending the power of +# BASH Shell scripting with safer programming paradigms. +# ''' [build] -build_root = ${PROJECT_ROOT}/build +build_root = "${PROJECT_ROOT}/build" [hello_world] -greeting = Salutations +greeting = "Salutations" diff --git a/src/bin/autotask b/src/bin/autotask index 9234256..461d348 100755 --- a/src/bin/autotask +++ b/src/bin/autotask @@ -18,7 +18,7 @@ __script_parse_opts() { declare -g TASK_FILE - LOG_CONTEXT_BUILDER="autotask:${TASK_NAME}:" + # LOG_CONTEXT_BUILDER="autotask:${TASK_NAME}:" [ -n "${TASK_MAIN-}" ] || \ TASK_MAIN="${TASK_NAME}" } diff --git a/src/lib/libautoshell.exec.bash b/src/lib/libautoshell.exec.bash index 12bf787..8bd520f 100644 --- a/src/lib/libautoshell.exec.bash +++ b/src/lib/libautoshell.exec.bash @@ -28,13 +28,15 @@ export -f try # 1 and exits the current process ############################### fatal() { - local _message="${1}" - - if type log &>/dev/null; then - log FATAL "${_message}" "${FUNCNAME[1]-}" - else - echo "FATAL: ${_message}" - fi + local _message="${1-}" + + [ -n "${_message}" ] && { + if type log &>/dev/null; then + log FATAL "${_message}" "${FUNCNAME[1]-}" + else + echo "FATAL: ${_message}" + fi + } exit 1 } diff --git a/src/lib/libautoshell.toml.bash b/src/lib/libautoshell.toml.bash index 2c56c40..a7dc206 100644 --- a/src/lib/libautoshell.toml.bash +++ b/src/lib/libautoshell.toml.bash @@ -1,55 +1,49 @@ #!/usr/bin/env bash -export TOML_PREFIX="TOML" +export TOML_CONFIG_VAR="TOML_CONFIG" toml.load() { # toml_file[, toml_prefix=$TOML_PREFIX] - local \ - current_heading="default" \ - current_key \ - current_value \ - global_var_name \ - line \ toml_file="${1}" \ - toml_prefix="${2:-"${TOML_PREFIX}"}" - - while read -r line; do - case "${line}" in - \[*\]) - current_heading="$(sed -e 's/\[\(.*\)\]/\1/' <<< "${line}")" - ;; - *\ \=\ *) - current_key="$(sed -e 's/^\(.*\) = .*$/\1/' <<< "${line}")" - current_value="$(sed -e 's/^.* = \(.*\)$/\1/' <<< "${line}")" - - if [ -n "${current_value}" ]; then - global_var_name="${toml_prefix}_${current_heading/\./_}_KEY_${current_key}" - declare -gx "${global_var_name}" - local -n ref_var="${global_var_name}" - ref_var="${current_value}" - fi - ;; - esac - done < <(cat "${toml_file}"; echo) + config_var="${2:-"${TOML_CONFIG_VAR}"}" + + include "$(find_lib autoshell.toml.parser)" + + declare -gA "${config_var}" + + tomlparser.parse "${config_var}" < "${toml_file}" } export -f toml.load toml.get_value() { # toml_key, toml_section[, toml_prefix=$TOML_PREFIX] local \ toml_key="${1}" \ - toml_section="${2}" \ - toml_prefix="${3:-"${TOML_PREFIX}"}" + config_var_name="${2:-"${TOML_CONFIG_VAR}"}" - toml.map_value "${toml_key}" "${toml_section}" "${toml_prefix}" TOML_VALUE + toml.map_value "${toml_key}" TOML_VALUE "${config_var_name}" echo "${TOML_VALUE-}" } -toml.map_value() { # toml_key, toml_section[, toml_prefix=$TOML_PREFIX, dest_var=$toml_key] +toml.map_value() { # toml_key, dest_var[, config_var=$TOML_CONFIG_VAR] local \ toml_key="${1}" \ - toml_section="${2}" \ - toml_prefix="${3:-"${TOML_PREFIX}"}" \ - dest_var="${4:-${1}}" - - declare -gn "${dest_var}=${toml_prefix}_${toml_section}_KEY_${toml_key}" + dest_var_name="${2}" \ + config_var_name="${3:-"${TOML_CONFIG_VAR}"}" + local -n config_ref="${config_var_name}" + local -n var_ref="${dest_var_name}" + declare -g "${dest_var_name}" + var_ref="" + + [ -n "${config_ref[*]-}" ] || \ + return 0 + + var_ref="${config_ref["${toml_key}"]-}" + + [ -n "${var_ref-}" ] || { + [ "$(type -t map.keys)" = "function" ] || \ + include "$(find_lib map)" + declare -ga "${dest_var_name}=()" + while read -r key; do var_ref+=("${config_ref[${key}]}"); done < \ + <( map.keys config_ref | grep "${toml_key}\[[0-9]*\]" | sort ) + } } -export -f toml.map_value +export -f toml.map_value \ No newline at end of file diff --git a/src/lib/libautoshell.toml.parser.bash b/src/lib/libautoshell.toml.parser.bash new file mode 100644 index 0000000..0bf3ed8 --- /dev/null +++ b/src/lib/libautoshell.toml.parser.bash @@ -0,0 +1,217 @@ +#!/usr/bin/env bash + +tomlparser.parse() { # config_var <<< TOML Data + declare -g \ + heading="" \ + key="" \ + value="" \ + quote="" \ + array_index="" \ + line_index="1" \ + mode="key" \ + line char + declare -gn ref=key + declare -gn config="${1}" + + while read -r line; do + tomlparser.parse_line "${line}" + line_index=$(( line_index + 1 )) + done +} + +tomlparser.parse_line() { + local \ + line="${1}" \ + last_char="" \ + char_index=0 + + while read -rN1 char; do + tomlparser.parse_char "${char_index}" "${char-}" "${last_char-}" + char_index=$(( char_index + 1 )) + last_char="${char-}" + done <<< "${line}" + case "${mode}" in + array) + ;; + *) + tomlparser.flush_key + mode=key + ;; + esac +} + +tomlparser.parse_char() { + local \ + char_index="${1}" \ + char="${2:- }" \ + last_char="${3:- }" + + [ "${char}" = $'\n' ] && return 0 + + case "${mode}" in + key) + if [ -n "${quote-}" ]; then + tomlparser.parse_char^quote key "${char}" + else + tomlparser.parse_char^key "${char}" + fi + ;; + heading) + if [ -n "${quote-}" ]; then + tomlparser.parse_char^quote heading "${char}" + else + tomlparser.parse_char^heading "${char}" + fi + ;; + value) + if [ -n "${quote-}" ]; then + tomlparser.parse_char^quote value "${char}" + else + tomlparser.parse_char^value "${char}" + fi + ;; + array) + [ -n "${array_index-}" ] || array_index=0 + if [ -n "${quote-}" ]; then + tomlparser.parse_char^quote value "${char}" + else + tomlparser.parse_char^array "${char}" + fi + ;; + line_return) + tomlparser.parse_char^line_return "${char}" + ;; + comment) + ;; + esac +} + +tomlparser.parse_char^quote() { + local -n ref="${1}" + local char="${2}" + + case "${char}" in + "${quote}") + quote="" + ;; + $''|$' ') + ref+=" " + ;; + *) + ref+="${char}" + ;; + esac +} + +tomlparser.parse_char^key() { + case "${1}" in + $'[') + heading="" + mode=heading + ;; + $'=') + mode=value + ;; + $'"') + quote="${char}" + ;; + $'#') + mode=comment + ;; + $' ') + ;; + *) + [ "${last_char}" = " " ] && [ "${char_index}" -gt 0 ] && \ + tomlparser.parse_error "Unexpected char: ${char}: Unquoted keys cannot have spaces" + key+="${char}" + ;; + esac +} + +tomlparser.parse_char^heading() { + case "${1}" in + $']') + mode=line_return + ;; + $'"') + quote="${char}" + ;; + $' ') + ;; + *) + heading+="${char}" + ;; + esac +} + +tomlparser.parse_char^value() { + case "${1}" in + $'[') + mode=array + ;; + $'"') + quote="${char}" + ;; + $' ') + ;; + $'#') + mode=comment + ;; + *) + tomlparser.parse_error "Unquoted string" + ;; + esac +} + +tomlparser.parse_char^array() { + case "${1}" in + $']') + tomlparser.flush_key + mode=line_return + ;; + $',') + tomlparser.flush_value + array_index=$(( array_index + 1 )) + ;; + $'"') + quote="${char}" + ;; + $' ') + ;; + *) + tomlparser.parse_error "Unquoted string" + ;; + esac +} + +tomlparser.parse_char^line_return() { + case "${1}" in + $' ') + ;; + $'#') + mode[-1]="comment" + ;; + *) + tomlparser.parse_error "Unexpected symbol: ${char}" + ;; + esac +} + +tomlparser.flush_value() { + [ -n "${key}" ] && [ -n "${value}" ] && { + local config_key="${heading:+.${heading}}.${key}${array_index:+[${array_index}]}" + local config_value="$(envsubst <<< "${value}")" + config["${config_key}"]="${config_value}" + } + value="" +} + +tomlparser.flush_key() { + tomlparser.flush_value + key="" +} + +tomlparser.parse_error() { + log FATAL "${1}" "tomlparser: line ${line_index}, char ${char_index}" + fatal +} \ No newline at end of file diff --git a/src/lib/libautotask.config.bash b/src/lib/libautotask.config.bash index f0afa97..eda5746 100644 --- a/src/lib/libautotask.config.bash +++ b/src/lib/libautotask.config.bash @@ -1,8 +1,8 @@ #!/usr/bin/env bash export \ - TASK_CONFIG_PREFIX="TASK_CONFIG" \ - TASK_USER_CONFIG_PREFIX="TASK_USER_CONFIG" + TASK_CONFIG_VAR="TASK_CONFIG" \ + TASK_USER_CONFIG_VAR="TASK_USER_CONFIG" task.load_config() { local \ task_name="${1}" \ @@ -12,12 +12,12 @@ task.load_config() { IFS="." [ "${task_name}" = "${TASK_MAIN-}" ] && [ -f "./project.toml" ] && \ - toml.load "./project.toml" "${TASK_USER_CONFIG_PREFIX}" + toml.load "./project.toml" "${TASK_USER_CONFIG_VAR}" for task_part in ${task_name}; do task="${task:+${task}.}${task_part}" if toml_file="$(task.find_file "${task}" toml)"; then - toml.load "${toml_file}" "${TASK_CONFIG_PREFIX}" + toml.load "${toml_file}" "${TASK_CONFIG_VAR}" fi done } @@ -30,23 +30,21 @@ task.get_config() { # key_name[, task_name=$TASK_NAME] export "${key_name}" local -n key_ref="${key_name}" - task.get_config^try_prefix "${TASK_USER_CONFIG_PREFIX}" + task.get_config^try_prefix "${TASK_USER_CONFIG_VAR}" [ -n "${key_ref-}" ] || \ - task.get_config^try_prefix "${TASK_CONFIG_PREFIX}" + task.get_config^try_prefix "${TASK_CONFIG_VAR}" } task.get_config^try_prefix() { local \ - toml_prefix="${1}" \ - toml_section="" \ + config_var="${1}" \ + toml_key="" \ task_part \ IFS="." - local -a toml_config=() for task_part in ${task_name}; do - toml_section="${toml_section:+${toml_section}_}${task_part}" - toml_config=("${key_name}" "${toml_section}" "${toml_prefix}") - if [ -n "$(toml.get_value "${toml_config[@]}")" ]; then - toml.map_value "${toml_config[@]}" + toml_key="${toml_key-}.${task_part}" + if [ -n "$(toml.get_value "${toml_key}.${key_name}" "${config_var}")" ]; then + toml.map_value "${toml_key}.${key_name}" "${key_name}" "${config_var}" fi done } diff --git a/src/lib/libmap.bash b/src/lib/libmap.bash new file mode 100644 index 0000000..7c1413a --- /dev/null +++ b/src/lib/libmap.bash @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +map.keys() { + local -n array="${1}" + local key + for key in "${!array[@]}"; do + echo "${key}" + done +} +export -f map.keys \ No newline at end of file diff --git a/tasks/hello_world/hello_world.toml b/tasks/hello_world/hello_world.toml index 515a3ee..4875e63 100644 --- a/tasks/hello_world/hello_world.toml +++ b/tasks/hello_world/hello_world.toml @@ -1,2 +1,2 @@ [hello_world] -greeting = Hello +greeting = "Hello" diff --git a/tasks/package/package.bash b/tasks/package/package.bash new file mode 100644 index 0000000..f4c8ee1 --- /dev/null +++ b/tasks/package/package.bash @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +task.dependencies() { + depends_on "package.stage" +} + +task.exec() { + local archive dir + + task.get_config archive + task.get_config dir package.stage + + log INFO "Creating archive: ${archive}" + mkdir -p "$(dirname "${archive}")" + tar -czf "${archive}" -C "${dir}" ./ +} \ No newline at end of file diff --git a/tasks/package/package.toml b/tasks/package/package.toml new file mode 100644 index 0000000..ca63917 --- /dev/null +++ b/tasks/package/package.toml @@ -0,0 +1,8 @@ +[package] +archive = "${PROJECT_ROOT}/build/autoshell.tar.gz" +stage.dir = "${PROJECT_ROOT}/build/stage" +stage.files = [ + "${PROJECT_ROOT}/src/lib:lib/autoshell", + "${PROJECT_ROOT}/src/bin:bin", + "${PROJECT_ROOT}/tasks:share/autoshell/tasks" +] diff --git a/tasks/package/stage.bash b/tasks/package/stage.bash new file mode 100644 index 0000000..043cabd --- /dev/null +++ b/tasks/package/stage.bash @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +task.exec() { + local dir + local -a files + + task.get_config dir + task.get_config files + + log INFO "Creating staging directory: ${dir}" + rm -rf "${dir}" + mkdir -p "${dir}" + + log INFO "Copying files:" + cd "${dir}" || \ + fatal "Could not enter staging directory" + for cp_expr in "${files[@]}"; do + [ -n "${cp_expr}" ] || \ + continue + + log INFO " - ${cp_expr}" + local IFS=":" + local -a cp_files=(${cp_expr}) + [ "${#cp_files[@]}" -gt 1 ] || \ + fatal "stage.files: ${cp_expr}: destination not specified" + + mkdir -p "$(dirname "${cp_files[-1]}")" + cp -r "${cp_files[@]}" + done +} \ No newline at end of file diff --git a/test/bin/test_autotask.bats b/test/bin/test_autotask.bats index 0258a0e..7dc57cf 100644 --- a/test/bin/test_autotask.bats +++ b/test/bin/test_autotask.bats @@ -332,7 +332,7 @@ EOT cat <"$(build_task.config "${task_name}")" [task1] -test_value = ${expected_task_output} +test_value = "${expected_task_output}" EOC run "${AUTOTASK}" "${task_name}" @@ -358,18 +358,19 @@ EOT cat <"$(build_task.config "${task_name}")" [task1] -test_value = default_value +test_value = "default_value" EOC cat < "./project.toml" [task1] -test_value = ${expected_task_output} +test_value = "${expected_task_output}" EOC - run -0 "${AUTOTASK}" "${task_name}" + run "${AUTOTASK}" "${task_name}" echo "${output}" + [ "${status}" -eq 0 ] [ "${output}" = "${expected_task_output}" ] } @@ -390,7 +391,7 @@ EOT cat <"$(build_task.config "${parent_task_name}")" [task1] -test_value = ${expected_task_output} +test_value = "${expected_task_output}" EOC run -0 "${AUTOTASK}" "${child_task_name}" diff --git a/test/lib/test_libautoshell.toml.bats b/test/lib/test_libautoshell.toml.bats index d035a4e..80f4dac 100644 --- a/test/lib/test_libautoshell.toml.bats +++ b/test/lib/test_libautoshell.toml.bats @@ -8,25 +8,25 @@ source "src/lib/libautoshell.toml.bash" expected_value="${RANDOM}" cat <"${toml_file}" [heading1] -key1 = ${expected_value} +key1 = "${expected_value}" EOC toml.load "${toml_file}" - [ "${TOML_heading1_KEY_key1}" = "${expected_value}" ] + [ "${TOML_CONFIG[.heading1.key1]}" = "${expected_value}" ] } -@test "toml.load: can override variable prefix values are loaded into" { +@test "toml.load: can override config variable values are loaded into" { toml_file="${BATS_TEST_TMPDIR}/config.toml" expected_value="${RANDOM}" cat <"${toml_file}" [heading1] -key1 = ${expected_value} +key1 = "${expected_value}" EOC - toml.load "${toml_file}" "MY_PREFIX" + toml.load "${toml_file}" "MY_CONFIG" - [ "${MY_PREFIX_heading1_KEY_key1}" = "${expected_value}" ] + [ "${MY_CONFIG[.heading1.key1]}" = "${expected_value}" ] } @test "toml.get_value: echos loaded toml environment variable value for the header and key" { @@ -34,12 +34,12 @@ EOC expected_value="${RANDOM}" cat <"${toml_file}" [heading1] -key1 = ${expected_value} +key1 = "${expected_value}" EOC toml.load "${toml_file}" - [ "$(toml.get_value "key1" "heading1")" = "${expected_value}" ] + [ "$(toml.get_value ".heading1.key1")" = "${expected_value}" ] } @test "toml.map_value: references loaded toml environment variable to variable named toml_key" { @@ -47,12 +47,44 @@ EOC expected_value="${RANDOM}" cat <"${toml_file}" [heading1] -key1 = ${expected_value} +key1 = "${expected_value}" EOC toml.load "${toml_file}" - toml.map_value "key1" "heading1" + toml.map_value ".heading1.key1" "key1" [ "${key1}" = "${expected_value}" ] +} + +@test "toml.map_value: gracefully handles the config variable being unset, clearing stored values" { + my_var="stale" + + toml.map_value ".doop" "my_var" "UNDEFINED_CONFIG_VAR" + + log INFO "my_var: ${my_var}" + + [ -z "${my_var-}" ] +} + +@test "toml.map_value: maps array keys to array variables" { + toml_file="${BATS_TEST_TMPDIR}/config.toml" + expected_value1="${RANDOM}" + expected_value2="${RANDOM}" + cat <"${toml_file}" +[heading1] +key1 = [ "${expected_value1}", "${expected_value2}" ] +EOC + + toml.load "${toml_file}" + + toml.map_value ".heading1.key1" "key1" + + echo "expected: [ ${expected_value1} ${expected_value2} ]" + echo "key1[${#key1[@]}]: [ ${key1[*]} ]" + + [ "${#key1[@]}" -eq 2 ] + + [ "${key1[0]}" = "${expected_value1}" ] + [ "${key1[1]}" = "${expected_value2}" ] } \ No newline at end of file diff --git a/test/lib/test_libautoshell.toml.parser.bats b/test/lib/test_libautoshell.toml.parser.bats new file mode 100644 index 0000000..6f93748 --- /dev/null +++ b/test/lib/test_libautoshell.toml.parser.bats @@ -0,0 +1,125 @@ +#!/usr/bin/env bats + +bats_require_minimum_version "1.5.0" + +source "src/lib/libautoshell.bash" +include "$(find_lib autoshell.toml.parser)" + +setup() { + declare -Ag TEST_CONFIG + cd "${BATS_TEST_TMPDIR}" +} + +@test "tomlparser.parse: parses double quoted string values" { + toml_key="key1" + toml_value="space separated value" + toml_file="./test.toml" + cat <"${toml_file}" +${toml_key}="${toml_value}" +TOML + + tomlparser.parse TEST_CONFIG < "${toml_file}" + + echo "${TEST_CONFIG[.${toml_key}]}" + [ "${TEST_CONFIG[.${toml_key}]}" = "${toml_value}" ] +} + +@test "tomlparser.parse: parses multiple values from the file" { + toml_key1="key1" + toml_key2="key2" + toml_value1="value1" + toml_value2="value2" + toml_file="./test.toml" + cat <"${toml_file}" +${toml_key1}="${toml_value1}" +${toml_key2}="${toml_value2}" +TOML + + tomlparser.parse TEST_CONFIG < "${toml_file}" + + [ "${TEST_CONFIG[.${toml_key1}]}" = "${toml_value1}" ] + [ "${TEST_CONFIG[.${toml_key2}]}" = "${toml_value2}" ] +} + +@test "tomlparser.parse: prepends table headers onto key names" { + toml_heading="heading1" + toml_key="key1" + toml_value="${RANDOM}" + toml_file="./test.toml" + cat <"${toml_file}" +[${toml_heading}] +${toml_key}="${toml_value}" +TOML + + tomlparser.parse TEST_CONFIG < "${toml_file}" + + echo "${TEST_CONFIG[.${toml_heading}.${toml_key}]}" + [ "${TEST_CONFIG[.${toml_heading}.${toml_key}]}" = "${toml_value}" ] +} + +@test "tomlparser.parse: parses array values into multiple, enumerated CONFIG entries" { + toml_heading="heading1" + toml_key="key1" + toml_value1="${RANDOM}" + toml_value2="${RANDOM}" + toml_file="./test.toml" + cat <"${toml_file}" +[${toml_heading}] +${toml_key} = [ "${toml_value1}", "${toml_value2}" ] +TOML + + tomlparser.parse TEST_CONFIG < "${toml_file}" + + [ "${TEST_CONFIG[.${toml_heading}.${toml_key}[0]]}" = "${toml_value1}" ] + [ "${TEST_CONFIG[.${toml_heading}.${toml_key}[1]]}" = "${toml_value2}" ] +} + +@test "tomlparser.parse: parses arrays expressed over multiple lines" { + toml_heading="heading1" + toml_key="key1" + toml_value1="${RANDOM}" + toml_value2="${RANDOM}" + toml_file="./test.toml" + cat <"${toml_file}" +[${toml_heading}] +${toml_key} = [ + "${toml_value1}", + "${toml_value2}" +] +TOML + + tomlparser.parse TEST_CONFIG < "${toml_file}" + + [ "${TEST_CONFIG[.${toml_heading}.${toml_key}[0]]}" = "${toml_value1}" ] + [ "${TEST_CONFIG[.${toml_heading}.${toml_key}[1]]}" = "${toml_value2}" ] +} + +@test "tomlparser.parse: substitutes valid variable expressions with their values" { + toml_heading="heading1" + toml_key="key1" + expected_value="${RANDOM}" + toml_file="./test.toml" + cat <"${toml_file}" +[${toml_heading}] +${toml_key}="\${ENV_VAR}" +TOML + export ENV_VAR="${expected_value}" + + tomlparser.parse TEST_CONFIG < "${toml_file}" + + echo "${TEST_CONFIG[.${toml_heading}.${toml_key}]}" + [ "${TEST_CONFIG[.${toml_heading}.${toml_key}]}" = "${expected_value}" ] +} + +@test "tomlparser.parse: treats unquoted values as an error" { + toml_file="./test.toml" + cat <"${toml_file}" +key1=value1 +TOML + + run ! tomlparser.parse TEST_CONFIG < "${toml_file}" + + echo "output: ${output}" + + [ "${output}" = "[FATAL] tomlparser: line 1, char 5: Unquoted string" ] +} \ No newline at end of file diff --git a/test/lib/test_libautotask.config.bats b/test/lib/test_libautotask.config.bats index e8887ca..373312a 100644 --- a/test/lib/test_libautotask.config.bats +++ b/test/lib/test_libautotask.config.bats @@ -25,15 +25,16 @@ build_config() { task_name="task1" task_config_key="key1" expected_value="${RANDOM}" + loaded_config_key=".${task_name}.${task_config_key}" cat <"$(build_config "${task_name}")" [${task_name}] -${task_config_key} = ${expected_value} +${task_config_key} = "${expected_value}" EOC task.load_config "${task_name}" - [ "$(toml.get_value "${task_config_key}" "${task_name}" "${TASK_CONFIG_PREFIX}")" = "${expected_value}" ] + [ "$(toml.get_value "${loaded_config_key}" "${TASK_CONFIG_VAR}")" = "${expected_value}" ] } @test "task.load_config: also loads parent config when present" { @@ -41,31 +42,33 @@ EOC task_name="${parent_task_name}.task1" task_config_key="key1" expected_value="${RANDOM}" + loaded_config_key=".${parent_task_name}.${task_config_key}" cat <"$(build_config "${parent_task_name}")" [${parent_task_name}] -${task_config_key} = ${expected_value} +${task_config_key} = "${expected_value}" EOC task.load_config "${task_name}" - [ "$(toml.get_value "${task_config_key}" "${parent_task_name}" "${TASK_CONFIG_PREFIX}")" = "${expected_value}" ] + [ "$(toml.get_value "${loaded_config_key}" "${TASK_CONFIG_VAR}")" = "${expected_value}" ] } -@test "task.load_config: loads user config into TASK_USER_CONFIG_PREFIX" { +@test "task.load_config: loads user config into TASK_USER_CONFIG_VAR" { task_name="task1" TASK_MAIN="${task_name}" task_config_key="key1" expected_value="${RANDOM}" + loaded_config_key=".${task_name}.${task_config_key}" cat <"./project.toml" [${task_name}] -${task_config_key} = ${expected_value} +${task_config_key} = "${expected_value}" EOC task.load_config "${task_name}" - [ "$(toml.get_value "${task_config_key}" "${task_name}" "${TASK_USER_CONFIG_PREFIX}")" = "${expected_value}" ] + [ "$(toml.get_value "${loaded_config_key}" "${TASK_USER_CONFIG_VAR}")" = "${expected_value}" ] } @test "task.load_config: does not load user config when not running as main task" { @@ -80,7 +83,7 @@ EOC task.load_config "${task_name}" - [ -z "$(toml.get_value "${task_config_key}" "${task_name}" "${TASK_USER_CONFIG_PREFIX}")" ] + [ -z "$(toml.get_value "${task_config_key}" "${task_name}" "${TASK_USER_CONFIG_VAR}")" ] } @test "task.get_config: copies the TOML loaded config value into the key name variable" { @@ -90,7 +93,7 @@ EOC cat <"$(build_config "${task_name}")" [${task_name}] -${task_config_key} = ${expected_value} +${task_config_key} = "${expected_value}" EOC task.load_config "${task_name}" @@ -109,7 +112,7 @@ EOC cat <"$(build_config "${TASK_NAME}")" [${TASK_NAME}] -${task_config_key} = ${expected_value} +${task_config_key} = "${expected_value}" EOC task.load_config "${TASK_NAME}" @@ -129,7 +132,7 @@ EOC cat <"$(build_config "${parent_task}")" [${parent_task}] -${task_config_key} = ${expected_value} +${task_config_key} = "${expected_value}" EOC task.load_config "${TASK_NAME}" @@ -150,11 +153,11 @@ EOC cat <"$(build_config "${TASK_NAME}")" [${TASK_NAME}] -${task_config_key} = default +${task_config_key} = "default" EOC cat <"./project.toml" [${task_parent_name}] -${task_config_key} = ${expected_value} +${task_config_key} = "${expected_value}" EOC task.load_config "${TASK_NAME}"