[grand-rapids-pm-list] Perl Date Validator Test Chokes!

grand-rapids-pm-list at pm.org grand-rapids-pm-list at pm.org
Fri May 1 11:56:39 PDT 2009


Today I noticed a test failing in a piece of old code that tests a date validator. After some quick debugging, I found the problem. Can you find what is wrong with the second test below? (Btw, you can't actually run the code below, as I'm only including the tests from the pod.) Hint: It worked yesterday! How would you fix it? I'll share my solution a bit later.

    use Test::Exception;

    # TEST 1 valid date, in the future
    $q->param("${field}", '01/01/3005');
    lives_ok {
        %ret = $date_v->validate;
    } 'Valid date validated';
    isnt($ret{'valid'}, 1, '> 6 months ago date validated correctly');
    like($ret{'error'}, qr/\w+/, 'Correct error message returned.');

    # TEST 2 valid date
    my @time = localtime(time - 86400); # yesterday
    my $date = sprintf('%02d/%02d/%04d', $time[4] + 1, $time[3] + 1, $time[5] + 1900);
    diag("Date: $date");
    $q->param("${field}", $date);
    lives_ok {
        %ret = $date_v->validate;
    } 'Valid date validated';
    is($ret{'valid'}, 1, 'Valid date validated correctly');



Ed Eddington
Gr.pm

** ** **  PRIVILEGED AND CONFIDENTIAL  ** ** **
This email transmission contains privileged and confidential information intended only for the use of the individual(s) or entity named above.  Any unauthorized review, use, disclosure or distribution is prohibited and may be a violation of law.  If you are not the intended recipient or a person responsible for delivering this message to an intended recipient, please delete the email and immediately notify the sender via the email return address or mailto:postmaster at priorityhealth.com.  Thank you.




More information about the grand-rapids-pm-list mailing list