From bf0cffd89e5c528c3705a13bf41a047a4f3c53d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Altahr=C3=AFm?= Date: Mon, 16 Sep 2019 15:58:53 +0200 Subject: [PATCH 1/4] Write debug and errors on stderr. --- src/output/print.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/output/print.sh b/src/output/print.sh index 47b3eb7..d1ea1b0 100644 --- a/src/output/print.sh +++ b/src/output/print.sh @@ -16,10 +16,10 @@ function b2r:print:debug() { if ! ${B2R_DEBUG}; then return fi - b2r:color 248 + b2r:color 248 >&2 # shellcheck disable=SC2059 - printf "${@}" - b2r:ansi:reset + printf "${@}" >&2 + b2r:ansi:reset >&2 } # @description Internal debug message. @@ -124,9 +124,9 @@ function b2r:print:success() { # @stderr Formatted message # @see printf for format options. function b2r:print:warning() { - b2r:print:_prefix '⚠' 202 1>&2 + b2r:print:_prefix '⚠' 202 >&2 # shellcheck disable=SC2059 - printf "${@}" 1>&2 + printf "${@}" >&2 } # @description Error message. @@ -138,9 +138,9 @@ function b2r:print:warning() { # @stderr Formatted message # @see printf for format options. function b2r:print:error() { - b2r:print:_prefix '⚠' 124 1>&2 + b2r:print:_prefix '⚠' 124 >&2 # shellcheck disable=SC2059 - printf "${@}" 1>&2 + printf "${@}" >&2 } # @description Panic message and quit script. @@ -152,9 +152,9 @@ function b2r:print:error() { # @stderr Formatted message # @see printf for format options. function b2r:print:panic() { - b2r:print:_prefix "$(b2r:ansi:bold)⚠" "196" 1>&2 + b2r:print:_prefix "$(b2r:ansi:bold)⚠" "196" >&2 # shellcheck disable=SC2059 - printf "${@}" 1>&2 + printf "${@}" >&2 exit 255 } -- GitLab From edf48eda493fe962f1da7b885ac9454103c2e469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Altahr=C3=AFm?= Date: Mon, 16 Sep 2019 15:59:50 +0200 Subject: [PATCH 2/4] Global variables must be available globally. --- beer.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/beer.sh b/beer.sh index 7ba9890..6271f51 100644 --- a/beer.sh +++ b/beer.sh @@ -2,10 +2,10 @@ # @file BEER init file # @brief This file must be included first in your project. # Framework variables -declare B2R_ROOT_PATH +declare -g B2R_ROOT_PATH B2R_ROOT_PATH="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" -declare -r B2R_ROOT_PATH -declare -A B2R_LOADED_MODULES=() +declare -gr B2R_ROOT_PATH +declare -gA B2R_LOADED_MODULES=() # @description Initialize framework # Enforces best practices and declare global variables. -- GitLab From b264a0b3c3c52df0fbdb4a888f327771bec8e7d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Altahr=C3=AFm?= Date: Mon, 16 Sep 2019 16:24:21 +0200 Subject: [PATCH 3/4] Fix for ShellCheck 0.7.0 --- src/output/ansi.sh | 3 ++- tests/output/ansi.sh | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100755 tests/output/ansi.sh diff --git a/src/output/ansi.sh b/src/output/ansi.sh index e41d4f3..d156a39 100644 --- a/src/output/ansi.sh +++ b/src/output/ansi.sh @@ -42,5 +42,6 @@ function b2r:ansi:strike() { function b2r:ansi:strip() { declare -r TEXT="${1}" ESC_PREFIX="$(printf '\033[')" + # shellcheck disable=SC2001 <<< "${TEXT}" sed "s/${ESC_PREFIX}[0-9;]\\+m//g" -} \ No newline at end of file +} diff --git a/tests/output/ansi.sh b/tests/output/ansi.sh new file mode 100755 index 0000000..0d6878c --- /dev/null +++ b/tests/output/ansi.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# @file Test suite for ansi output +# shellcheck source=tests/init.sh +source "$(dirname "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")")/init.sh" + +function testAnsiStrip() { + declare -r ANSI_STRING="$(b2r:ansi:seq 48 5 25)Colored $(b2r:ansi:bold)and bold$(b2r:ansi:reset)" + declare -r BASIC_STRING="Colored and bold" + + assertEquals "ANSI sequences must be completely removed" "${BASIC_STRING}" "$(b2r:ansi:strip "${ANSI_STRING}")" +} \ No newline at end of file -- GitLab From 173c5756a44938a12a7df7fc31b8f4e06da19dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Altahr=C3=AFm?= Date: Mon, 16 Sep 2019 16:26:57 +0200 Subject: [PATCH 4/4] Fixes for Shellcheck (also in tests) --- tests/output/ansi.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/output/ansi.sh b/tests/output/ansi.sh index 0d6878c..150cabc 100755 --- a/tests/output/ansi.sh +++ b/tests/output/ansi.sh @@ -4,8 +4,9 @@ source "$(dirname "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")")/init.sh" function testAnsiStrip() { - declare -r ANSI_STRING="$(b2r:ansi:seq 48 5 25)Colored $(b2r:ansi:bold)and bold$(b2r:ansi:reset)" - declare -r BASIC_STRING="Colored and bold" + declare ANSI_STRING BASIC_STRING + ANSI_STRING="$(b2r:ansi:seq 48 5 25)Colored $(b2r:ansi:bold)and bold$(b2r:ansi:reset)" + BASIC_STRING="Colored and bold" assertEquals "ANSI sequences must be completely removed" "${BASIC_STRING}" "$(b2r:ansi:strip "${ANSI_STRING}")" } \ No newline at end of file -- GitLab