File: 20_errmode.t

package info (click to toggle)
net-telnet-cisco 1.10-5.3
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 160 kB
  • ctags: 32
  • sloc: perl: 792; makefile: 52
file content (92 lines) | stat: -rw-r--r-- 2,363 bytes parent folder | download | duplicates (4)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# -*- perl -*-

#use Test::More qw/no_plan/;
use Test::More tests => 17;

use Net::Telnet::Cisco;
use FindBin;
use Carp;
use t::Utils;

my %G = load();
my $S;

SKIP: {
    skip("Router unknown", 1) 		unless $G{ROUTER};
    skip("Login or password unknown", 1)	unless $G{LOGIN} || $G{PASSWD};

    ok $S = Net::Telnet::Cisco->new( Errmode	 => \&confess,
				     Host	 => $G{ROUTER},
				     Timeout => 3,
				    log_args(),
				   ),				"new()";
}

SKIP: {
    skip("No Net::Telnet::Cisco session", 11) unless $S;

    ok $S->login(Name     => $G{LOGIN},
		 Password => $G{PASSWD},
		 Passcode => $G{PASSCODE},),			"login()";

    @help = show_help($S);
    ok @help,							"cmd()";
    ok $S->cmd("\b" x 6),				 	"show ? cleanup";

    $donttouch = 'virgin';
    ok $S->errmode( sub { $donttouch = 'hussy'} ),		"errmode closure";
    is $donttouch, 'virgin',					"errmode shouldn't eval CODE";

    # breaks
    my $errmsg = '';
    sub handler {
	$errmsg = $S->errmsg;
	$S->timed_out(0); 
	$S->timeout(10);
	$S->ios_break;
    }
    ok $S->errmode( \&handler ),	 			"set errmode(errmode())";

    # Turn off autopaging. This will display a more prompt, thus pausing until we timeout.
    is $S->autopage(0), 0,					"turn off autopage";

    $S->timeout(10);

    local $SIG{'__DIE__'} = \&confess;
    @short = show_help($S);

    like $errmsg, "/timed-out/",				"error reports a timeout";
    ok @short <= @help,						"ios_break()";

    # XXX search log for "\cZ"

    is $S->autopage(1), 1, 					"turn on autopage";
    ok $S->cmd("\b" x 6),				 	"show ? cleanup";

    # Error handling
    my $seen = 0;
    ok $S->timeout(3),						"set timeout(1)";

    sub incr { $seen++ }

    ok $S->errmode(\&incr),	 				"set errmode(closure)";
    $S->cmd(  "Small_Change_got_rained_on_with_his_own_thirty_eight"
	    . "_And_nobody_flinched_down_by_the_arcade");

    # $seen should be incrememnted to 1.
    is $seen, 1,						"error() called";

    # $seen should not be incremented (it should remain 1)
    ok $S->errmode('return'),					"no errmode()";
    $S->cmd(  "Brother_my_cup_is_empty_"
	    . "And_I_havent_got_a_penny_"
	    . "For_to_buy_no_more_whiskey_"
	    . "I_have_to_go_home");
    is $seen, 1,						"don't call error()";
}

END {
   cleanup(savelogs => $G{SAVELOGS},
		   failed => scalar grep {$_ == 0} Test::More->builder->summary,
		  );
};