From patchwork Fri Oct 11 09:54:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 1175080 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46qNbv4nKyz9sCJ for ; Fri, 11 Oct 2019 20:55:07 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id D7C863C2292 for ; Fri, 11 Oct 2019 11:55:04 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5]) by picard.linux.it (Postfix) with ESMTP id E43DA3C1453 for ; Fri, 11 Oct 2019 11:54:54 +0200 (CEST) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id 6F460600C5B for ; Fri, 11 Oct 2019 11:53:18 +0200 (CEST) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 660C8AE40; Fri, 11 Oct 2019 09:54:53 +0000 (UTC) From: Petr Vorel To: ltp@lists.linux.it Date: Fri, 11 Oct 2019 11:54:38 +0200 Message-Id: <20191011095442.10541-2-pvorel@suse.cz> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191011095442.10541-1-pvorel@suse.cz> References: <20191011095442.10541-1-pvorel@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH v5 1/5] shell: Add tst_is_num() X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Using grep -E, which more portable than using awk or anything else. Reviewed-by: Li Wang Reviewed-by: Clemens Famulla-Conrad Signed-off-by: Petr Vorel --- doc/test-writing-guidelines.txt | 6 ++++++ testcases/lib/tst_test.sh | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt index 6da87baa7..997272cbe 100644 --- a/doc/test-writing-guidelines.txt +++ b/doc/test-writing-guidelines.txt @@ -2338,6 +2338,12 @@ Checking for integers tst_is_int "$FOO" ------------------------------------------------------------------------------- +Checking for integers and floating point numbers +++++++++++++++++++++++++++++++++++++++++++++++++ +# returns zero if passed an integer or floating point number parameter, non-zero otherwise +tst_is_num "$FOO" +------------------------------------------------------------------------------- + Obtaining random numbers ++++++++++++++++++++++++ diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh index e0b24c6b9..ca63745fd 100644 --- a/testcases/lib/tst_test.sh +++ b/testcases/lib/tst_test.sh @@ -1,6 +1,6 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0-or-later -# Copyright (c) Linux Test Project, 2014-2018 +# Copyright (c) Linux Test Project, 2014-2019 # Author: Cyril Hrubis # # LTP test library for shell. @@ -344,6 +344,11 @@ tst_is_int() return $? } +tst_is_num() +{ + echo "$1" | grep -Eq '^[-+]?[0-9]+\.?[0-9]*$' +} + tst_usage() { if [ -n "$TST_USAGE" ]; then