Menu

[b29b51]: / tests / PlainTest.pm  Maximize  Restore  History

Download this file

96 lines (70 with data), 2.2 kB

 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
93
94
95
# Test cases for the LXR::Files::Plain module
# Uses the associated lxr.conf file
package PlainTest;
use strict;
use Test::Unit;
use lib "..";
use lib "../lib";
use LXR::Files;
use LXR::Config;
use LXR::Common;
use base qw(Test::Unit::TestCase);
use vars qw($root);
$root = "/Users/malcolmbox/dev/lxr-src/";
$config = new LXR::Config("http://test/lxr", "./lxr.conf");
sub new {
my $self = shift()->SUPER::new(@_);
# $self->{config} = {};
return $self;
}
# define tests
# test that a files object can be created
sub test_creation {
my $self = shift;
$self->assert(defined($self->{'plain'}), "Failed to create Files::Plain");
$self->assert($self->{'plain'}->isa("LXR::Files::Plain"), "Not a Plain object");
}
# Access some of the values to check what is found
sub test_root {
my $self = shift;
$self->assert($self->{'plain'}->{rootpath} eq $self->{'config'}->{'dir'},
"rootpath failed $self->{plain}->{rootpath} $self->{'config'}->{'dir'}");
}
# Test the get_dir function. Depends on the ctags 5.5.4 release being in place
sub test_getdir {
my $self = shift;
my $f = $self->{'plain'};
my @files = sort($f->getdir("/",'5.5.4')); # use different releases to disambiguate
my @files2 = sort($f->getdir("", '5.5.4')); # should now produce same result
$self->assert_deep_equals(\@files, \@files2);
# Check for invalid behaviours
@files = $f->getdir("/COPYING", '5.5.4');
$self->assert($#files == -1);
@files = $f->getdir("tests", '5.5.4');
$self->assert($#files == -1);
@files = $f->getdir("notthere/", '5.5.4');
$self->assert($#files == -1);
}
# Test the get_file method.
sub test_getfile {
my $self = shift;
my $f = $self->{'plain'};
my $file = $f->getfile("/COPYING", '5.5.4');
local ($/) = undef;
open FILE, "<". "$root/5.5.4/COPYING" || die "Can't open file";
my $ref = <FILE>;
$self->assert($file eq $ref, "Files not matching");
}
# set_up and tear_down are used to
# prepare and release resources need for testing
# Prepare a config object
sub set_up {
my $self = shift;
$self->{'plain'} = new LXR::Files("$root");
$self->{'config'}->{'dir'} = "$root";
}
sub tear_down {
my $self = shift;
# $self->{config} = undef;
}
1;
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.