From f298ca8c6e0eeedbc1c935c2fdd7b449fd120b69 Mon Sep 17 00:00:00 2001 From: Jiri Kucera Date: May 19 2022 12:43:17 +0000 Subject: Add blutils.sh library blutils.sh (Beakerlib Utilities) is a shell library for making tests that use beakerlib in a comfort way. --- diff --git a/lib/blutils.sh b/lib/blutils.sh new file mode 100644 index 0000000..f292bb5 --- /dev/null +++ b/lib/blutils.sh @@ -0,0 +1,477 @@ +# SPDX-License-Identifier: MIT +# +# library-prefix = blutils +# library-version = 1 + +__INTERNAL_blutils_LIB_NAME="blutils" +__INTERNAL_blutils_LIB_VERSION=1 + +echo -n "loading library" \ + "${__INTERNAL_blutils_LIB_NAME} v${__INTERNAL_blutils_LIB_VERSION}... " + +: <<'=cut' +=pod + +=encoding utf8 + +=head1 NAME + +blutils - C utilities + +=head1 DESCRIPTION + +Provides a set of functions for writing tests in C in a comfort way. +The library implements + + do_setup && do_run_tests + do_cleanup + +pattern, providing following features: + +=over + +=item * + +Do not run tests when setup phase has failed. + +=item * + +Provide a list-like container (test suite) to store tests to run. + +=item * + +Provide a stack-like container to store actions to run during cleanup phase. + +=item * + +Support organizing tests into functions, allow to quit one test when an error +occurs and move to the next one. + +=item * + +Provide several C idioms, like creating temporary directory, as +functions. + +=back + +=head1 USAGE + +The following snippet of code demonstrates how to use the library: + + set -o pipefail + + . /path/to/beakerlib.sh || exit 1 + . /path/to/blutils.sh || exit 1 + + + blutils_SetTestName "Library" 2 + blutils_SetTestVersion 1 + + T_CMD="greet" + T_BIN="/usr/local/bin/${T_CMD}" + T_OUT="stdout.txt" + + + function __install_greet() { + if [[ -e "${1}" ]]; then + echo "${1} exists, choose another name!" >&2 + return 1 + fi + echo -e '#!/bin/bash\n\necho "Hello, World!"' > "${1}" || return $? + chmod a+x "${1}" + } + + # Define Setup function. If it is defined, Setup function is run by + # blutils_RunTest during the setup phase + function Setup() { + # Create temporary directory and put path to it by default to TmpDir + # variable. This command also automatically registers a cleanup action that + # removes the temporary directory + blutils_MakeTmpDir || return $? + + # Enter the created temporary directory. Also register a cleanup action + # that leaves from it + blutils_PushTmpDir || return $? + + # Install a simple shell script + rlRun "__install_greet ${T_BIN}" 0 "Install ${T_BIN}" || return $? + + # Register cleanup action that removes the installed script + blutils_AtCleanup "rm -f \"${T_BIN}\"" + } + + # Test that ${T_CMD} is visible from PATH + function test_cmd_in_path() { + rlRun "command -v ${T_CMD}" 0 "Checking if ${T_CMD} exists" + } + # Add the test to the test suite + blutils_AddTest test_cmd_in_path "Test that ${T_CMD} is visible from PATH" + + # Test that ${T_CMD} prints Hello, World! + function test_hello_world() { + rlRun "${T_CMD} > ${T_OUT}" 0 "Run ${T_CMD}" || return $? + rlAssertGrep "Hello, World!" "${T_OUT}" + } + # Add the test to the test suite + blutils_AddTest test_hello_world "Test that ${T_CMD} prints Hello, World!" + + + # Run test(s) + blutils_RunTest + +=head1 ENVIRONMENT VARIABLES + +C - if set to 1, the summary produced by +C will not be printed (by default it is printed). + +=head1 FUNCTIONS + +=cut + +# Cleanup actions stack +declare -ag __INTERNAL_blutils_cleanup_actions=() +# Test suite +declare -ag __INTERNAL_blutils_tests=() +# Variable name that holds path to a temporary directory +__INTERNAL_blutils_tempdir_varname="TmpDir" + +: <<'=cut' +=pod + +=head2 blutils_SetTestName + +Set a test name. + +Usage: + + blutils_SetTestName [PREFIX] [NDIRS] + blutils_SetTestName -n NAME + +=over + +=item PREFIX + +Test name prefix (default empty). + +=item NDIRS + +Number of last directories from the path to the test included in a test name +(default 1). + +=item -n NAME + +Use I directly as a test name. + +=back + +Set the variable C representing a test name. If the value of C was +given earlier, use it instead of constructing it. + +The function comes in two forms. The first one constructs the test name from +I and the location of the test in a directory tree. The I +determines a length of the tail of the path to the test as a number of +directories included in the test name. For example, if a path to the test is + + /home/jdoe/qa/burning-stack-tests/tests/lib/blutils/basic_usage/runtest.sh + +and I is invoked as + + blutils_SetTestName Library 2 + +the value of C will be + + Library/blutils/basic_usage + +since the I is C and we wish to include 2 last directories +from the path to our test into the test name. The second form of +I sets C directly, i.e. + + blutils_SetTestName -n MyTest + +set C to C. + +=cut + +function blutils_SetTestName() { + local prefix="" + local ndirs=1 + local testdir="" + local testname="" + local lastdir="" + + if [[ "${TEST:-}" ]]; then + return + fi + + if [[ "${1:-}" = "-n" ]]; then + if [[ -z "${2:-}" ]]; then + echo "${FUNCNAME[0]}: Missing a test name after -n flag." >&2 + exit 1 + fi + TEST="$2" + return + fi + + prefix="${1:-}" + ndirs="${2:-1}" + + if [[ ! "${ndirs}" =~ ^[[:digit:]]+$ ]]; then + echo "${FUNCNAME[0]}: NDIRS argument must be a number." >&2 + exit 1 + fi + + testdir="$(cd "$(dirname "${BASH_SOURCE[1]}")" && pwd)" + while [[ ${ndirs} -gt 0 ]]; do + lastdir="${testdir##*/}" + if [[ -z "${lastdir}" ]]; then + break + fi + testname="${lastdir}${testname:+/}${testname}" + testdir="${testdir%/*}" + ndirs=$(( ndirs - 1 )) + done + testname="${prefix}${prefix:+/}${testname}" + + if [[ -z "${testname}" ]]; then + echo "${FUNCNAME[0]}: Guessed empty test name. Something went wrong." >&2 + exit 1 + fi + + TEST="${testname}" +} + +: <<'=cut' += pod + +=head2 blutils_SetTestVersion + +Set a test version. + +Usage: + + blutils_SetTestVersion [VERSION] + +=over + +=item VERSION + +A test version (default 0). + +=back + +Set C variable if it was not set already. + +=cut + +function blutils_SetTestVersion() { + TESTVERSION="${TESTVERSION:-${1:-0}}" +} + +: <<'=cut' +=pod + +=head2 blutils_MakeTmpDir + +Create a temporary directory. + +Usage: + + blutils_MakeTmpDir [VARNAME] + +=over + +=item VARNAME + +A name of variable to which a path to the created temporary directory will be +stored. If not specified, C is used. + +=back + +When a temporary directory is successfully created, a cleanup action that +removes it is automatically registered. + +=cut + +function blutils_MakeTmpDir() { + local varname="${1:-TmpDir}" + + rlRun "${varname}=\$(mktemp -d)" 0 "Create temporary directory" || return $? + blutils_AtCleanup "rm -rf \${${varname}}" + __INTERNAL_blutils_tempdir_varname="${varname}" +} + +: <<'=cut' +=pod + +=head2 blutils_PushTmpDir + +Enter the temporary directory. + +Usage: + + blutils_PushTmpDir + +Enter the temporary directory created with C. In case of +success, register cleanup action that leaves the temporary directory. + +=cut + +function blutils_PushTmpDir() { + rlRun "pushd \${${__INTERNAL_blutils_tempdir_varname}}" || return $? + blutils_AtCleanup "popd" +} + +: <<'=cut' +=pod + +=head2 blutils_AtCleanup + +Register a cleanup action. + +Usage: + + blutils_AtCleanup ACTION + +=over + +=item ACTION + +Action (command) that will be run during the cleanup phase. + +=back + +During the cleanup phase, actions are run in the reverse order as they were +registered (last registered cleanup action first). + +=cut + +function blutils_AtCleanup() { + __INTERNAL_blutils_cleanup_actions=( + "${1}" "${__INTERNAL_blutils_cleanup_actions[@]}" + ) +} + +: <<'=cut' +=pod + +=head2 blutils_AddTest + +Add a test to the test suite. + +Usage: + + blutils_AddTest TEST [DESCRIPTION] + +=over + +=item TEST + +Test (command) to be added to the test suite. I should not contain C<=> +character. + +=item DESCRIPTION + +Description of the test. If omitted, I is used. + +=back + +=cut + +function blutils_AddTest() { + __INTERNAL_blutils_tests+=( "${1}${2:+=}${2:-}" ) +} + +function __INTERNAL_blutils_DoSetup() { + local status=0 + + rlPhaseStartSetup + if [[ "$(LC_ALL=C type -t Setup)" != "function" ]]; then + rlLog "Function 'Setup' is not defined. Skipping the setup phase." + else + Setup + status=$? + fi + rlPhaseEnd + return ${status} +} + +function __INTERNAL_blutils_DoTest() { + for testspec in "${__INTERNAL_blutils_tests[@]}"; do + rlPhaseStartTest "${testspec#*=}" + eval "${testspec%%=*}" || : + rlPhaseEnd + done +} + +function __INTERNAL_blutils_DoCleanup() { + rlPhaseStartCleanup + for action in "${__INTERNAL_blutils_cleanup_actions[@]}"; do + rlRun "${action}" || : + done + rlPhaseEnd +} + +: <<'=cut' +=pod + +=head2 blutils_RunTest + +Execute tests in the test suite. + +Usage: + + blutils_RunTest + +First, run the user defined C function. C function implements the +setup phase. If setup phase succeeds, run all tests from the test suite in +order as added by C. Finally, run cleanup actions in reverse +order as registered by C. If C is set to +1, do not print a test summary report. + +=cut + +function blutils_RunTest() { + rlJournalStart + __INTERNAL_blutils_DoSetup && __INTERNAL_blutils_DoTest + __INTERNAL_blutils_DoCleanup + + [[ "${BLUTILS_NO_SUMMARY:-0}" = "1" ]] || rlJournalPrintText + rlJournalEnd +} + +: <<'=cut' +=pod + +=head1 AUTHORS + +=over + +=item * + +Jiří Kučera + +=back + +=head1 VERSION + +=over + +=item * + +1 + +=back + +=head1 LICENSE + +=over + +=item * + +MIT + +=back + +=cut + +echo "done" diff --git a/plans/basic.fmf b/plans/basic.fmf new file mode 100644 index 0000000..938e6c1 --- /dev/null +++ b/plans/basic.fmf @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: MIT +--- +summary: Plan for running all tests + +discover: + how: fmf +execute: + how: tmt diff --git a/tests/lib/blutils/basic_usage/main.fmf b/tests/lib/blutils/basic_usage/main.fmf new file mode 100644 index 0000000..deec17d --- /dev/null +++ b/tests/lib/blutils/basic_usage/main.fmf @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: MIT +--- +summary: blutils.sh basic usage test +description: | + Test a basic usage of blutils.sh library. diff --git a/tests/lib/blutils/basic_usage/runtest.sh b/tests/lib/blutils/basic_usage/runtest.sh new file mode 100755 index 0000000..c1743f6 --- /dev/null +++ b/tests/lib/blutils/basic_usage/runtest.sh @@ -0,0 +1,66 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT + +set -o pipefail + +T_HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" +T_TOPDIR="$(cd "${T_HERE}/../../../.." && pwd -P)" + +. /usr/share/beakerlib/beakerlib.sh || exit 1 +. "${T_TOPDIR}/lib/blutils.sh" || exit 1 + + +blutils_SetTestName "Library" 2 +blutils_SetTestVersion 1 + +T_CMD="greet" +T_BIN="/usr/local/bin/${T_CMD}" +T_OUT="stdout.txt" + + +function __install_greet() { + if [[ -e "${1}" ]]; then + echo "${1} exists, choose another name!" >&2 + return 1 + fi + echo -e '#!/bin/bash\n\necho "Hello, World!"' > "${1}" || return $? + chmod a+x "${1}" +} + +# Define Setup function. If it is defined, Setup function is run by +# blutils_RunTest during the setup phase +function Setup() { + # Create temporary directory and put path to it by default to TmpDir + # variable. This command also automatically registers a cleanup action that + # removes the temporary directory + blutils_MakeTmpDir || return $? + + # Enter the created temporary directory. Also register a cleanup action + # that leaves from it + blutils_PushTmpDir || return $? + + # Install a simple shell script + rlRun "__install_greet ${T_BIN}" 0 "Install ${T_BIN}" || return $? + + # Register cleanup action that removes the installed script + blutils_AtCleanup "rm -f \"${T_BIN}\"" +} + +# Test that ${T_CMD} is visible from PATH +function test_cmd_in_path() { + rlRun "command -v ${T_CMD}" 0 "Checking if ${T_CMD} exists" +} +# Add the test to the test suite +blutils_AddTest test_cmd_in_path "Test that ${T_CMD} is visible from PATH" + +# Test that ${T_CMD} prints Hello, World! +function test_hello_world() { + rlRun "${T_CMD} > ${T_OUT}" 0 "Run ${T_CMD}" || return $? + rlAssertGrep "Hello, World!" "${T_OUT}" +} +# Add the test to the test suite +blutils_AddTest test_hello_world "Test that ${T_CMD} prints Hello, World!" + + +# Run test(s) +blutils_RunTest diff --git a/tests/lib/blutils/empty/main.fmf b/tests/lib/blutils/empty/main.fmf new file mode 100644 index 0000000..4608a94 --- /dev/null +++ b/tests/lib/blutils/empty/main.fmf @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: MIT +--- +summary: blutils.sh empty test +description: | + Minimal test skeleton using blutils.sh. diff --git a/tests/lib/blutils/empty/runtest.sh b/tests/lib/blutils/empty/runtest.sh new file mode 100755 index 0000000..f60f2dd --- /dev/null +++ b/tests/lib/blutils/empty/runtest.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT + +set -o pipefail + +T_HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" +T_TOPDIR="$(cd "${T_HERE}/../../../.." && pwd -P)" + +. /usr/share/beakerlib/beakerlib.sh || exit 1 +. "${T_TOPDIR}/lib/blutils.sh" || exit 1 + + +blutils_SetTestName "Library" 2 +blutils_SetTestVersion 1 + + +blutils_RunTest diff --git a/tests/lib/blutils/main.fmf b/tests/lib/blutils/main.fmf new file mode 100644 index 0000000..bd592ce --- /dev/null +++ b/tests/lib/blutils/main.fmf @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: MIT +--- +tag: + - library + - library-blutils +tier: '0' diff --git a/tests/lib/blutils/maketmpdir_custom/main.fmf b/tests/lib/blutils/maketmpdir_custom/main.fmf new file mode 100644 index 0000000..94a94d6 --- /dev/null +++ b/tests/lib/blutils/maketmpdir_custom/main.fmf @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: MIT +--- +summary: blutils_MakeTmpDir test with user variable +description: | + Test blutils_MakeTmpDir with a user-specified variable name for a variable + that holds the path to the created temporary directory. diff --git a/tests/lib/blutils/maketmpdir_custom/runtest.sh b/tests/lib/blutils/maketmpdir_custom/runtest.sh new file mode 100755 index 0000000..d469dd3 --- /dev/null +++ b/tests/lib/blutils/maketmpdir_custom/runtest.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT + +set -o pipefail + +T_HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" +T_TOPDIR="$(cd "${T_HERE}/../../../.." && pwd -P)" + +. /usr/share/beakerlib/beakerlib.sh || exit 1 +. "${T_TOPDIR}/lib/blutils.sh" || exit 1 + + +blutils_SetTestName "Library" 2 +blutils_SetTestVersion 1 + +T_TEMPDIR="" + + +function Setup() { + blutils_AtCleanup "rlAssertNotExists \"\${T_TEMPDIR}\"" + blutils_MakeTmpDir T_TEMPDIR + blutils_PushTmpDir +} + +function test_tmpdir_exists() { + rlAssertEquals "Check whether TmpDir is unset" "${TmpDir:-}" "" + rlAssertEquals "Check whether T_TEMPDIR is our current working directory" \ + "${T_TEMPDIR}" "${PWD}" +} +blutils_AddTest test_tmpdir_exists + + +blutils_RunTest diff --git a/tests/lib/blutils/maketmpdir_default/main.fmf b/tests/lib/blutils/maketmpdir_default/main.fmf new file mode 100644 index 0000000..c66c64d --- /dev/null +++ b/tests/lib/blutils/maketmpdir_default/main.fmf @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: MIT +--- +summary: blutils_MakeTmpDir test +description: | + Test blutils_MakeTmpDir with default variable name for a variable that holds + the path to the created temporary directory. diff --git a/tests/lib/blutils/maketmpdir_default/runtest.sh b/tests/lib/blutils/maketmpdir_default/runtest.sh new file mode 100755 index 0000000..7211eb7 --- /dev/null +++ b/tests/lib/blutils/maketmpdir_default/runtest.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT + +set -o pipefail + +T_HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" +T_TOPDIR="$(cd "${T_HERE}/../../../.." && pwd -P)" + +. /usr/share/beakerlib/beakerlib.sh || exit 1 +. "${T_TOPDIR}/lib/blutils.sh" || exit 1 + + +blutils_SetTestName "Library" 2 +blutils_SetTestVersion 1 + + +function Setup() { + blutils_AtCleanup "rlAssertNotExists \"\${TmpDir}\"" + blutils_MakeTmpDir + blutils_PushTmpDir +} + +function test_tmpdir_exists() { + rlAssertEquals "Check whether TmpDir is our current working directory" \ + "${TmpDir}" "${PWD}" +} +blutils_AddTest test_tmpdir_exists + + +blutils_RunTest diff --git a/tests/lib/blutils/setters/main.fmf b/tests/lib/blutils/setters/main.fmf new file mode 100644 index 0000000..a59d2f0 --- /dev/null +++ b/tests/lib/blutils/setters/main.fmf @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: MIT +--- +summary: blutils_Set* test +description: | + Test blutils_SetTestName and blutils_SetTestVersion. diff --git a/tests/lib/blutils/setters/runtest.sh b/tests/lib/blutils/setters/runtest.sh new file mode 100755 index 0000000..f5d8962 --- /dev/null +++ b/tests/lib/blutils/setters/runtest.sh @@ -0,0 +1,199 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT + +set -o pipefail + +T_HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" +T_TOPDIR="$(cd "${T_HERE}/../../../.." && pwd -P)" + +. /usr/share/beakerlib/beakerlib.sh || exit 1 +. "${T_TOPDIR}/lib/blutils.sh" || exit 1 + + +blutils_SetTestName "Library" 2 +blutils_SetTestVersion 1 + +T_STATUS=0 +T_RESULT="result.txt" +T_OUT="stdout.txt" +T_TEST="foo" +T_PREFIX="Prefix" +T_VERSION=42 + + +function Setup() { + blutils_MakeTmpDir + blutils_PushTmpDir +} + +function __check_no_stdout() { + rlAssertEquals "Check whether ${T_OUT} is empty" "$(cat "${T_OUT}")" "" +} + +# Wrapper that ensures that ${BASH_SOURCE[1]} has expected value. In tests +# their result depends on ${BASH_SOURCE[1]} value, do not forget to pushd/popd +# since ${BASH_SOURCE[1]} holds relative path +function __do_blutils_SetTestName() { + blutils_SetTestName "$@" +} + +function test_testname_preset() { + rlRun "( + TEST=\"${T_TEST}\" + __do_blutils_SetTestName -n bar 2>&1; T_STATUS=\$? + + echo \"STATUS: \${T_STATUS}\" > \"${T_RESULT}\" + echo \"TEST: \${TEST}\" >> \"${T_RESULT}\" + ) | tee \"${T_OUT}\"" + + rlAssertGrep "^STATUS: 0$" "${T_RESULT}" + rlAssertGrep "^TEST: ${T_TEST}$" "${T_RESULT}" + __check_no_stdout +} +blutils_AddTest test_testname_preset + +function test_missing_testname() { + rlRun "( + TEST=\"\" + (__do_blutils_SetTestName -n) 2>&1; T_STATUS=\$? + + echo \"STATUS: \${T_STATUS}\" > \"${T_RESULT}\" + ) | tee \"${T_OUT}\"" + + rlAssertGrep "^STATUS: 1$" "${T_RESULT}" + rlAssertGrep \ + "^blutils_SetTestName: Missing a test name after -n flag.$" "${T_OUT}" +} +blutils_AddTest test_missing_testname + +function test_n_flag() { + rlRun "( + TEST=\"\" + __do_blutils_SetTestName -n \"${T_TEST}\" 2>&1; T_STATUS=\$? + + echo \"STATUS: \${T_STATUS}\" > \"${T_RESULT}\" + echo \"TEST: \${TEST}\" >> \"${T_RESULT}\" + ) | tee \"${T_OUT}\"" + + rlAssertGrep "^STATUS: 0$" "${T_RESULT}" + rlAssertGrep "^TEST: ${T_TEST}$" "${T_RESULT}" + __check_no_stdout +} +blutils_AddTest test_n_flag + +function test_bad_arg() { + rlRun "( + TEST=\"\" + (__do_blutils_SetTestName \"${T_PREFIX}\" foo) 2>&1; T_STATUS=\$? + + echo \"STATUS: \${T_STATUS}\" > \"${T_RESULT}\" + ) | tee \"${T_OUT}\"" + + rlAssertGrep "^STATUS: 1$" "${T_RESULT}" + rlAssertGrep \ + "^blutils_SetTestName: NDIRS argument must be a number.$" "${T_OUT}" +} +blutils_AddTest test_bad_arg + +function test_no_prefix() { + rlRun "( + TEST=\"\" + pushd \"${T_HERE}\" >/dev/null 2>&1 + __do_blutils_SetTestName 2>&1; T_STATUS=\$? + popd >/dev/null 2>&1 + + echo \"STATUS: \${T_STATUS}\" > \"${T_RESULT}\" + echo \"TEST: \${TEST}\" >> \"${T_RESULT}\" + ) | tee \"${T_OUT}\"" + + rlAssertGrep "^STATUS: 0$" "${T_RESULT}" + rlAssertGrep "^TEST: setters$" "${T_RESULT}" + __check_no_stdout +} +blutils_AddTest test_no_prefix + +function test_empty_testname() { + rlRun "( + TEST=\"\" + (__do_blutils_SetTestName \"\" 0) 2>&1; T_STATUS=\$? + + echo \"STATUS: \${T_STATUS}\" > \"${T_RESULT}\" + ) | tee \"${T_OUT}\"" + + rlAssertGrep "^STATUS: 1$" "${T_RESULT}" + rlAssertGrep \ + "^blutils_SetTestName: Guessed empty test name. Something went wrong.$" \ + "${T_OUT}" +} +blutils_AddTest test_empty_testname + +function test_prefix_only() { + rlRun "( + TEST=\"\" + __do_blutils_SetTestName \"${T_PREFIX}\" 0 2>&1; T_STATUS=\$? + + echo \"STATUS: \${T_STATUS}\" > \"${T_RESULT}\" + echo \"TEST: \${TEST}\" >> \"${T_RESULT}\" + ) | tee \"${T_OUT}\"" + + rlAssertGrep "^STATUS: 0$" "${T_RESULT}" + rlAssertGrep "^TEST: ${T_PREFIX}/$" "${T_RESULT}" + __check_no_stdout +} +blutils_AddTest test_prefix_only + +function test_constructing_testname() { + rlRun "( + TEST=\"\" + pushd \"${T_HERE}\" >/dev/null 2>&1 + __do_blutils_SetTestName \"${T_PREFIX}\" 3 2>&1; T_STATUS=\$? + popd >/dev/null 2>&1 + + echo \"STATUS: \${T_STATUS}\" > \"${T_RESULT}\" + echo \"TEST: \${TEST}\" >> \"${T_RESULT}\" + ) | tee \"${T_OUT}\"" + + rlAssertGrep "^STATUS: 0$" "${T_RESULT}" + rlAssertGrep "^TEST: ${T_PREFIX}/lib/blutils/setters$" "${T_RESULT}" + __check_no_stdout +} +blutils_AddTest test_constructing_testname + +function test_version_is_preset() { + rlRun "( + TESTVERSION=\"${T_VERSION}\" + blutils_SetTestVersion 123 + + echo \"TESTVERSION: \${TESTVERSION}\" > \"${T_RESULT}\" + )" + + rlAssertGrep "^TESTVERSION: ${T_VERSION}$" "${T_RESULT}" +} +blutils_AddTest test_version_is_preset + +function test_version_default() { + rlRun "( + TESTVERSION=\"\" + blutils_SetTestVersion + + echo \"TESTVERSION: \${TESTVERSION}\" > \"${T_RESULT}\" + )" + + rlAssertGrep "^TESTVERSION: 0$" "${T_RESULT}" +} +blutils_AddTest test_version_default + +function test_set_version() { + rlRun "( + TESTVERSION=\"\" + blutils_SetTestVersion \"${T_VERSION}\" + + echo \"TESTVERSION: \${TESTVERSION}\" > \"${T_RESULT}\" + )" + + rlAssertGrep "^TESTVERSION: ${T_VERSION}$" "${T_RESULT}" +} +blutils_AddTest test_set_version + + +blutils_RunTest diff --git a/tests/main.fmf b/tests/main.fmf new file mode 100644 index 0000000..15e750b --- /dev/null +++ b/tests/main.fmf @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: MIT +--- +contact: + - Jiří Kučera + +test: ./runtest.sh +framework: beakerlib +duration: 5m +enabled: true