Skip to content

Commit d73f942

Browse files
committed
test: Convert to Capture::Tiny
1 parent 8b3304d commit d73f942

File tree

3 files changed

+15
-33
lines changed

3 files changed

+15
-33
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
Module::Build::Tiny
3232
Devel::Cover
3333
Devel::Cover::Report::Html
34-
IO::Capture::Stderr
34+
Capture::Tiny
3535
Hash::Merge
3636
Text::Hunspell
3737
" |sort|xargs)"

t/DictionaryCoverage.t

+10-21
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use warnings;
66
use File::Temp qw/ tempfile tempdir /;
77
use File::Basename;
88
use Test::More;
9-
use IO::Capture::Stderr;
9+
use Capture::Tiny ':all';
1010
plan tests => 11;
1111
use_ok('CheckSpelling::DictionaryCoverage');
1212

@@ -84,34 +84,24 @@ is($output2, "1-4-0-other:$one_match_name [other:$one_match_name]($one_match) (4
8484

8585
($fh, $filename) = tempfile();
8686
close $fh;
87-
my $capture = IO::Capture::Stderr->new();
88-
$capture->start();
89-
CheckSpelling::DictionaryCoverage::main($filename, "no-such-file");
90-
$capture->stop();
91-
is((join "\n", $capture->read()), "Couldn't open dictionary \`no-such-file\` (dictionary-not-found)
87+
my ($stdout, $stderr, @result);
88+
($stdout, $stderr, @result) = capture { CheckSpelling::DictionaryCoverage::main($filename, "no-such-file"); };
89+
is($stderr, "Couldn't open dictionary \`no-such-file\` (dictionary-not-found)
9290
", 'dictionary-not-found');
9391

94-
$capture = IO::Capture::Stderr->new();
95-
$capture->start();
96-
CheckSpelling::DictionaryCoverage::main("/dev/no-such-file", ());
97-
$capture->stop();
98-
is((join "\n", $capture->read()), 'Could not read /dev/no-such-file
92+
($stdout, $stderr, @result) = capture { CheckSpelling::DictionaryCoverage::main("/dev/no-such-file", ()); };
93+
is($stderr, 'Could not read /dev/no-such-file
9994
', 'no-such-file');
10095

101-
$capture = IO::Capture::Stderr->new();
102-
$capture->start();
103-
CheckSpelling::DictionaryCoverage::main($filename, "/dev/no-such-file.dic");
104-
$capture->stop();
105-
my $dictionary_coverage = (join "\n", $capture ? $capture->read() : ());
96+
($stdout, $stderr, @result) = capture { CheckSpelling::DictionaryCoverage::main($filename, "/dev/no-such-file.dic"); };
97+
my $dictionary_coverage = $stderr;
10698
if ($dictionary_coverage =~ /hunspell-unavailable/) {
10799
is($dictionary_coverage, 'Could not load Text::Hunspell for `/dev/no-such-file.dic` (hunspell-unavailable)
108100
', 'no-such-file');
109101
} else {
110102
is($dictionary_coverage, "Couldn't open dictionary `/dev/no-such-file.dic` (dictionary-not-found)
111103
", 'no-such-file');
112104
}
113-
$capture = IO::Capture::Stderr->new();
114-
$capture->start();
115105
($fh, $filename) = tempfile();
116106
print $fh 'world
117107
hello
@@ -120,9 +110,8 @@ worked
120110
something
121111
';
122112
close $fh;
123-
CheckSpelling::DictionaryCoverage::main($filename, 't/sample.dic');
124-
$capture->stop();
125-
$dictionary_coverage = (join "\n", $capture ? $capture->read() : ());
113+
($stdout, $stderr, @result) = capture { CheckSpelling::DictionaryCoverage::main($filename, 't/sample.dic'); };
114+
$dictionary_coverage = $stderr;
126115
if ($dictionary_coverage =~ /hunspell-unavailable/) {
127116
is($dictionary_coverage, 'Could not load Text::Hunspell for `t/sample.dic` (hunspell-unavailable)
128117
', 'hunspell-unavailable')

t/SpellingCollator.t

+4-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use strict;
44
use warnings;
55

66
use File::Temp qw/ tempfile tempdir /;
7-
use IO::Capture::Stderr;
7+
use Capture::Tiny ':all';
88

99
use Test::More;
1010
plan tests => 34;
@@ -35,18 +35,12 @@ sub stage_test {
3535
sub run_test {
3636
my ($directories) = @_;
3737
my $output = '';
38-
open(my $outputFH, '>', \$output) or die; # This shouldn't fail
39-
my $oldFH = select $outputFH;
40-
my $capture = IO::Capture::Stderr->new();
41-
$capture->start();
42-
{
38+
my ($stdout, $stderr, @result) = capture {
4339
open my $fh, "<", \$directories;
4440
local *ARGV = $fh;
4541
CheckSpelling::SpellingCollator::main();
46-
}
47-
$capture->stop();
48-
select $oldFH;
49-
return ($output, (join "\n", $capture->read()));
42+
};
43+
return ($stdout, $stderr);
5044
}
5145

5246
sub read_file {
@@ -117,7 +111,6 @@ my $directories = "$directory
117111
fill_file($early_warnings, "goose (animal)\n");
118112
my ($output, $error_lines) = run_test($directories);
119113
is($error_lines, 'Not a directory: /dev/null
120-
121114
Could not find: /dev/no-such-dev
122115
');
123116
check_output_file($warning_output, 'goose (animal)

0 commit comments

Comments
 (0)