From patchwork Sun Jun 16 16:02:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7870 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 4W2Hqj0GrCz3ws3 for ; Sun, 16 Jun 2024 16:03:29 +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 4W2Hqd2LrRz5nP; Sun, 16 Jun 2024 16:03:25 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4W2Hqb3kq1z33G5; Sun, 16 Jun 2024 16:03:23 +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 4W2HqW3T72z33Fq for ; Sun, 16 Jun 2024 16:03:19 +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 4W2HqS1k6Nz5nN; Sun, 16 Jun 2024 16:03:16 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718553796; 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=hlJ+DF2XKYgivlSkbMfQ0MkU5Oo6ky7KBk0VlXzs+Mw=; b=7SvFAOVOlcOZXXgn7n5hp/3s5sSA9faGgMHBEAMx3OGmM/Ym+099izaJ0o6BimdLH5eoN7 fgU2/SRoxsdSPaAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718553796; 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=hlJ+DF2XKYgivlSkbMfQ0MkU5Oo6ky7KBk0VlXzs+Mw=; b=f6L4YVS/+/zflPK8oEz4lITIoMBJTwDD8w1aokE5SZyfb20Zmcn+MDotmz5jMonTYfTNze OXd9ofbC5GV2fNuDUTCSak1l1D62EwGJOCjheMkDT4YBCF119IpVu5EgWKffrTrw2hHvdZ tFy8Gsga6pZtIAVT26Of/zApLfqcjDAS+d/JD3dMQHJt8yhQ5GUh+5ZgM6W3IAJPSgwhdJ ZI6H4gFG+Y0vxRmPX7zPnLr1EnisWzP8sDeqKiOyqGP6bM/cAYtpJmU0RdggCzZZ8woTvb rgRk8W2lV6EZh6afvVH8g7759ILs191BoF3BKShIR5p7zih7Mo/zoFdirPKzGQ== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 07/18] tests: Add function to test the ouput of a bash function Date: Sun, 16 Jun 2024 18:02:34 +0200 Message-Id: <20240616160245.18865-8-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: 7EE6TH4334ZW26NFSNDDKLDMZPEAV7EG X-Message-ID-Hash: 7EE6TH4334ZW26NFSNDDKLDMZPEAV7EG 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 af8c632cf..4110ed2d8 100644 --- a/tests/lib.sh +++ b/tests/lib.sh @@ -64,3 +64,32 @@ test_value_in_array() { 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}" +}