From 4c127543795b276b9683e0e0300363b646f844b2 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 22 May 2015 18:39:11 +0200 Subject: [PATCH] Bug 14256: Make TestBuilder regenerates a string if to short In some cases, especially branchcode and categorycode, the generated string for a primary key already existed in DB. Which make the tests fail, and the data are not gererated. This patch regenerate a string if the one generated is too short and can be longer. Test plan: Use the diff from the previous comment, and confirm that the tests only fail in the very few cases. QA: Actually I don't know if the better could be to use the existing value, but maybe not... --- t/lib/TestBuilder.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/t/lib/TestBuilder.pm b/t/lib/TestBuilder.pm index 72364e3..826ab1a 100644 --- a/t/lib/TestBuilder.pm +++ b/t/lib/TestBuilder.pm @@ -299,7 +299,11 @@ sub _gen_text { $regex = '[A-Za-z]'; } my $random = String::Random->new( max => $size ); - return $random->randregex($regex); + my $string = $random->randregex($regex); + while ( defined $size and $size > 2 and length( $string ) <= 2 ) { + $string = $random->randregex($regex); + } + return $string; } sub _gen_set_enum { -- 2.1.0