From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5CFB8C433EF for ; Sun, 6 Feb 2022 18:22:59 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AFEAE83881; Sun, 6 Feb 2022 19:22:56 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="a5L/17hm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CF73A83881; Sun, 6 Feb 2022 19:22:55 +0100 (CET) Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 834F783868 for ; Sun, 6 Feb 2022 19:22:49 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=none smtp.helo=mail-wr1-x431.google.com Received: by mail-wr1-x431.google.com with SMTP id k18so21095127wrg.11 for ; Sun, 06 Feb 2022 10:22:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VlkQppXGB+1W6p/b0qQiZeG2uJif5SQJyG39iirhOz4=; b=a5L/17hmc7E9vw0Mkvuv5aY+Lv1LcLI/UkEFTkRKPTJRLMOTbOE6oZXQn3BAxeZEKe IOhRbTiI7MoeGl+OrH5HZyr/hpdMAiPYk7814rZ6OJ+gjZp4Fus/Pzb+8Mil4MAEDz6c W0LVM6hMvoIuMdXIc8bcBOWLCNvSNSpSA+rqE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VlkQppXGB+1W6p/b0qQiZeG2uJif5SQJyG39iirhOz4=; b=zWVwWPFzHXwH7W2QMm/ttekONBD93vCqV4iMKzdMEmkP3ubzAWqGFqr7WYJFVMdwOz o4SOvXbzVd2iiqnSQxH/kwRJt8tHRVdU0jD2q+w8ALf5gEyB2wAgMs6An1x0wsoYaYrH 0+/KimQxN1Qv9hIh+u5rhX6BrAUbPruGXtX6isJxwqHzh6clPSoDc7/9AnRvV5uao7sz H0+Qv8ZVqc+naBEm227ieif4lBlI6Qrt1eREUFVKIbTXPiZ0bxirKzv8Os9Jd+kRgumf dhPdGG6nUKdNwIqHHRJiGMmu+c05D/aRU3MSu0DMdw3Wb8PDoSziKRtMpgvhnjrORro9 fPlQ== X-Gm-Message-State: AOAM5337UrqBfW9U+kIsXysqpilJikjaRbfxcaong6f1BOAVB/BFbS69 bUL4zV4GX2BVuerEmIsihVRE3vi+pCsd6g== X-Google-Smtp-Source: ABdhPJzDJg/j1LMNuRPw+/noCp8+/bN1+VK4+UvvNLG5Ei6sTTKGseisqzh9HiL4rjVA9b7nn8kKoA== X-Received: by 2002:adf:802a:: with SMTP id 39mr6906421wrk.533.1644171769014; Sun, 06 Feb 2022 10:22:49 -0800 (PST) Received: from pwmachine.localnet ([2a01:cb14:983:1f00:e5b3:218b:cb92:2549]) by smtp.gmail.com with ESMTPSA id f20sm18780289wmg.2.2022.02.06.10.22.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Feb 2022 10:22:48 -0800 (PST) From: Francis Laniel To: Simon Glass Cc: U-Boot Mailing List , Marek Behun , Michael Nazzareno Trimarchi , Wolfgang Denk , Harald Seiler Subject: Re: [RFC PATCH v1 04/21] test: hush: Test hush variable expansion. Date: Sun, 06 Feb 2022 19:22:47 +0100 Message-ID: <2095969.irdbgypaU6@pwmachine> In-Reply-To: References: <20211231161327.24918-1-francis.laniel@amarulasolutions.com> <20211231161327.24918-5-francis.laniel@amarulasolutions.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Hi. =46irst, sorry for the delayed answer and thank you a lot for all your revi= ews! Le samedi 8 janvier 2022, 15:53:49 CET Simon Glass a =E9crit : > Hi Francis, >=20 > On Fri, 31 Dec 2021 at 09:14, Francis Laniel >=20 > wrote: > > This commit ensures shell variables are replaced by their values. > >=20 > > Signed-off-by: Francis Laniel > > --- > >=20 > > test/hush/Makefile | 1 + > > test/hush/dollar.c | 191 +++++++++++++++++++++++++++++++++++++++++++++ > > 2 files changed, 192 insertions(+) > > create mode 100644 test/hush/dollar.c > >=20 > > diff --git a/test/hush/Makefile b/test/hush/Makefile > > index a3c9ae5106..feb4f71956 100644 > > --- a/test/hush/Makefile > > +++ b/test/hush/Makefile > > @@ -5,3 +5,4 @@ > >=20 > > obj-y +=3D cmd_ut_hush.o > > obj-y +=3D if.o > >=20 > > +obj-y +=3D dollar.o > > diff --git a/test/hush/dollar.c b/test/hush/dollar.c > > new file mode 100644 > > index 0000000000..9313d145d6 > > --- /dev/null > > +++ b/test/hush/dollar.c > > @@ -0,0 +1,191 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * (C) Copyright 2021 > > + * Francis Laniel, Amarula Solutions, francis.laniel@amarulasolutions.= com > > + */ > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +static int hush_test_simple_dollar(struct unit_test_state *uts) > > +{ > > + console_record_reset_enable(); > > + ut_assertok(run_command("echo $dollar_foo", 0)); > > +#pragma GCC diagnostic push > > +#pragma GCC diagnostic ignored "-Wformat-zero-length" > > + /* > > + * Next line is empty as $dollar_foo was not set before, but > > compiler + * complains about the format being empty, so we disab= le > > this warning + * only for this line. > > + */ > > + ut_assert_nextline(""); > > +#pragma GCC diagnostic pop >=20 > You might be able to dp: >=20 > ut_assert_nextline("%s", ""); Thank you for the trick! With this I was able to get rid of this bad warnin= g=20 canceling. >=20 > > + ut_assert_console_end(); > > + > > + ut_assertok(run_command("echo ${dollar_foo}", 0)); > > +#pragma GCC diagnostic push > > +#pragma GCC diagnostic ignored "-Wformat-zero-length" > > + /* > > + * Next line is empty as $dollar_foo was not set before, but > > compiler + * complains about the format being empty, so we disab= le > > this warning + * only for this line. > > + */ > > + ut_assert_nextline(""); > > +#pragma GCC diagnostic pop > > + ut_assert_console_end(); > > + > > + ut_assertok(run_command("dollar_foo=3Dbar", 0)); > > + > > + ut_assertok(run_command("echo $dollar_foo", 0)); > > + ut_assert_nextline("bar"); > > + ut_assert_console_end(); > > + > > + ut_assertok(run_command("echo ${dollar_foo}", 0)); > > + ut_assert_nextline("bar"); > > + ut_assert_console_end(); > > + > > + /* > > + * R is way of giving raw string literals in C++. > > + * It means a "\n" is a R string literal will not be interpreted > > as line + * feed but printed as "\n". > > + * GCC provides it for C as an extension. > > + */ > > + ut_assertok(run_command(R"(dollar_foo=3D\$bar)", 0)); > > + > > + ut_assertok(run_command("echo $dollar_foo", 0)); > > + ut_assert_nextline("$bar"); > > + ut_assert_console_end(); > > + > > + ut_assertok(run_command("dollar_foo=3D'$bar'", 0)); > > + > > + ut_assertok(run_command("echo $dollar_foo", 0)); > > + ut_assert_nextline("$bar"); > > + ut_assert_console_end(); > > + > > + ut_asserteq(1, run_command("dollar_foo=3Dbar quux", 0)); > > + /* Next line contains error message. */ > > + ut_assert_skipline(); > > + ut_assert_console_end(); > > + > > + ut_asserteq(1, run_command("dollar_foo=3D'bar quux", 0)); > > + /* Next line contains error message. */ > > + ut_assert_skipline(); > > + ut_assert_console_end(); > > + > > + ut_asserteq(1, run_command(R"(dollar_foo=3Dbar quux")", 0)); > > + /* Two next lines contain error message. */ > > + ut_assert_skipline(); > > + ut_assert_skipline(); > > + ut_assert_console_end(); > > + > > + ut_assertok(run_command(R"(dollar_foo=3D'bar "quux')", 0)); > > + > > + ut_assertok(run_command("echo $dollar_foo", 0)); > > + /* > > + * This one is buggy. > > + * ut_assert_nextline(R"(bar "quux)"); > > + * ut_assert_console_end(); > > + * > > + * So, let's reset output: > > + */ > > + console_record_reset_enable(); > > + > > + ut_asserteq(1, run_command(R"(dollar_foo=3D"bar 'quux")", 0)); > > + /* Next line contains error message. */ > > + ut_assert_skipline(); > > + ut_assert_console_end(); > > + > > + ut_assertok(run_command("dollar_foo=3D'bar quux'", 0)); > > + ut_assertok(run_command("echo $dollar_foo", 0)); > > + ut_assert_nextline("bar quux"); > > + ut_assert_console_end(); > > + > > + puts("Beware: this test set local variable dollar_foo and it > > cannot be unset!"); + > > + return 0; > > +} > > +HUSH_TEST(hush_test_simple_dollar, 0); > > + > > +static int hush_test_env_dollar(struct unit_test_state *uts) > > +{ > > + env_set("env_foo", "bar"); > > + console_record_reset_enable(); > > + > > + ut_assertok(run_command("echo $env_foo", 0)); > > + ut_assert_nextline("bar"); > > + ut_assert_console_end(); > > + > > + ut_assertok(run_command("echo ${env_foo}", 0)); > > + ut_assert_nextline("bar"); > > + ut_assert_console_end(); > > + > > + /* Environment variables have precedence over local variable. */ >=20 > spelling >=20 > also please avoid period before */ >=20 > > + ut_assertok(run_command("env_foo=3Dquux", 0)); > > + ut_assertok(run_command("echo ${env_foo}", 0)); > > + ut_assert_nextline("bar"); > > + ut_assert_console_end(); > > + > > + /* Clean up setting the variable. */ > > + env_set("env_foo", NULL); > > + > > + puts("Beware: this test set local variable env_foo and it cannot > > be unset!"); > Don't you unset it in the previous line? I unsetted the environment variable named env_foo, but the local variable=20 sadly remained because it is not possible to unset local variable. So, after running "ut hush", the following should occur: =3D> ut hush Running 20 hush tests =2E.. =46ailures: 0 =3D> echo env_foo quux > > + > > + return 0; > > +} > > +HUSH_TEST(hush_test_env_dollar, 0); > > + > > +static int hush_test_command_dollar(struct unit_test_state *uts) > > +{ > > + console_record_reset_enable(); > > + > > + ut_assertok(run_command(R"(dollar_bar=3D"echo bar")", 0)); > > + > > + ut_assertok(run_command("$dollar_bar", 0)); > > + ut_assert_nextline("bar"); > > + ut_assert_console_end(); > > + > > + ut_assertok(run_command("${dollar_bar}", 0)); > > + ut_assert_nextline("bar"); > > + ut_assert_console_end(); > > + > > + ut_assertok(run_command(R"(dollar_bar=3D"echo > > + bar")", 0)); >=20 > newline in the middle of a string ? I think this should be a problem with how the mailer rendered this because = on=20 my side it is: ut_assertok(run_command(R"(dollar_bar=3D"echo bar")", 0)); I will check this on v2 (which should arrive from within 15-30 minutes). >=20 > > + > > + ut_assertok(run_command("$dollar_bar", 0)); > > + ut_assert_nextline("bar"); > > + ut_assert_console_end(); > > + > > + ut_assertok(run_command(R"(dollar_bar=3D'echo bar > > + ')", 0)); > > + > > + ut_assertok(run_command("$dollar_bar", 0)); > > + ut_assert_nextline("bar"); > > + ut_assert_console_end(); > > + > > + ut_assertok(run_command(R"(dollar_bar=3D'echo bar\n')", 0)); > > + > > + ut_assertok(run_command("$dollar_bar", 0)); > > + ut_assert_nextline("barn"); > > + ut_assert_console_end(); > > + > > + ut_assertok(run_command("dollar_bar=3D'echo $bar'", 0)); > > + > > + ut_assertok(run_command("$dollar_bar", 0)); > > + ut_assert_nextline("$bar"); > > + ut_assert_console_end(); > > + > > + ut_assertok(run_command("dollar_quux=3Dquux", 0)); > > + ut_assertok(run_command(R"(dollar_bar=3D"echo $dollar_quux")", = 0)); > > + > > + ut_assertok(run_command("$dollar_bar", 0)); > > + ut_assert_nextline("quux"); > > + ut_assert_console_end(); > > + > > + puts("Beware: this test sets local variable dollar_bar and > > dollar_quux and they cannot be unset!"); + > > + return 0; > > +} > > +HUSH_TEST(hush_test_command_dollar, 0); > > -- > > 2.25.1 >=20 > Regards, > Simon