From patchwork Mon May 20 09:05:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7790 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 4VjWsD3tScz3wxG for ; Mon, 20 May 2024 09:06:40 +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 4VjWs56l9Dz5SL; Mon, 20 May 2024 09:06:33 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4VjWs56F4Wz2y2N; Mon, 20 May 2024 09:06:33 +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 4VjWs26ck8z32W4 for ; Mon, 20 May 2024 09:06:30 +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 4VjWs25Wwwz5N; Mon, 20 May 2024 09:06:30 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1716195990; 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=Y5gQGNaZtz62TkBCGRwC52MNt+LvBpy3hohL27Nx8HU=; b=HaYjiOPHsNHA8HGGdCOmkt+4DL25yTXm+C4DIN3is0MV4BgCaI82pLsI392UOvRjR2Hynk 4jOBj1vbTG7aNUBQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1716195990; 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=Y5gQGNaZtz62TkBCGRwC52MNt+LvBpy3hohL27Nx8HU=; b=ZJi7tAeMiOtYDT72o/UXrJ8k8JfETeGH1dZmxHu9HU5PDtRxjofEDqdTVMzyeWCqScaPVW UUMHBGIx5Bb7LIRGqEvP+3OdF9580SizvPholi4cZuxfAbO7s3Cs1cciMd68jZykkCK7lx Wdge1FI+FiIUrbM73U4vCppuC68wJuczIyG2axhwPKnwjhNeI536iXT8XBD+2d4IPy/Pi9 +cU1wNfiYrgJH7pLYncKbKXGhn832uSYoMY6UXYvjrnxQOO5ZW1uxhWpF7gA7a2OEwN8dv b4CX22Kkuk0s9b1oX9ciW56OM0fm34OH6K2dz5gk8Hnvp56WZ9HPv4rTxi59Jg== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH 05/21] tests/lib.sh: Add logging functions Date: Mon, 20 May 2024 11:05:55 +0200 Message-Id: <20240520090611.10406-6-jonatan.schlag@ipfire.org> In-Reply-To: <20240520090611.10406-1-jonatan.schlag@ipfire.org> References: <20240520090611.10406-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: TSCJNDTTSFRBBQXRV5TO4BEOWFXYTKST X-Message-ID-Hash: TSCJNDTTSFRBBQXRV5TO4BEOWFXYTKST 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 373b7c3a0..6483c41c3 100644 --- a/tests/lib.sh +++ b/tests/lib.sh @@ -4,13 +4,21 @@ LIB_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" . ${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_that() { 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 } @@ -25,15 +33,15 @@ test_that_key_in_arry_has_value() { local value="${3}" if [[ ! -v "${array}" ]]; 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 }