diff --git a/src/bdd-features.adb b/src/bdd-features.adb
index e131855..2619a98 100644
--- a/src/bdd-features.adb
+++ b/src/bdd-features.adb
@@ -378,13 +378,24 @@ package body BDD.Features is
----------------
procedure Set_Status
- (Self : not null access Step_Record;
- Status : BDD.Scenario_Status)
+ (Self : not null access Step_Record;
+ Status : BDD.Scenario_Status;
+ Error_Msg : String := "")
is
begin
Self.Status := Status;
+ Self.Error_Msg := To_Unbounded_String (Error_Msg);
end Set_Status;
+ ---------------
+ -- Error_Msg --
+ ---------------
+
+ function Error_Msg (Self : not null access Step_Record) return String is
+ begin
+ return To_String (Self.Error_Msg);
+ end Error_Msg;
+
------------
-- Status --
------------
diff --git a/src/bdd-features.ads b/src/bdd-features.ads
index a0b0e31..d7d18a8 100644
--- a/src/bdd-features.ads
+++ b/src/bdd-features.ads
@@ -60,10 +60,12 @@ package BDD.Features is
-- Return the components of the step
procedure Set_Status
- (Self : not null access Step_Record;
- Status : BDD.Scenario_Status);
+ (Self : not null access Step_Record;
+ Status : BDD.Scenario_Status;
+ Error_Msg : String := "");
function Status
(Self : not null access Step_Record) return BDD.Scenario_Status;
+ function Error_Msg (Self : not null access Step_Record) return String;
-- Set the status for a specific step
-------------
@@ -149,6 +151,7 @@ private
Line : Positive;
Text : Ada.Strings.Unbounded.Unbounded_String;
Multiline : Ada.Strings.Unbounded.Unbounded_String;
+ Error_Msg : Ada.Strings.Unbounded.Unbounded_String;
Status : BDD.Scenario_Status;
Table : BDD.Tables.Table;
end record;
diff --git a/src/bdd-formatters.adb b/src/bdd-formatters.adb
index f0db505..df3dc85 100644
--- a/src/bdd-formatters.adb
+++ b/src/bdd-formatters.adb
@@ -259,6 +259,25 @@ package body BDD.Formatters is
Scenario : BDD.Features.Scenario;
Step : not null access BDD.Features.Step_Record'Class)
is
+ procedure Indent (Text : String);
+ -- Display text on multiple lines, and indent each line as needed
+
+ procedure Indent (Text : String) is
+ Start, Last : Integer;
+ begin
+ Start := Text'First;
+ while Start <= Text'Last loop
+ Last := Line_End (Text, Start);
+ if Last < Start then -- empty line
+ New_Line;
+ Start := Last + 2;
+ else
+ Put (" " & Text (Start .. Last));
+ Start := Last + 1;
+ end if;
+ end loop;
+ end Indent;
+
begin
Self.Term.Set_Color
(Term => Ada.Text_IO.Standard_Output,
@@ -282,35 +301,33 @@ package body BDD.Formatters is
declare
Multi : constant String := Step.Multiline;
- Start, Last : Integer;
begin
if Multi /= "" then
Self.Term.Set_Color
(Term => Ada.Text_IO.Standard_Output,
Foreground => BDD.Step_Colors (Step.Status));
Put_Line (" """"""");
-
- Start := Multi'First;
- while Start <= Multi'Last loop
- Last := Line_End (Multi, Start);
- if Last < Start then -- empty line
- New_Line;
- Start := Last + 2;
- else
- Put (" " & Multi (Start .. Last));
- Start := Last + 1;
- end if;
- end loop;
-
+ Indent (Multi);
Put_Line (" """"""");
end if;
+ end;
- if Step.Table /= No_Table then
+ if Step.Table /= No_Table then
+ Self.Term.Set_Color
+ (Term => Ada.Text_IO.Standard_Output,
+ Foreground => BDD.Step_Colors (Step.Status));
+ Step.Table.Display
+ (Ada.Text_IO.Standard_Output, Prefix => " ");
+ end if;
+
+ declare
+ Msg : constant String := Step.Error_Msg;
+ begin
+ if Msg /= "" then
Self.Term.Set_Color
(Term => Ada.Text_IO.Standard_Output,
Foreground => BDD.Step_Colors (Step.Status));
- Step.Table.Display
- (Ada.Text_IO.Standard_Output, Prefix => " ");
+ Indent (Msg);
end if;
end;
diff --git a/src/bdd-runner.adb b/src/bdd-runner.adb
index 5033bb2..e87bcab 100644
--- a/src/bdd-runner.adb
+++ b/src/bdd-runner.adb
@@ -21,6 +21,9 @@
-- --
------------------------------------------------------------------------------
+with Ada.Exceptions; use Ada.Exceptions;
+with BDD.Steps; use BDD.Steps;
+
package body BDD.Runner is
--------------
@@ -144,23 +147,29 @@ package body BDD.Runner is
procedure Run_Step
(Scenario : BDD.Features.Scenario;
- Step : not null access Step_Record'Class) is
+ Step : not null access Step_Record'Class)
+ is
+ Status : Scenario_Status;
begin
case Scenario.Status is
when Status_Passed =>
- -- ??? Simulate a run
- -- delay 0.2;
- if Step.Line >= 25 and then Step.Line <= 26 then
- Step.Set_Status (Status_Passed);
- elsif Step.Line = 47 then
- Step.Set_Status (Status_Failed);
- elsif Step.Line = 13 then
- Step.Set_Status (Status_Undefined);
- elsif Step.Line = 7 then
- Step.Set_Status (Status_Passed);
- else
- Step.Set_Status (Status_Passed);
- end if;
+ Step.Set_Status (Status_Passed);
+
+ begin
+ Status := BDD.Steps.Run_Step (Step.Text);
+
+-- if Status = Status_Undefined then
+-- -- ??? Could run some predefined steps here
+-- null;
+-- end if;
+
+ Step.Set_Status (Status);
+
+ exception
+ when E : others =>
+ Step.Set_Status
+ (Status_Failed, Exception_Information (E));
+ end;
if Show_Steps then
Self.Steps_Stats (Step.Status) :=
diff --git a/src/bdd-steps.adb b/src/bdd-steps.adb
new file mode 100644
index 0000000..d9e2d60
--- /dev/null
+++ b/src/bdd-steps.adb
@@ -0,0 +1,77 @@
+-----------------------------------------------------------------------------
+-- G N A T C O L L --
+-- --
+-- Copyright (C) 2014, AdaCore --
+-- --
+-- This library is free software; you can redistribute it and/or modify it --
+-- under terms of the GNU General Public License as published by the Free --
+-- Software Foundation; either version 3, or (at your option) any later --
+-- version. This library is distributed in the hope that it will be useful, --
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
+-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. --
+-- --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception, --
+-- version 3.1, as published by the Free Software Foundation. --
+-- --
+-- You should have received a copy of the GNU General Public License and --
+-- a copy of the GCC Runtime Library Exception along with this program; --
+-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
+-- . --
+-- --
+------------------------------------------------------------------------------
+
+with GNAT.Regpat; use GNAT.Regpat;
+
+package body BDD.Steps is
+
+ Re_1 : constant Pattern_Matcher := Compile
+ ("^Given a user named '(.*)'$");
+ Re_2 : constant Pattern_Matcher := Compile
+ ("^Given I am sitting at my desk$");
+
+ procedure Do_Step_1 (Name : String);
+ procedure Do_Step_2;
+
+ ---------------
+ -- Do_Step_1 --
+ ---------------
+
+ procedure Do_Step_1 (Name : String) is
+ pragma Unreferenced (Name);
+ begin
+ null;
+ end Do_Step_1;
+
+ ---------------
+ -- Do_Step_2 --
+ ---------------
+
+ procedure Do_Step_2 is
+ begin
+ raise Constraint_Error;
+ end Do_Step_2;
+
+ --------------
+ -- Run_Step --
+ --------------
+
+ function Run_Step (Step : String) return Scenario_Status is
+ Matches : Match_Array (0 .. 20);
+ begin
+ Match (Re_1, Step, Matches);
+ if Matches (0) /= No_Match then
+ Do_Step_1 (Name => Step (Matches (1).First .. Matches (1).Last));
+ return Status_Passed;
+ end if;
+
+ Match (Re_2, Step, Matches);
+ if Matches (0) /= No_Match then
+ Do_Step_2;
+ return Status_Passed;
+ end if;
+
+ return Status_Undefined;
+ end Run_Step;
+
+end BDD.Steps;
diff --git a/src/bdd-steps.ads b/src/bdd-steps.ads
new file mode 100644
index 0000000..a1df7e0
--- /dev/null
+++ b/src/bdd-steps.ads
@@ -0,0 +1,33 @@
+-----------------------------------------------------------------------------
+-- G N A T C O L L --
+-- --
+-- Copyright (C) 2014, AdaCore --
+-- --
+-- This library is free software; you can redistribute it and/or modify it --
+-- under terms of the GNU General Public License as published by the Free --
+-- Software Foundation; either version 3, or (at your option) any later --
+-- version. This library is distributed in the hope that it will be useful, --
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
+-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. --
+-- --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception, --
+-- version 3.1, as published by the Free Software Foundation. --
+-- --
+-- You should have received a copy of the GNU General Public License and --
+-- a copy of the GCC Runtime Library Exception along with this program; --
+-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
+-- . --
+-- --
+------------------------------------------------------------------------------
+
+-- This package provides support for matching steps with actual subprograms
+-- registered by the user
+
+package BDD.Steps is
+
+ function Run_Step (Step : String) return Scenario_Status;
+ -- Run a step.
+ -- This procedure is expected to raise exceptions when a test fails.
+
+end BDD.Steps;
diff --git a/src/bdd-tables.ads b/src/bdd-tables.ads
index eec81cb..75054a5 100644
--- a/src/bdd-tables.ads
+++ b/src/bdd-tables.ads
@@ -21,6 +21,9 @@
-- --
------------------------------------------------------------------------------
+-- This package provides support for manipulating, comparing and displaying
+-- tables.
+
with Ada.Containers.Indefinite_Vectors;
with Ada.Containers.Vectors;
with Ada.Text_IO; use Ada.Text_IO;