-
Notifications
You must be signed in to change notification settings - Fork 8
/
10test-linecache.t
executable file
·69 lines (57 loc) · 2.37 KB
/
10test-linecache.t
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
#!/usr/bin/env perl
use strict; use warnings;
use rlib '../lib';
use Test::More;
note( "Testing Devel::Trepan::DB::LineCache" );
BEGIN {
use English qw( -no_match_vars );
$PERLDB |= 0x400;
use_ok( 'Devel::Trepan::DB::LineCache' );
}
note 'Test update_script_cache';
my $lines = "now\nis\nthe\ntime";
my $script_name = '(eval 234)';
DB::LineCache::update_script_cache($script_name, {string => $lines});
my $ary_ref = $DB::LineCache::script_cache{$script_name}{lines_href}{plain};
is(join("\n", @$ary_ref), $lines);
note 'Test getlines';
my $file=__FILE__;
# my $line_count = scalar(@{"main::_<$file"});
$lines = DB::LineCache::getlines(__FILE__);
my $line_count = scalar @$lines;
ok($line_count > __LINE__, "Compare getlines count to __LINE__");
## FIXME: doesn't work:
## use Cwd 'abs_path';
## my $full_file = abs_path(__FILE__);
## $lines = DB::LineCache::getlines($full_file);
## is(scalar @$lines, $line_count, "Compare linecount for full name $full_file");
my $expected_line = 'my $line = DB::LineCache::getline(__FILE__, __LINE__);';
my $line_number = __LINE__+1;
my $line = DB::LineCache::getline(__FILE__, __LINE__);
is($line, $expected_line, "Test getline");
DB::LineCache::remap_file('another_name', __FILE__);
my $another_line = DB::LineCache::getline('another_name', $line_number);
is($another_line, $expected_line, "Test getline via remap_file");
# printf "Files cached: %s\n", join(', ', DB::LineCache::cached_files);
# DB::LineCache::update_cache(__FILE__);
## DB::LineCache::checkcache(__FILE__);
# printf "I said %s has %d lines!\n", __FILE__, DB::LineCache::size(__FILE__);
my $sha1 = DB::LineCache::sha1(__FILE__);
like($sha1, qr/^[0-9a-f]+$/, 'Got some sort of SHA1');
note 'DB::LineCache::filename_is_eval';
eval "is(DB::LineCache::filename_is_eval(__FILE__), 1, " .
"'eval(...) should pick up eval filename')";
is($EVAL_ERROR, '', 'no eval error on previous test');
is(DB::LineCache::filename_is_eval(__FILE__), '',
'__FILE__ should not be an eval filename');
is(DB::LineCache::filename_is_eval('-e'), 1,
'-e should be an eval filename');
note 'DB::LineCache::map_script';
$DB::filename = '(eval 1)';
my $eval_str = "\$x=1;\n\$y=2;\n\$z=3;\n";
my $filename = DB::LineCache::map_script($DB::filename, $eval_str);
open(FH, '<', $filename);
undef $INPUT_RECORD_SEPARATOR;
my $got_str = <FH>;
is($got_str, $eval_str, "reading contents temp file $filename");
done_testing();