File: 17_cache.t

package info (click to toggle)
liborlite-perl 1.97-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 524 kB
  • sloc: perl: 3,693; sql: 97; makefile: 2
file content (98 lines) | stat: -rw-r--r-- 1,942 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
93
94
95
96
97
98
#!/usr/bin/perl

# Tests the basic functionality of SQLite.

use strict;
BEGIN {
	$|  = 1;
	$^W = 1;
}

use Test::More tests => 9;
use File::Spec::Functions ':ALL';
use File::Remove 'clear';
use t::lib::Test;

# Where will the cache file be written to
my $orlite_version = $t::lib::Test::VERSION;
$orlite_version =~ s/[\._]/-/g;
my $cached = catfile( 
	"t",
	"Foo-Bar-1-23-ORLite-$orlite_version-user_version-2.pm",
);
clear($cached);
ok( ! -e $cached, 'Cache file does not initially exist' );

# Set up the database
my $file = test_db();
my $dbh  = create_ok(
	file    => catfile(qw{ t 17_cache.sql }),
	connect => [ "dbi:SQLite:$file" ],
);

# Create the test package
eval <<"END_PERL"; die $@ if $@;
package Foo::Bar;

use strict;
use vars qw{\$VERSION};
BEGIN {
	\$VERSION = '1.23';
}

use ORLite {
	file         => '$file',
	cache        => 't',
	user_version => 2,
};

1;
END_PERL

# Check some basics
$file = rel2abs($file);
is( Foo::Bar->sqlite, $file,              '->sqlite ok' );
is( Foo::Bar->dsn,    "dbi:SQLite:$file", '->dsn ok'    );

# Did the cache file get created?
ok( -f $cached, "Cache file $cached created" );
my $inc1 = scalar keys %INC;

# Delete the generated class (using hacky inlined Class::Unload)
SCOPE: {
	no strict 'refs';
	
	ok( Foo::Bar->VERSION, 'Foo::Bar exists' );
	my $symtab = "Foo::Bar::";
	@Foo::Bar::ISA = ();
	for my $symbol ( keys %$symtab ) {
		delete $symtab->{$symbol};
	}
}

# Load the class again
eval <<"END_PERL"; die $@ if $@;
package Foo::Bar;

use strict;
use vars qw{\$VERSION};
BEGIN {
	\$VERSION = '1.23';
}

use ORLite {
	file         => '$file',
	cache        => 't',
	user_version => 2,
};

1;
END_PERL

# Did it load the second time?
is( Foo::Bar->sqlite, $file,              '->sqlite ok' );
is( Foo::Bar->dsn,    "dbi:SQLite:$file", '->dsn ok'    );

# There should be one extra entry now
my $inc2 = scalar keys %INC;
is( $inc2, $inc1 + 1, '%INC is larger by one from cache' );