Skip to content

Commit c2aa3d4

Browse files
committed
Migrate token and AST testing into 'dzil test'
1 parent 9fd1084 commit c2aa3d4

File tree

4 files changed

+74
-35
lines changed

4 files changed

+74
-35
lines changed

perl/Makefile

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ clean: ## Remove all build artifacts and files generated by the acceptance tests
4343

4444
.DELETE_ON_ERROR:
4545

46-
acceptance: .built lib/Gherkin/Generated/Languages.pm $(TOKENS) $(ASTS) $(PICKLES) $(SOURCES) $(ERRORS) ## Build acceptance test dir and compare results with reference
46+
acceptance: .built lib/Gherkin/Generated/Languages.pm $(TOKENS) $(ASTS) $(PICKLES) $(SOURCES) $(ERRORS)
47+
FEATURE_FILES_BASEDIR=$PWD/../testdata/ dzil test
4748

4849
.built: perl5 $(SOURCE_FILES)
4950
touch $@
@@ -57,16 +58,6 @@ lib/Gherkin/Generated/Languages.pm:
5758
$(GHERKIN_PARSER): $(GHERKIN_RAZOR) ../gherkin.berp
5859
berp -g ../gherkin.berp -t $< -o $@ --noBOM
5960

60-
acceptance/testdata/%.tokens: ../testdata/% ../testdata/%.tokens
61-
mkdir -p $(@D)
62-
$(GHERKIN_GENERATE_TOKENS) $< > $@
63-
diff --unified $<.tokens $@
64-
65-
acceptance/testdata/%.ast.ndjson: ../testdata/% ../testdata/%.ast.ndjson
66-
mkdir -p $(@D)
67-
$(GHERKIN) --no-source --no-pickles --predictable-ids $< | jq --sort-keys --compact-output "." > $@
68-
diff --unified <(jq "." $<.ast.ndjson) <(jq "." $@)
69-
7061
acceptance/testdata/%.pickles.ndjson: ../testdata/% ../testdata/%.pickles.ndjson
7162
mkdir -p $(@D)
7263
$(GHERKIN) --no-source --no-ast --predictable-ids $< | jq --sort-keys --compact-output "." > $@

perl/bin/gherkin-generate-tokens

Lines changed: 0 additions & 23 deletions
This file was deleted.

perl/cpanfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ on 'test' => sub {
1515
};
1616

1717
on 'develop' => sub {
18-
# there are no specific development dependencies...
18+
requires "File::Find::Rule";
19+
requires "Text::Diff";
1920
};

perl/t/010-good-features.t

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!perl
2+
3+
use strict;
4+
use warnings;
5+
6+
BEGIN {
7+
use Test2::V0;
8+
9+
skip_all 'No AUTHOR_TESTING'
10+
unless $ENV{AUTHOR_TESTING};
11+
skip_all 'Missing FEATURE_FILES_BASEDIR'
12+
unless $ENV{FEATURE_FILES_BASEDIR};
13+
}
14+
15+
use File::Find::Rule;
16+
use JSON::PP;
17+
18+
use App::gherkin;
19+
use Gherkin::Parser;
20+
use Gherkin::TokenFormatterBuilder;
21+
22+
use Test2::Tools::ClassicCompare qw/ is_deeply /;
23+
use Text::Diff;
24+
25+
my @good_features =
26+
File::Find::Rule
27+
->file()
28+
->name('*.feature')
29+
->in( File::Spec->catfile( $ENV{FEATURE_FILES_BASEDIR}, 'good' ) );
30+
31+
skip_all 'No test files found'
32+
unless @good_features;
33+
34+
35+
# Test tokens
36+
do {
37+
my $tp = Gherkin::Parser->new( Gherkin::TokenFormatterBuilder->new() );
38+
for my $feature (@good_features) {
39+
subtest "$feature tokens" => sub {
40+
my $tokens = $tp->parse( $feature );
41+
my $str = join( "\n", @{ $tokens } ) . "\n";
42+
# compare $tokens string content with content of file "$feature.tokens"
43+
my $diff = diff \$str, "$feature.tokens";
44+
45+
ok( not $diff )
46+
or diag $diff;
47+
};
48+
}
49+
};
50+
51+
# Test AST
52+
do {
53+
my $app = App::gherkin->new;
54+
$app->parse_options( qw/--no-source --no-pickles --predictable-ids/ );
55+
for my $feature (@good_features) {
56+
subtest "$feature AST" => sub {
57+
my $content;
58+
open my $fh, '>:encoding(UTF-8)', \$content;
59+
local $app->{out_handle} = $fh;
60+
$app->run( $feature );
61+
close $fh;
62+
my $diff = diff \$content, "$feature.ast.ndjson";
63+
64+
ok( not $diff )
65+
or diag $diff;
66+
};
67+
}
68+
};
69+
70+
done_testing;

0 commit comments

Comments
 (0)