From 79e951e504eb22c1d7e87bf2df5c2a1c9d86d937 Mon Sep 17 00:00:00 2001 From: Emmanuel Briot Date: Mon, 10 Feb 2014 11:56:30 +0100 Subject: [PATCH] regexps for steps should not include leading 'Given|Then|...' --- src/bdd-runner.adb | 17 ++++++++++++++++- src/bdd-steps.adb | 8 ++++---- src/bdd-steps.ads | 5 +++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/bdd-runner.adb b/src/bdd-runner.adb index fef0982..49e9040 100644 --- a/src/bdd-runner.adb +++ b/src/bdd-runner.adb @@ -23,6 +23,7 @@ with Ada.Exceptions; use Ada.Exceptions; with BDD.Steps; use BDD.Steps; +with GNATCOLL.Utils; use GNATCOLL.Utils; package body BDD.Runner is @@ -150,6 +151,9 @@ package body BDD.Runner is Step : not null access Step_Record'Class) is Execute : constant Boolean := Scenario.Status = Status_Passed; + Text : constant String := Step.Text; + First : Integer := Text'First; + begin -- Run the step, or at least check whether it is defined. if Execute then @@ -158,9 +162,20 @@ package body BDD.Runner is Step.Set_Status (Status_Skipped); end if; + -- Skip the leading 'Given|Then|...' keywords, which are irrelevant + -- for the purpose of the match + + while First <= Text'Last + and then not Is_Whitespace (Text (First)) + loop + First := First + 1; + end loop; + Skip_Blanks (Text, First); + begin -- Will set status to undefined if necessary - BDD.Steps.Run_Step (Step, Execute => Execute); + BDD.Steps.Run_Step + (Step, Text (First .. Text'Last), Execute => Execute); -- if Step.Status = Status_Undefined then -- -- ??? Could run some predefined steps here -- null; diff --git a/src/bdd-steps.adb b/src/bdd-steps.adb index af1f5f6..d1e645c 100644 --- a/src/bdd-steps.adb +++ b/src/bdd-steps.adb @@ -26,11 +26,11 @@ with GNAT.Regpat; use GNAT.Regpat; package body BDD.Steps is Re_1 : constant Pattern_Matcher := Compile - ("^Given a user named '(.*)'$"); + ("^a user named '(.*)'$"); Re_2 : constant Pattern_Matcher := Compile - ("^Given I am sitting at my desk$"); + ("^I am sitting at my desk$"); Re_3 : constant Pattern_Matcher := Compile - ("^Then I should create great software$"); + ("^I should create great software$"); procedure Do_Step_1 (Name : String); procedure Do_Step_2; @@ -70,9 +70,9 @@ package body BDD.Steps is procedure Run_Step (Step : not null access BDD.Features.Step_Record'Class; + Text : String; Execute : Boolean) is - Text : constant String := Step.Text; Matches : Match_Array (0 .. 10); begin Match (Re_1, Text, Matches); diff --git a/src/bdd-steps.ads b/src/bdd-steps.ads index fc18944..58d4bd4 100644 --- a/src/bdd-steps.ads +++ b/src/bdd-steps.ads @@ -30,10 +30,15 @@ package BDD.Steps is procedure Run_Step (Step : not null access BDD.Features.Step_Record'Class; + Text : String; Execute : Boolean); -- Run a step, and sets its status. + -- -- If Execute is False, then we only check whether the step is known, but -- it is not run. No exception is raised in this mode. + -- + -- Text must be Step.Text, minus the leading 'Given|Then|...' words. + -- -- This procedure is expected to raise exceptions when a test fails. end BDD.Steps;