[Gluster-devel] Bug in EXPECT family of macros in test framework

Niels de Vos ndevos at redhat.com
Tue Jan 27 14:27:43 UTC 2015


On Tue, Jan 27, 2015 at 12:35:35PM +0100, Xavier Hernandez wrote:
> Hi,
> 
> I've just discovered that EXPECT, EXPECT_WITHIN and others have a bug that
> can hide some failures.
> 
> The problem is that the test is made using a regular expression comparison.
> For example, EXPECT checks this:
> 
>     if ! [[ "$a" =~ $e ]]; then
> 
> There are some tests that use a regular expression as the first argument to
> EXPECT, however there are many other tests that simply use a number or a
> text.
> 
> This can cause problems. For example if the test is:
> 
>     EXPECT "0" <test>
> 
> And the test returns 10, the regular expression "0" *will* match with "10",
> so the test will be considered successful when it shouldn't.
> 
> It will also report success for test cases that check for an empty result:
> 
>     EXPECT "" <test>
> 
> This will always succeed, even if the test returns something.
> 
> What would be the best approach to solve this ?

Oh, yuck!

I think we should test like this, untested: [[ "$a" =~ "^$e\$" ]]

It might break some regular expressions, the expressions are now forced
to be very strict and should match the whole line.

Thoughts?
Niels
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://www.gluster.org/pipermail/gluster-devel/attachments/20150127/abcb7d3d/attachment.sig>


More information about the Gluster-devel mailing list