Skip to content

Commit

Permalink
capture the warning in the test using Test::Warn
Browse files Browse the repository at this point in the history
  • Loading branch information
szabgab committed Jun 7, 2014
1 parent b028145 commit 9246027
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -2,6 +2,7 @@ Revision history for Perl extension Syntax::Highlight::Engine::Kate.


0.09
- Require Test::Warn for testing.
- Support case insensitive names. RT #84982 (Jeff Fearn)
- Replace use of File::Slurp with Path::Tiny (Martin McGrath)
- Spelling RT #88156 (Debian)
Expand Down
3 changes: 2 additions & 1 deletion Makefile.PL
Expand Up @@ -12,7 +12,8 @@ requires 'Path::Tiny' => '0';
requires 'Data::Dumper' => '0';
requires 'File::Basename' => '0';

test_requires 'Test::More' => '0.88';
test_requires 'Test::More' => '1.00';
test_requires 'Test::Warn' => '0.30';
test_requires 'Test::Differences' => '0.61';
test_requires 'Term::ANSIColor' => '0';

Expand Down
8 changes: 4 additions & 4 deletions lib/Syntax/Highlight/Engine/Kate.pm
Expand Up @@ -9,7 +9,7 @@ use 5.006;
our $VERSION = '0.08';
use strict;
use warnings;
use Carp;
use Carp qw(carp);
use Data::Dumper;
use File::Basename;

Expand Down Expand Up @@ -623,19 +623,19 @@ sub languagePlug {
my $matched = 0;
foreach my $key (keys(%{$self->{'syntaxes'}})) {
if (lc($key) eq lc($req)) {
warn "substituting language $key for $req";
carp "substituting language $key for $req";
$req = $key;
$matched = 1;
last;
}
}

unless ($matched) {
warn "undefined language: $req";
carp "undefined language: $req";
return undef;
}
} else {
warn "undefined language: $req";
carp "undefined language: $req";
return undef;
}
}
Expand Down
18 changes: 16 additions & 2 deletions t/10-case.t
Expand Up @@ -2,12 +2,26 @@ use strict;
use warnings;

use Test::More tests => 4;
use Test::Warn;
use Syntax::Highlight::Engine::Kate;

my $hl = new Syntax::Highlight::Engine::Kate();

is($hl->languagePlug( 'HTML'), 'HTML', 'Standard "HTML" should work');
is($hl->languagePlug( 'html'), undef, 'Standard "html" should not work');

subtest html => sub {
plan tests => 2;
my $lang;
warning_is { $lang = $hl->languagePlug( 'html') } 'undefined language: html', 'warn';
is($lang, undef, 'Standard "html" should not work');
};

is($hl->languagePlug( 'HTML', 1), 'HTML', 'Insesitive "HTML" should work');
is($hl->languagePlug( 'html', 1), 'HTML', 'Insesitive "html" should work');

subtest html_1 => sub {
plan tests => 2;
my $lang;
warning_is { $lang = $hl->languagePlug( 'html', 1) } 'substituting language HTML for html', 'warn';
is($lang, 'HTML', 'Insesitive "html" should work');
};

0 comments on commit 9246027

Please sign in to comment.