-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate token and AST testing into 'dzil test'
- Loading branch information
1 parent
9fd1084
commit 79bebc7
Showing
4 changed files
with
74 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
BEGIN { | ||
use Test2::V0; | ||
|
||
skip_all 'No AUTHOR_TESTING' | ||
unless $ENV{AUTHOR_TESTING}; | ||
skip_all 'Missing FEATURE_FILES_BASEDIR' | ||
unless $ENV{FEATURE_FILES_BASEDIR}; | ||
} | ||
|
||
use File::Find::Rule; | ||
use JSON::PP; | ||
|
||
use App::gherkin; | ||
use Gherkin::Parser; | ||
use Gherkin::TokenFormatterBuilder; | ||
|
||
use Test2::Tools::ClassicCompare qw/ is_deeply /; | ||
use Text::Diff; | ||
|
||
my @good_features = | ||
File::Find::Rule | ||
->file() | ||
->name('*.feature') | ||
->in( File::Spec->catfile( $ENV{FEATURE_FILES_BASEDIR}, 'good' ) ); | ||
|
||
skip_all 'No test files found' | ||
unless @good_features; | ||
|
||
|
||
# Test tokens | ||
do { | ||
my $tp = Gherkin::Parser->new( Gherkin::TokenFormatterBuilder->new() ); | ||
for my $feature (@good_features) { | ||
subtest "$feature tokens" => sub { | ||
my $tokens = $tp->parse( $feature ); | ||
my $str = join( "\n", @{ $tokens } ) . "\n"; | ||
# compare $tokens string content with content of file "$feature.tokens" | ||
my $diff = diff \$str, "$feature.tokens"; | ||
|
||
ok( not $diff ) | ||
or diag $diff; | ||
}; | ||
} | ||
}; | ||
|
||
# Test AST | ||
do { | ||
my $app = App::gherkin->new; | ||
$app->parse_options( qw/--no-source --no-pickles --predictable-ids/ ); | ||
for my $feature (@good_features) { | ||
subtest "$feature AST" => sub { | ||
my $content; | ||
open my $fh, '>:encoding(UTF-8)', \$content; | ||
local $app->{out_handle} = $fh; | ||
$app->run( $feature ); | ||
close $fh; | ||
my $diff = diff \$content, "$feature.ast.ndjson"; | ||
|
||
ok( not $diff ) | ||
or diag $diff; | ||
}; | ||
} | ||
}; | ||
|
||
done_testing; |