Message ID | 20240520090611.10406-3-jonatan.schlag@ipfire.org |
---|---|
State | New |
Headers |
Return-Path: <development-bounces@lists.ipfire.org> 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 4VjWs544Vvz3wxG for <patchwork@web04.haj.ipfire.org>; Mon, 20 May 2024 09:06:33 +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 4VjWs31w0jz1Fb; Mon, 20 May 2024 09:06:31 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4VjWs31Nj5z32w8; Mon, 20 May 2024 09:06:31 +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 4VjWs06pmtz2y2N for <development@lists.ipfire.org>; Mon, 20 May 2024 09:06:28 +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 4VjWs02YLKz2PV; Mon, 20 May 2024 09:06:28 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1716195988; 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=3c9qfvwiI0b2KhGo7Hp1UisXYc10n5u8chMNBMekolA=; b=j8lmroPCieK8AHSZuG9qEmlziQ3RNEKHMKpBnX3EisIohYlKvI+u4cE6adnCK6+gbL5hYB FJq4YPM1nofRiqBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1716195988; 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=3c9qfvwiI0b2KhGo7Hp1UisXYc10n5u8chMNBMekolA=; b=epECaIJF/UqZJDUvfcVb3bU1IvgygIwCA4tBqfY57o7QzbJJ5ldDpg8d9L5pKvSoJjyk2x nu80Sx9lKahHo0pSKU8QYg14murm5LWRPnIqp4NNqvaBaVoe2XWdacut0UVu/uUEqUWkSB V1oPTU8N1Qdh5m3m/VIxs5eBbKOlv38N0uY4DEaAX+GuhlTzriqObRa1iScsPD56kdzgEm quBWYlewzEGL9NzOgH3eHe2SaY5xIrOrrRINo6TJLzmgFf7oNl3qc3d0aSalaOdKqEWfUQ fKtxO/hk91ZvafA+BPH+7O4b1129lkfAYty9zIT4+XKL6faxKa2M4uCc/4JvqQ== From: Jonatan Schlag <jonatan.schlag@ipfire.org> To: development@lists.ipfire.org Subject: [PATCH 02/21] tests: Add bash lib Date: Mon, 20 May 2024 11:05:52 +0200 Message-Id: <20240520090611.10406-3-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 Content-Transfer-Encoding: 8bit Message-ID-Hash: VCHFVUPTKILNUOORJBCEO5MJ5GMDD7MU X-Message-ID-Hash: VCHFVUPTKILNUOORJBCEO5MJ5GMDD7MU 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 <development.lists.ipfire.org> Archived-At: <https://lists.ipfire.org/hyperkitty/list/development@lists.ipfire.org/message/VCHFVUPTKILNUOORJBCEO5MJ5GMDD7MU/> List-Archive: <https://lists.ipfire.org/hyperkitty/list/development@lists.ipfire.org/> List-Help: <mailto:development-request@lists.ipfire.org?subject=help> List-Owner: <mailto:development-owner@lists.ipfire.org> List-Post: <mailto:development@lists.ipfire.org> List-Subscribe: <mailto:development-join@lists.ipfire.org> List-Unsubscribe: <mailto:development-leave@lists.ipfire.org> |
Series |
[01/21] test: Add bash lib for colors
|
|
Commit Message
Jonatan Schlag
May 20, 2024, 9:05 a.m. UTC
This allows use to write test with less effort as we can reuse functions
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
---
tests/lib.sh | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
create mode 100644 tests/lib.sh
Comments
Hello, > On 20 May 2024, at 10:05, Jonatan Schlag <jonatan.schlag@ipfire.org> wrote: > > This allows use to write test with less effort as we can reuse functions > > Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org> > --- > tests/lib.sh | 20 ++++++++++++++++++++ > 1 file changed, 20 insertions(+) > create mode 100644 tests/lib.sh > > diff --git a/tests/lib.sh b/tests/lib.sh > new file mode 100644 > index 000000000..7749d5158 > --- /dev/null > +++ b/tests/lib.sh > @@ -0,0 +1,20 @@ > +#!/usr/bin/bash > + > +LIB_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" ??? I don’t think this is very intuitive. > +. ${LIB_DIR}/lib_color.sh > + > +test_that() { > + > + if ! "$@" ; then > + echo -e "${CLR_RED_BG} Test failed: ${*} ${CLR_RESET}" > + return 1 > + else > + echo -e "${CLR_GREEN_BG} Test succeded: ${*} ${CLR_RESET}" > + return 0 > + fi > +} We have had so many discussions about how to name functions. “That” is quite generic in my opinion. Why not “test_command” or something like that? > + > +var_has_value() { > + [[ "${!1}" == "${2}" ]] > +} > -- > 2.39.2 >
Hi, Am Freitag, dem 31.05.2024 um 10:47 +0100 schrieb Michael Tremer: > Hello, > > > On 20 May 2024, at 10:05, Jonatan Schlag > > <jonatan.schlag@ipfire.org> wrote: > > > > This allows use to write test with less effort as we can reuse > > functions > > > > Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org> > > --- > > tests/lib.sh | 20 ++++++++++++++++++++ > > 1 file changed, 20 insertions(+) > > create mode 100644 tests/lib.sh > > > > diff --git a/tests/lib.sh b/tests/lib.sh > > new file mode 100644 > > index 000000000..7749d5158 > > --- /dev/null > > +++ b/tests/lib.sh > > @@ -0,0 +1,20 @@ > > +#!/usr/bin/bash > > + > > +LIB_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" > > ??? > > I don’t think this is very intuitive. Ok, what am I supposed to do about it? I need the path where this file is located, and I cannot hard-code it. Should I add a comment? Jonatan > > > +. ${LIB_DIR}/lib_color.sh > > + > > +test_that() { > > + > > + if ! "$@" ; then > > + echo -e "${CLR_RED_BG} Test failed: ${*} ${CLR_RESET}" > > + return 1 > > + else > > + echo -e "${CLR_GREEN_BG} Test succeded: ${*} ${CLR_RESET}" > > + return 0 > > + fi > > +} > > We have had so many discussions about how to name functions. “That” > is quite generic in my opinion. > > Why not “test_command” or something like that? > > > + > > +var_has_value() { > > + [[ "${!1}" == "${2}" ]] > > +} > > -- > > 2.39.2 > > >
Hello, > On 2 Jun 2024, at 18:49, Jonatan Schlag <jonatan.schlag@ipfire.org> wrote: > > > Hi, > > > Am Freitag, dem 31.05.2024 um 10:47 +0100 schrieb Michael Tremer: >> Hello, >> >>> On 20 May 2024, at 10:05, Jonatan Schlag >>> <jonatan.schlag@ipfire.org> wrote: >>> >>> This allows use to write test with less effort as we can reuse >>> functions >>> >>> Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org> >>> --- >>> tests/lib.sh | 20 ++++++++++++++++++++ >>> 1 file changed, 20 insertions(+) >>> create mode 100644 tests/lib.sh >>> >>> diff --git a/tests/lib.sh b/tests/lib.sh >>> new file mode 100644 >>> index 000000000..7749d5158 >>> --- /dev/null >>> +++ b/tests/lib.sh >>> @@ -0,0 +1,20 @@ >>> +#!/usr/bin/bash >>> + >>> +LIB_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" >> >> ??? >> >> I don’t think this is very intuitive. > > Ok, what am I supposed to do about it? I need the path where this file > is located, and I cannot hard-code it. Should I add a comment? Generally speaking, I like to split things into one line per task. So that it is very easy to see what is happening when reading the code. This approach also has some more advantages. For example, you can easily put a print statement between lines to see if you are getting the output that you are expecting. That makes debugging nice and easy. When I say generally, there are of course exceptions like very trivial things that can often be put into the same line. Commenting is also a lot easier when you only have to comment one thing at once. You need to add way more comments, please. -Michael > Jonatan > >> >>> +. ${LIB_DIR}/lib_color.sh >>> + >>> +test_that() { >>> + >>> + if ! "$@" ; then >>> + echo -e "${CLR_RED_BG} Test failed: ${*} ${CLR_RESET}" >>> + return 1 >>> + else >>> + echo -e "${CLR_GREEN_BG} Test succeded: ${*} ${CLR_RESET}" >>> + return 0 >>> + fi >>> +} >> >> We have had so many discussions about how to name functions. “That” >> is quite generic in my opinion. >> >> Why not “test_command” or something like that? >> >>> + >>> +var_has_value() { >>> + [[ "${!1}" == "${2}" ]] >>> +} >>> -- >>> 2.39.2
diff --git a/tests/lib.sh b/tests/lib.sh new file mode 100644 index 000000000..7749d5158 --- /dev/null +++ b/tests/lib.sh @@ -0,0 +1,20 @@ +#!/usr/bin/bash + +LIB_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" + +. ${LIB_DIR}/lib_color.sh + +test_that() { + + if ! "$@" ; then + echo -e "${CLR_RED_BG} Test failed: ${*} ${CLR_RESET}" + return 1 + else + echo -e "${CLR_GREEN_BG} Test succeded: ${*} ${CLR_RESET}" + return 0 + fi +} + +var_has_value() { + [[ "${!1}" == "${2}" ]] +}