diff --git a/scripts/go_test_with_coverage_report b/scripts/go_test_with_coverage_report index 85707751a1fb4d223d0c95f41e541c29bd0f861e..4d3c4b18f6c61fc9d47403ed1146adef7c7da71d 100755 --- a/scripts/go_test_with_coverage_report +++ b/scripts/go_test_with_coverage_report @@ -37,8 +37,7 @@ prepareTestCommands() { local testIndex=0 local runTests=() - local tests - tests=$(go test -list "Test.*" "${pkg}" | grep "^Test" || echo "") + local tests=$(go test -list "Test.*" "${pkg}" | grep "^Test" || echo "") if [[ -z "${tests}" ]]; then continue @@ -76,8 +75,7 @@ executeTestCommand() { local options="" - local pkgSlug - pkgSlug=$(echo "${pkg}" | tr "/" "-") + local pkgSlug=$(echo "${pkg}" | tr "/" "-") if [[ ${TESTFLAGS} = *"-cover"* ]]; then mkdir -p ".cover" @@ -85,28 +83,28 @@ executeTestCommand() { printMessage "\\n\\n--- Starting part ${index} of go tests of '${pkg}' package with coverprofile in '${coverMode}' mode:\\n" - profileFile=".cover/${pkgSlug}.${index}.${coverMode}.cover.txt" + local profileFile=".cover/${pkgSlug}.${index}.${coverMode}.cover.txt" options="-covermode=${coverMode} -coverprofile=${profileFile}" else echo "Starting go test" fi - testOutputFile=".testoutput/${pkgSlug}.${index}.${output}.output.txt" + local testOutputFile=".testoutput/${pkgSlug}.${index}.${output}.output.txt" - exitCode=0 + local exitCode=0 # shellcheck disable=SC2086 go test ${options} ${TESTFLAGS} -v "${pkg}" -run "${runTestsList}" 2>&1 | tee "${testOutputFile}" || exitCode=1 - return $exitCode + return ${exitCode} } executeTestPart() { rm -rf ".cover/" rm -rf ".testoutput/" - numberOfDefinitions=$(< "${testsDefinitions}" wc -l) - executionSize=$((numberOfDefinitions/SUITE_TOTAL+1)) - executionOffset=$((SUITE_INDEX*executionSize+1)) + local numberOfDefinitions=$(< "${testsDefinitions}" wc -l) + local executionSize=$((numberOfDefinitions/SUITE_TOTAL+1)) + local executionOffset=$((SUITE_INDEX*executionSize+1)) printMessage "Number of definitions: ${numberOfDefinitions}" printMessage "Suite size: ${SUITE_TOTAL}" @@ -115,12 +113,12 @@ executeTestPart() { printMessage "Execution size: ${executionSize}" printMessage "Execution offset: ${executionOffset}" - exitCode=0 + local exitCode=0 while read -r pkg index tests; do executeTestCommand "${pkg}" "${index}" "${tests}" || exitCode=1 done < <(tail -n +${executionOffset} ${testsDefinitions} | head -n ${executionSize}) - exit $exitCode + exit ${exitCode} } computeCoverageReport() { @@ -140,7 +138,7 @@ computeCoverageReport() { go tool cover -o ${textReportFile} -func=${sourceFile} printMessage "General coverage percentage:" - total=$(grep "total" "${textReportFile}" || echo "") + local total=$(grep "total" "${textReportFile}" || echo "") if [[ -n "${total}" ]]; then echo "${output} ${total}"