summaryrefslogtreecommitdiff
path: root/t/traverse.t
blob: 07543dede18d6a4d569bdd6a6f10052336096635 (plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env perl

use strict;
use warnings;
use lib 't';

use Config::Tiny;

use DBI;

use File::Temp;

use Test;
use Test::More;

use Try::Tiny;

# -----------------------------------------------

sub BEGIN { use_ok('Data::Session'); }

# -----------------------------------------------

sub run
{
	my($id, $serializer, $config, $test_count) = @_;

	my(@dsn, $directory, $type);
	my($tester);

	try
	{
		# WTF: You cannot use DBI -> parse_dsn(...) || die $msg;
		# even though that's what the docs say to do.
		# BAIL_OUT reports (e.g.): ... Error in type: Unexpected component 'sha1' ...

		@dsn = DBI -> parse_dsn($$config{dsn});

		if ($#dsn < 0)
		{
			die __PACKAGE__ . ". Can't parse dsn '$$config{dsn}'";
		}

		# The EXLOCK option is for BSD-based systems.

		$directory = File::Temp::newdir('temp.XXXX', CLEANUP => 1, EXLOCK => 0, TMPDIR => 1);
		$type      = "driver:$dsn[1];id:$id;serialize:$serializer";
		$tester    = Test -> new
		(
			directory => $directory,
			dsn       => $$config{dsn},
			dsn_attr  => $$config{attributes},
			password  => $$config{password},
			type      => $type,
			username  => $$config{username},
			verbose   => 1,
		);

		subtest $type => sub
		{
			$$test_count += $tester -> traverse;
		};
	}
	catch
	{
		# This extra call to done_testing just stops an extra error message.

		done_testing($$test_count);
		BAIL_OUT($_);
	};

} # End of run.

# -----------------------------------------------

sub report
{
	my($s) = @_;

	print STDERR "# $s\n";

} # End of report.

# -----------------------------------------------

sub string2hashref
{
	my($s)      = @_;
	$s          ||= '';
	my($result) = {};

	if ($s)
	{
		if ($s =~ m/^\{\s*([^}]*)\}$/)
		{
			my(@attr) = map{split(/\s*=>\s*/)} split(/\s*,\s*/, $1);

			if (@attr)
			{
				$result = {@attr};
			}
		}
		else
		{
			die "Invalid syntax for hashref: $s";
		}
	}

	return $result;

} # End of string2hashref.

# -----------------------------------------------

my($dsn_config) = Config::Tiny -> read('t/basic.ini');
my($test_count) = 1; # The use_ok in BEGIN counts as the first test.

my($config);
my($temp);

# We skip UUID16 since echoing such ids to the console can change the char set.

for my $id (qw/MD5/)
{
	for my $serializer (qw/DataDumper/)
	{
		for my $dsn_name (sort keys %$dsn_config)
		{
			$config              = $$dsn_config{$dsn_name};
			$$config{attributes} = string2hashref($$config{attributes});

			next if ( ($$config{active} == 0) || ($$config{use_for_testing} == 0) );

			$temp = Test -> new(dsn => $$config{dsn}, type => 'Fake');

			if ($temp -> check_sqlite_directory_exists == 0)
			{
				report("Skipping dsn '$$config{dsn}' because the SQLite directory does not exist");

				next;
			}

			report("DSN name: $dsn_name. DSN: $$config{dsn}. ID generator: $id. Serializer: $serializer");

			run($id, $serializer, $config, \$test_count);
		}
	}
}

done_testing($test_count);