4 # avoiding this prologue would be nice, but it seems to be unavoidable,
5 # see "It is also important to note ..." in perldoc threads
9 if ($Config{useithreads} && $] > 5.008007) {
21 or plan skip_all => "can't test Imager's threads support with no threads";
23 or plan skip_all => "require a perl with CLONE_SKIP to test Imager's threads support";
25 or plan skip_all => "couldn't load threads";
27 $INC{"Devel/Cover.pm"}
28 and plan skip_all => "threads and Devel::Cover don't get along";
32 -d "testout" or mkdir "testout";
34 Imager->open_log(log => "testout/t080log1.log")
35 or plan skip_all => "Cannot open log file: " . Imager->errstr;
39 Imager->log("main thread a\n");
41 my $t1 = threads->create
44 Imager->log("child thread a\n");
45 Imager->open_log(log => "testout/t080log2.log")
46 or die "Cannot open second log file: ", Imager->errstr;
47 Imager->log("child thread b\n");
49 Imager->log("child thread c\n");
55 Imager->log("main thread b\n");
57 Imager->log("main thread c\n");
58 ok($t1->join, "join child thread");
59 Imager->log("main thread d\n");
62 my %log1 = parse_log("testout/t080log1.log");
63 my %log2 = parse_log("testout/t080log2.log");
80 is_deeply(\%log1, { map {; $_ => 1 } @log1 },
81 "check messages in main thread log");
82 is_deeply(\%log2, { map {; $_ => 1 } @log2 },
83 "check messages in child thread log");
85 # grab the messages from the given log
89 open my $fh, "<", $filename
90 or die "Cannot open log file $filename: $!";
95 my ($date, $time, $file_line, $level, $message) = split ' ', $_, 5;
99 delete $lines{"Imager - log started (level = 1)"};
100 delete $lines{"Imager $Imager::VERSION starting"};
106 unlink "testout/t080log1.log", "testout/t080log2.log"
107 unless $ENV{IMAGER_KEEP_FILES};