Improve EXPECT/EXPECT_WITHIN result check in tests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I've found an spurious failure caused by an incorrect check of the expected value in EXPECT_WITHIN.

The problem is that the value passed to EXPECT_WITHIN (EXPECT also has the same problem) is considered a regular expression but most tests do not pass a full/valid regular expression.

For example, most tests expect a '0' result and they pass "0" as an argument to EXPECT/EXPECT_WITHIN. This will match with "0", that's ok, but it will also match with 10, 20, 102, ... and that's bad.

There are also some tests that do use a regular expression, like "^0$" to correctly match only "0", however current implementation of EXPECT_WITHIN uses the following check:

    if [[ "$a" =~ "$e" ]]; then

Where "$e" is the regular expression. However putting $e between quotation marks (") makes special regular expression characters to not be considered. This means that "^0$" will be searched literally and it won't never match. When the timeout expires, test_expect_footer is called, which does the same check but without using quotation marks. At this time the check succeeds, but we have waited an unnecessary amount of time.

This is not the first time that I've found something similar.

Would it be ok to change all regular expression checks to something like this in include.rc ?

    if [[ "$a" =~ ^$e$ ]]; then

This will allow using regular expressions in EXPECT and EXPECT_WITHIN, but will enforce full answer match in all cases, avoiding some possible side effects.

This needs some changes in many tests, but I think it's worth doing.

What do you think ?

Xavi
_______________________________________________
Gluster-devel mailing list
Gluster-devel@xxxxxxxxxxx
http://www.gluster.org/mailman/listinfo/gluster-devel



[Index of Archives]     [Gluster Users]     [Ceph Users]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux