xfs
[Top] [All Lists]

Re: [PATCH V2] xfstests: don't remove trailing zeros from integers

To: Dave Chinner <david@xxxxxxxxxxxxx>
Subject: Re: [PATCH V2] xfstests: don't remove trailing zeros from integers
From: Rich Johnston <rjohnston@xxxxxxx>
Date: Tue, 5 Mar 2013 13:20:45 -0600
Cc: Eric Whitney <enwlinux@xxxxxxxxx>, <sandeen@xxxxxxxxxx>, <xfs@xxxxxxxxxxx>
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <20130301203026.GC23616@dastard>
References: <20130301180158.GC6449@wallace> <20130301203026.GC23616@dastard>
User-agent: Mozilla/5.0 (X11; Linux i686; rv:13.0) Gecko/20120615 Thunderbird/13.0.1
On 03/01/2013 02:30 PM, Dave Chinner wrote:
On Fri, Mar 01, 2013 at 01:01:58PM -0500, Eric Whitney wrote:
_within_tolerance strips trailing zeros from the min and max range
values it outputs.  This leads to damage if the min or max value is
an integer containing trailing zeros rather than a real number with
a fractional part containing trailing zeros. Xfstest 289 can exhibit
this problem when its input is out of range.  Modify the code so it
will only remove trailing zeros found after a decimal point, and
remove decimal points not followed by digits.

Signed-off-by: Eric Whitney <enwlinux@xxxxxxxxx>
---
  common.filter |    7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/common.filter b/common.filter
index 9e4c90c..bfc800b 100644
--- a/common.filter
+++ b/common.filter
@@ -106,8 +106,11 @@ EOF

    # fix up min, max precision for output
    # can vary for 5.3, 6.2
-  _min=`echo $_min | sed -e 's/0*$//'` # get rid of trailling zeroes
-  _max=`echo $_max | sed -e 's/0*$//'` # get rid of trailling zeroes
+
+  # remove any trailing zeroes from min, max if they have fractional parts
+  # and then remove any decimal points not followed by digits
+  _min=`echo $_min | sed -e '/\./s/0*$//' | sed -e 's/\.$//'`
+  _max=`echo $_max | sed -e '/\./s/0*$//' | sed -e 's/\.$//'`

I like Dave's suggestion to change it to the following, what do you think Eric?

+ _min=`echo $_min | sed -e '/\./s/0*$//' -e 's/\.$//'` # get rid of trailing zeros + _max=`echo $_max | sed -e '/\./s/0*$//' -e 's/\.$//'` # get rid of trailing zeros

Regards
--Rich


You can do this with a single sed invocation via multiple
expressions:

$ echo 200.00 | sed -e '/\./s/0*$//' -e 's/\.$//'
200
$

Cheers,

Dave.



<Prev in Thread] Current Thread [Next in Thread>