File: 2-with-log-any.t

package info (click to toggle)
liblog-any-adapter-filehandle-perl 0.010-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 108 kB
  • sloc: perl: 70; makefile: 2
file content (46 lines) | stat: -rw-r--r-- 1,037 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
use Log::Any qw($log);
use Test::More;
use IO::File;
use IO::String;

plan tests => 5;

{ 
	my $str = IO::String->new();
	Log::Any->set_adapter('FileHandle', fh=>$str);
	$log->info("test");

	is(${$str->string_ref},"[info] test\n", "Testing to in memory IO::String filehandle");
}
{ 
	my $str = IO::String->new();
	Log::Any->set_adapter('FileHandle', fh=>$str, format=>"|%s| %s");
	$log->info("test");

	is(${$str->string_ref},"|info| test", "Testing to in memory IO::String filehandle & Format");
}
{
	
	my $fh = IO::File->new_tmpfile();
	Log::Any->set_adapter('FileHandle', fh=>$fh);
	$log->info("test");
	$fh->seek(0,0);
	my $message = $fh->getline;
	
	is($message,"[info] test\n","Message to temporary file");
	$fh->close();
}

{
	my $fh = IO::File->new_tmpfile();
	Log::Any->set_adapter('FileHandle', fh=>$fh);

	ok($fh->autoflush, "Testing autoflush is turned on");
}

{
	my $fh = IO::File->new_tmpfile();
	Log::Any->set_adapter('FileHandle', fh=>$fh, no_autoflush=>1);

	ok(! $fh->autoflush, "Testing autoflush is turned off");
}