From patchwork Sun Jun 16 16:02:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7866 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqd4JZ5z3ws3 for ; Sun, 16 Jun 2024 16:03:25 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4W2HqV1Lvpz5W9; Sun, 16 Jun 2024 16:03:18 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4W2HqN51c8z33Fv; Sun, 16 Jun 2024 16:03:12 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4W2HqL30QXz33FL for ; Sun, 16 Jun 2024 16:03:10 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4W2HqK4PDfz5gB; Sun, 16 Jun 2024 16:03:09 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718553789; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VDlmZXGoBGCQG9MudnMCcWQSn8nQvTNueWreNUJtXFg=; b=M7InXM34+Jzwh5i24ep7hqDqpORlpus1YWV+8bbI0Yi0bmOOgwJYApFc/HNBiS8Tup8EQJ 4edb3LYaVgNQqcAw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718553789; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VDlmZXGoBGCQG9MudnMCcWQSn8nQvTNueWreNUJtXFg=; b=vibZ1VxuYStTe3PfxheEE6juHyq56x9Nln4AI0Mf+qXq8lG4oh7maeCvz38QV5excpOXT1 Qsg1xJkIIGC8oPD4bm+IgoRGEEqDf9JhDV4LVVW2P/x7fgvlpE+KEsC/LgN00bvpKohAtv 6j8u8A9DT3ilbuCM+UqbiDsM9ymg92BLSUFQHq9JvfygdPaFdwwAANIUOjMZEB/7mXlW+m j38TDHsHXIjWxGY9KX/MGvX4Jne+xD8OED/KORWpqewGdnqUrocYHUoP8FRTpJkkDeMwcz u8100cNPnj3TlpW6k4NK2RateAe3DhdwvCgByGKnBoxm2ZXKlukoBK4AkpUNEg== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 04/18] tests/lib.sh: Add logging functions Date: Sun, 16 Jun 2024 18:02:31 +0200 Message-Id: <20240616160245.18865-5-jonatan.schlag@ipfire.org> In-Reply-To: <20240616160245.18865-1-jonatan.schlag@ipfire.org> References: <20240616160245.18865-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: KAJFCM5MRQYVOAIL4AEC5PF3AQOW45DC X-Message-ID-Hash: KAJFCM5MRQYVOAIL4AEC5PF3AQOW45DC X-MailFrom: jonatan.schlag@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: So we can change the style of our log messages better. Signed-off-by: Jonatan Schlag --- tests/lib.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/lib.sh b/tests/lib.sh index 4fce151f8..e462f4add 100644 --- a/tests/lib.sh +++ b/tests/lib.sh @@ -11,13 +11,21 @@ LIB_DIR="$(dirname "${LIB_DIR}")" . ${LIB_DIR}/lib_color.sh +log_test_failed(){ + echo -e "${CLR_RED_BG}Test failed: ${*}${CLR_RESET}'" +} + +log_test_succeded(){ + echo -e "${CLR_GREEN_BG}Test succeded: ${*}${CLR_RESET}" +} + test_command() { if ! "$@" ; then - echo -e "${CLR_RED_BG} Test failed: ${*} ${CLR_RESET}" + log_test_failed "${*}" return 1 else - echo -e "${CLR_GREEN_BG} Test succeded: ${*} ${CLR_RESET}" + log_test_succeded "${*}" return 0 fi } @@ -36,15 +44,15 @@ test_value_in_array() { # If the array was not declared as indexed or associative array we fail. We cannot check for a value in an array if # we were not given array. if [[ ! "$(declare -p "${arrayname}")" =~ "declare -a" && ! "$(declare -p "${arrayname}")" =~ "declare -A" ]]; then - echo -e "${CLR_RED_BG}Test failed: The array '${1}' does not exists. The variable is not set.${CLR_RESET}'" + log_test_failed "The array '${1}' does not exists. The variable is not set." return 1 fi if [[ "${array[${key}]}" == "${value}" ]] ; then - echo -e "${CLR_GREEN_BG}Test succeded: The array '${1}' contains the value '${value}' under the key '${key}' ${CLR_RESET}" + log_test_succeded "The array '${1}' contains the value '${value}' under the key '${key}'" return 0 else - echo -e "${CLR_RED_BG}Test failed: The array '${1}' contains the value '${array[${key}]}' under the key '${key} and not '${value}' ${CLR_RESET}" + log_test_failed "The array '${1}' contains the value '${array[${key}]}' under the key '${key} and not '${value}'" return 1 fi }