Test::More
kullanarak bazı testler yazıyorum ve baskıları test ettiğim işlevlerden biri STDERR
. Çıkışı STDERR
'a test etmek isterim, ancak bunun nasıl yapılacağından emin değilim. Yakın olduğumu biliyorum. Bu çalışır:STDERR'i Test :: More ile nasıl test edebilirim?
use strict;
use warnings;
use feature qw(say);
close STDERR;
open STDERR, ">", \my $error_string;
say STDERR "This is my message";
say qq(The \$error_string is equal to "$error_string");
Bu yazdırır:
The $error_string is equal to "This is my message
"
Ancak, ben STDERR kapatmak istemiyoruz. Sadece onu kopyalamak istiyorum.
Bu denedim:
use strict;
use warnings;
use feature qw(say);
open my $error_fh, ">", my $error_string;
open STDERR, ">&", $error_fh;
say STDERR "This is my message";
close $error_fh;
say qq(The \$error_string is equal to "$error_string");
Ama $error_string
boştur.
Neyi yanlış yapıyorum? (open STDERR, ">&" . fileno($error_fh)
ile birlikte) Benim için
Dang. Autodie'yi kullandığımı düşündüm, açtım. Bunu eklediğimde, '' GLOB (0x7fcb82829808) '' modunu '> &': '/ Badest tanımlayıcısı' ile ./test.pl satırında 11 'açamadım. STDERR'in yerelleştirilmesi hile yapmalıdır. –