Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Test::More bug?

by jens (Pilgrim)
on Aug 30, 2002 at 04:56 UTC ( [id://194003]=perlquestion: print w/replies, xml ) Need Help??

jens has asked for the wisdom of the Perl Monks concerning the following question:

I have been working my way through the examples in Test::Tutorial and the very first example does not work as expected. At first I thought I was doing something wrong. (hey, maybe I am!) But as far as I can tell, there's no way these inputs should give these outputs. Check out the following code:

#!/usr/bin/perl -w use strict; use Test::More tests => 8; use Date::ICal; my $ical = Date::ICal->new( year => 1964, month => 10, day => 6, hour => 6, min => 12, sec => 47, tz => '0530' ); ok( defined $ical, 'new() returned something' ); ok( $ical->isa('Date::ICal'), " and it's the right class" ); is( $ical->sec , 47, ' sec()' ); is( $ical->min , 12, ' min()' ); is( $ical->hour , 16, ' hour()' ); is( $ical->day , 16, ' day()' ); is( $ical->month , 10, ' month()' ); is( $ical->year , 1964, ' year()' );

Running this code with a debugging 'perl testmore.pl' gives the following output:
[jens@dhcp32 jens]$ perl testmore.pl 1..8 ok 1 - new() returned something ok 2 - and it's the right class ok 3 - sec() ok 4 - min() not ok 5 - hour() # Failed test (testmore.pl at line 20) # got: '20' # expected: '16' not ok 6 - day() # Failed test (testmore.pl at line 21) # got: '5' # expected: '16' ok 7 - month() ok 8 - year() # Looks like you failed 2 tests of 8.
How is Test::More coming up with these values? (or is it correctly indicating a bug in Date::Ical?)

Note: if you examine this example in Test::Tutorial, you'll notice I've changed values of hour and day from 16 for both to 6. My first original test--cut and pasted out of Test::Tutorial--gave me an error on hour:
not ok 5 - hour() # Failed test (testmore.pl at line 20) # got: '6' # expected: '16'
Can anyone else verify this bug? Obviously this is a bug in the docco Test::Tutorial. But is it a bug in Test::More or in Date::Ical? (or have I done something weird?)

Replies are listed 'Best First'.
Re: Test::More bug?
by chromatic (Archbishop) on Aug 30, 2002 at 18:14 UTC

    It was actually a bug in Date::Ical that the writing of Test::Tutorial exposed. There's an explanation of this in the Test::Tutorial slides, starting around slide 37.

Re: Test::More bug?
by danichka (Hermit) on Aug 30, 2002 at 05:45 UTC
    Your tests and your data to test don't match up. With a few changes this runs fine for me.

    #!/usr/bin/perl -w use strict; use Test::More tests => 8; use Date::ICal; my $ical = Date::ICal->new( year => 1964, month => 10, day => 6, hour => 6, min => 12, sec => 47, tz => '0530' ); ok( defined $ical, 'new() returned something' ); ok( $ical->isa('Date::ICal'), " and it's the right class" ); is( $ical->sec , 47, ' sec()' ); is( $ical->min , 12, ' min()' ); is( $ical->hour , 12, ' hour()' ); #changed to 12 is( $ical->day , 6, ' day()' ); #changed to 6 is( $ical->month , 10, ' month()' ); is( $ical->year , 1964, ' year()' );


    Of Course your tz may be different from mine (and that of the author of the module) which would seem to explain the first error you got.

    use Your::Head;
      Your tests and your data to test don't match up. With a few changes this runs fine for me.

      Yes, that was the idea!

      I'm expecting it to say:"test failed: got 6"
      but instead it says "20" and "5"!
      Also, when all the values match up as they should, I still get an error. When I try cutting and pasting the precise example from 'perldoc Test::Tutorial', my actual and tested values for hour are '16' but it says it actually "got 6".!!

      use Your::Eyes;
        I'm expecting it to say:"test failed: got 6"
        but instead it says "20" and "5"!


        20 is the line number and 5 is the test number that failed.

        When I try cutting and pasting the precise example from 'perldoc Test::Tutorial', my actual and tested values for hour are '16' but it says it actually "got 6"

        Like I said last time I think this is because your timezone is different from the author's. If I am wrong hopefully someone will clear that up.

        use Your::Eyes;

        I did, but they were tired and kept trying to close on me. Seriously though my "use Your::Head;" is merely my sig and wasn't an insult nor was it directed at you. I also think that it is a little silly to downvote some of my very old nodes over this.

        use Your::Head;
Re: Test::More bug?
by projekt21 (Friar) on Aug 30, 2002 at 17:08 UTC

    Looking at Date::ICal version 1.70, it says:

    new() handles timezones. It defaults times to UTC (Green­ wich Mean Time, also called Zulu). If you want to set up a time that's in the US "Pacific" timezone, which is GMT-8, use something like:

    my $ical = Date::ICal->new( ical => '19971024T120000', offset => "-0800");
    That 'tz' has no effect for me.

    Your example gives:

    1..8 ok 1 - new() returned something ok 2 - and it's the right class ok 3 - sec() not ok 4 - min() # Failed test (test056.pl at line 19) # got: '42' # expected: '12' not ok 5 - hour() # Failed test (test056.pl at line 20) # got: '0' # expected: '16' not ok 6 - day() # Failed test (test056.pl at line 21) # got: '6' # expected: '16' ok 7 - month() ok 8 - year() # Looks like you failed 3 tests of 8.
    after changing the tz-line to
    offset => '+0530'

    This looks correct.

    P.S. My sig is no insult, too :-)

    alex pleiner <alex@zeitform.de>
    zeitform Internet Dienste

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://194003]
Approved by dws
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-19 03:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found