File: head_ok.t

package info (click to toggle)
libtest-www-mechanize-perl 1.60-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 380 kB
  • sloc: perl: 2,725; makefile: 4
file content (62 lines) | stat: -rw-r--r-- 1,799 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!perl -T

use strict;
use warnings;

use Test::More tests => 11;

use Test::WWW::Mechanize;

use Test::Builder::Tester;
use URI::file;

my $mech = Test::WWW::Mechanize->new( autocheck => 0 );
isa_ok($mech,'Test::WWW::Mechanize');

GOOD_HEAD: { # Stop giggling, you!
    my $goodlinks = URI::file->new_abs( 't/goodlinks.html' )->as_string;

    $mech->head($goodlinks);
    ok($mech->success, 'sanity check: we can load goodlinks.html');

    test_out('ok 1 - Try to HEAD goodlinks.html');
    my $ok = $mech->head_ok($goodlinks, 'Try to HEAD goodlinks.html');
    test_test('HEAD existing URI and reports success');
    is( ref($ok), '', 'head_ok() should only return a scalar' );
    ok( $ok, 'And the result should be true' );

    # default desc
    test_out("ok 1 - HEAD $goodlinks");
    $mech->head_ok($goodlinks);
    test_test('HEAD existing URI and reports success - default desc');
}

BAD_HEAD: {
    my $badurl = URI::file->new_abs('t/no-such-file');
    my $abs_path = $badurl->file;
    $mech->head( $badurl->as_string );
    ok(!$mech->success, qq{sanity check: we can't load $badurl} );

    test_out( 'not ok 1 - Try to HEAD bad URL' );
    test_fail( +4 );
    test_diag( $badurl->as_string );
    test_diag( '404' );
    test_diag( qq{File `$abs_path' does not exist} );
    my $ok = $mech->head_ok( $badurl->as_string, 'Try to HEAD bad URL' );
    test_test( 'Fails to HEAD nonexistent URI and reports failure' );

    is( ref($ok), '', 'head_ok() should only return a scalar' );
    ok( !$ok, 'And the result should be false' );
}


UNDEF_URL: {
    test_out( 'not ok 1 - Passing undef for a URL' );
    test_fail( +2 );
    test_diag( 'URL cannot be undef.' );
    my $ok = $mech->head_ok( undef, 'Passing undef for a URL' );
    test_test( 'Undef URLs' );
}


done_testing();