File: 28_schemachange.t

package info (click to toggle)
libdbd-sqlite3-perl 1.76-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,004 kB
  • sloc: ansic: 167,715; perl: 1,788; pascal: 277; makefile: 9
file content (58 lines) | stat: -rw-r--r-- 1,537 bytes parent folder | download | duplicates (3)
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
# This test works, but as far as I can tell this doesn't actually test
# the thing that the test was originally meant to test.

use strict;
use warnings;
use Test::More;
use lib "t/lib";
use SQLiteTest;
use if -d ".git", "Test::FailWarnings";

my $create1 = 'CREATE TABLE table1 (id INTEGER NOT NULL, name CHAR (64) NOT NULL)';
my $create2 = 'CREATE TABLE table2 (id INTEGER NOT NULL, name CHAR (64) NOT NULL)';
my $drop1   = 'DROP TABLE table1';
my $drop2   = 'DROP TABLE table2';

# diag("Parent connecting... ($$)\n");
SCOPE: {
	my $dbh = connect_ok( dbfile => 'foo' );
	ok( $dbh->do($create1), $create1 );
	ok( $dbh->do($create2), $create2 );
	ok( $dbh->disconnect, '->disconnect ok' );
}
my $dbfile = dbfile('foo');

my $pid;
# diag("Forking... ($$)");
if ( not defined( $pid = fork() ) ) {
	die("fork: $!");

} elsif ( $pid == 0 ) {
	# Pause to let the parent connect
	sleep(2);

	# diag("Child starting... ($$)");
	my $dbh = DBI->connect(
		"dbi:SQLite:dbname=$dbfile", '', ''
	) or die 'connect failed';
	$dbh->do($drop2) or die "DROP ok";
	$dbh->disconnect or die "disconnect ok";
	# diag("Child exiting... ($$)");

	exit(0);

}

SCOPE: {
	# Parent process
	my $dbh = connect_ok( dbfile => 'foo' );
	# diag("Waiting for child... ($$)");
	ok( waitpid($pid, 0) != -1, "waitpid" );

	# Make sure the child actually deleted table2
	ok( $dbh->do($drop1),   $drop1   ) or diag("Error: '$DBI::errstr'");
	ok( $dbh->do($create2), $create2 ) or diag("Error: '$DBI::errstr'");
	ok( $dbh->disconnect, '->disconnect ok' );
}

done_testing;