This is an automated email from the git hooks/post-receive script. intrigeri pushed a commit to branch master in repository libtest-bdd-cucumber-perl.
commit 9cd5a061f11a9eb97e704f4db3ba1b2aa1daea49 Author: Tomas Pokorny <t...@verotel.cz> Date: Wed Apr 15 06:52:17 2015 +0000 Generate stable feature/scenario IDs in JSON output so that they can be used for identify same feature/scenario in multiple JSON result files. --- lib/Test/BDD/Cucumber/Harness/JSON.pm | 9 +++++++-- t/600_harness_json_output.t | 31 ++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/lib/Test/BDD/Cucumber/Harness/JSON.pm b/lib/Test/BDD/Cucumber/Harness/JSON.pm index cf5ad01..30f5e20 100644 --- a/lib/Test/BDD/Cucumber/Harness/JSON.pm +++ b/lib/Test/BDD/Cucumber/Harness/JSON.pm @@ -104,7 +104,7 @@ sub format_feature { return { uri => $feature->name_line->filename, keyword => $self->get_keyword( $feature->name_line ), - id => "feature-" . int($feature), + id => $self->_generate_stable_id( $feature->name_line ), name => $feature->name, line => $feature->name_line->number, description => $self->format_description($feature), @@ -117,7 +117,7 @@ sub format_scenario { my ( $self, $scenario, $dataset ) = @_; return { keyword => $self->get_keyword( $scenario->line ), - id => "scenario-" . int($scenario), + id => $self->_generate_stable_id( $scenario->line ), name => $scenario->name, line => $scenario->line->number, tags => $self->format_tags( $scenario->tags ), @@ -126,6 +126,11 @@ sub format_scenario { }; } +sub _generate_stable_id { + my ( $self, $line ) = @_; + return $line->filename . ":" . $line->number; +} + sub format_step { my ( $self, $step_context, $result, $duration ) = @_; my $step = $step_context->step; diff --git a/t/600_harness_json_output.t b/t/600_harness_json_output.t index 01b86da..049be61 100644 --- a/t/600_harness_json_output.t +++ b/t/600_harness_json_output.t @@ -24,11 +24,11 @@ sub get_line_number { } } -my $json_data = ""; -my $fh = new IO::Scalar \$json_data; - # Run tests -{ +sub run_tests { + my $json_data = ""; + my $fh = new IO::Scalar \$json_data; + my $harness = Test::BDD::Cucumber::Harness::JSON->new( fh => $fh ); for my $directory ( $DIGEST_DIR, 't/harness_json' ) { my ( $executor, @features ) = @@ -37,15 +37,21 @@ my $fh = new IO::Scalar \$json_data; $executor->execute( $_, $harness ) for @features; } $harness->shutdown(); + + $fh->close; + return $json_data; } -$fh->close; +my $json_data = run_tests(); # Load & Check JSON output my $parsed_json = decode_json($json_data); is( ref($parsed_json), 'ARRAY', 'json file contains list of features' ); +# Second run results +my $second_run_json = decode_json( run_tests() ); + # Test list of features my @json_features = @$parsed_json; is( scalar(@json_features), 2, "number of features matches" ); @@ -59,7 +65,11 @@ is_deeply( my %json_feature = %{ $parsed_json->[0] }; is( $json_feature{keyword}, 'Feature', 'feature keyword' ); is( $json_feature{name}, 'Simple tests of Digest.pm', 'feature name' ); -like( $json_feature{id}, qr/^feature-\d+$/, 'feature id' ); +like( $json_feature{id}, + qr{^.*examples/tagged-digest/features/basic\.feature:\d+$}, + 'feature id' +); +is( $json_feature{id}, $second_run_json->[0]{id}, "Feature ID is stable" ); is( $json_feature{uri}, $DIGEST_FEATURE_FILE, 'feature uri' ); is( $json_feature{line}, @@ -92,7 +102,14 @@ is_deeply( my %json_scenario = %{ $json_feature{elements}[2] }; is( $json_scenario{keyword}, 'Scenario', 'scenario keyword' ); is( $json_scenario{name}, 'Check SHA-1', 'scenario name' ); -like( $json_scenario{id}, qr/^scenario-\d+$/, 'scenario id' ); +like( $json_scenario{id}, + qr{^.*examples/tagged-digest/features/basic.feature:\d+$}, + 'scenario id' +); +is( $json_scenario{id}, + $second_run_json->[0]{elements}[2]{id}, + "Scenario ID is stable" +); is( $json_scenario{line}, get_line_number( $json_feature{uri}, 'Scenario: Check SHA-1' ), -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libtest-bdd-cucumber-perl.git _______________________________________________ Pkg-perl-cvs-commits mailing list Pkg-perl-cvs-commits@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits