From patchwork Mon May 20 09:06:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7794 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 4VjWsl3FlQz3wxG for ; Mon, 20 May 2024 09:07:07 +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 4VjWsK20zLz5nc; Mon, 20 May 2024 09:06:45 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4VjWsD2zxbz32w8; Mon, 20 May 2024 09:06:40 +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 4VjWs7047yz2y2N for ; Mon, 20 May 2024 09:06:35 +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 4VjWs653nVz5Vc; Mon, 20 May 2024 09:06:34 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1716195994; 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=mkZVoRNioq/xi0W7v5J0OjAM0HFuWW2D2tPl7mzCZtE=; b=+gusQnt7rsUGyvL6km5cEXLsUBAA4KOIxX1riLiOeXxBI9xghWCyr/5gFBcS08WESr+XV3 tpBtB7ti0tNBATBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1716195994; 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=mkZVoRNioq/xi0W7v5J0OjAM0HFuWW2D2tPl7mzCZtE=; b=kaAUMJhm0FVEXYPh+jSVhL74+zSZu/VL020ZY1Ghez08UWXdHz8DBRsC6xtRhoFWrAjuHJ aa/C7z5l1oOcNLK2ay8Vzh47BLsaCchM144FqnbZ1JqSBOf4AuHAG29DPYOJBkrfAClR2m i/CaLSA2CtES8aHRttV+K+sTGirru4MW/hFJVdPXn8ZTalg1TBI4ABmGhMxeHqENMoBSLj pVxfYYRVfDLwbaSQHLRKQ2SVVnbKLvgC81vDanx3mHSDVTFAzdePA2ivd5o4Er2NQzZe9f qI9ZwfH7Hv1HFXbzAEooNXZDAbYXOznslcS2F4oWUK4b6KrZ2eNUq4Hgai4XqQ== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH 11/21] tests: Add function to test the ouput of a bash function Date: Mon, 20 May 2024 11:06:01 +0200 Message-Id: <20240520090611.10406-12-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: 2BXAQHMNS5ZAGEJ5OKRNQ3NC4R2R4C76 X-Message-ID-Hash: 2BXAQHMNS5ZAGEJ5OKRNQ3NC4R2R4C76 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: Signed-off-by: Jonatan Schlag --- tests/lib.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/lib.sh b/tests/lib.sh index 81bc1439c..9ce0201b1 100644 --- a/tests/lib.sh +++ b/tests/lib.sh @@ -52,3 +52,32 @@ test_that_key_in_arry_has_value() { return 1 fi } + +test_that_output_is(){ + local reference_output_file="${1}" + local file_descriptor="${2}" + shift + shift + + local command="$@" + + local temp="$(mktemp)" + + case "${file_descriptor}" in + "stdout"|"1") + $command 1> "${temp}" 2>/dev/null + ;; + "stderr"|"2") + $command 2> "${temp}" 1>/dev/null + ;; + esac + + if diff -u "${temp}" "${reference_output_file}" &> /dev/null; then + log_test_succeded "The output of command '${command}' on file descriptor '${file_descriptor}' is equal to the reference output." + else + log_test_failed "The output of command '${command}' on file descriptor '${file_descriptor}' is unequal to the reference output." + diff -u --color "${reference_output_file}" "${temp}" + fi + + rm "${temp}" +}