@@ -39,7 +39,8 @@ package body Tester.Tests is
3939 type Command_Kind is (Start, Stop, Send, Shell, Comment);
4040
4141 procedure Do_Start
42- (Self : in out Test'Class);
42+ (Self : in out Test'Class;
43+ Command : GNATCOLL.JSON.JSON_Value);
4344
4445 procedure Do_Stop
4546 (Self : in out Test'Class;
@@ -53,10 +54,11 @@ package body Tester.Tests is
5354 (Self : in out Test'Class;
5455 Command : GNATCOLL.JSON.JSON_Value);
5556
56- function Wait_Factor return Integer;
57- -- Return the factor to multiply the delays with - useful for valgrind
58- -- runs. This is an integer read from the environment variable
59- -- $ALS_WAIT_FACTOR if it is defined.
57+ function Wait_Factor (Command : GNATCOLL.JSON.JSON_Value) return Integer;
58+ -- Return the factor to multiply the delays with - useful for valgrind runs
59+ -- or commands that take longer time.
60+ -- This is an integer read from either the "waitFactor" field of Command
61+ -- (if any) or the $ALS_WAIT_FACTOR environment variable (if any).
6062
6163 function Is_Has_Pattern (List : GNATCOLL.JSON.JSON_Array) return Boolean;
6264 -- Check if List in form of ["<HAS>", item1, item2, ...]
@@ -124,6 +126,7 @@ package body Tester.Tests is
124126 Request : constant GNATCOLL.JSON.JSON_Value := Command.Get (" request" );
125127 Wait : constant GNATCOLL.JSON.JSON_Array := Command.Get (" wait" ).Get;
126128 Sort : constant GNATCOLL.JSON.JSON_Value := Command.Get (" sortReply" );
129+
127130 Text : constant Ada.Strings.Unbounded.Unbounded_String :=
128131 Request.Write;
129132
@@ -139,7 +142,7 @@ package body Tester.Tests is
139142 exit when GNATCOLL.JSON.Length (Self.Waits) = 0 ;
140143
141144 Total_Milliseconds_Waited := Total_Milliseconds_Waited + Timeout;
142- if Total_Milliseconds_Waited > Max_Wait * Wait_Factor
145+ if Total_Milliseconds_Waited > Max_Wait * Wait_Factor (Command)
143146 and then not Self.In_Debug
144147 then
145148 declare
@@ -351,7 +354,8 @@ package body Tester.Tests is
351354 -- ------------
352355
353356 procedure Do_Start
354- (Self : in out Test'Class)
357+ (Self : in out Test'Class;
358+ Command : GNATCOLL.JSON.JSON_Value)
355359 is
356360 function Program_Name (Path : String) return String;
357361 -- Return full path to an exacutable designated by Path
@@ -371,25 +375,28 @@ package body Tester.Tests is
371375 end if ;
372376 end Program_Name ;
373377
374- Command_Line : constant GNAT.OS_Lib.String_Access := Getenv (" ALS" );
375-
376- Args : Spawn.String_Vectors.UTF_8_String_Vector;
378+ Command_Line : constant JSON_Array := Command.Get (" cmd" ).Get;
379+ ALS_Var : constant GNAT.OS_Lib.String_Access := Getenv (" ALS" );
380+ ALS_Exe : constant String :=
381+ (if ALS_Var /= null then ALS_Var.all else " " );
382+ Args : Spawn.String_Vectors.UTF_8_String_Vector;
377383 begin
378- if Command_Line = null or else Command_Line. all = " " then
384+ if ALS_Exe = " " then
379385 raise Program_Error with
380386 " You must specify the language server command line in $ALS" ;
381387 end if ;
382388
383- declare
384- Splits : constant Unbounded_String_Array :=
385- Split (Command_Line.all , ' ' );
386- begin
387- Self.Set_Program (Program_Name (To_String (Splits (Splits'First))));
389+ -- Set the program using $ALS env variable
390+ Self.Set_Program (Program_Name (ALS_Exe));
388391
389- for J in Splits'First + 1 .. Splits'Last loop
390- Args.Append (To_String (Splits (J)));
391- end loop ;
392- end ;
392+ -- Set the arguments using the 'cmd' field. Skip the first one, since
393+ -- it's "${ALS}".
394+ for J in
395+ GNATCOLL.JSON.Array_First (Command_Line) + 1 ..
396+ GNATCOLL.JSON.Length (Command_Line)
397+ loop
398+ Args.Append (GNATCOLL.JSON.Get (Command_Line, J).Get);
399+ end loop ;
393400
394401 Self.Set_Arguments (Args);
395402 Self.Start;
@@ -781,7 +788,7 @@ package body Tester.Tests is
781788
782789 case Kind is
783790 when Start =>
784- Self.Do_Start;
791+ Self.Do_Start (Value) ;
785792 when Stop =>
786793 Self.Do_Stop (Value);
787794 when Send =>
@@ -802,7 +809,7 @@ package body Tester.Tests is
802809 select
803810 accept Cancel;
804811 or
805- delay 20.0 * Wait_Factor;
812+ delay 20.0 * Wait_Factor (Command) ;
806813
807814 Ada.Text_IO.Put_Line (" Timeout on command:" );
808815 Ada.Text_IO.Put_Line (Command.Write);
@@ -845,14 +852,26 @@ package body Tester.Tests is
845852 -- Wait_Factor --
846853 -- ---------------
847854
848- function Wait_Factor return Integer is
849- Factor : constant GNAT.OS_Lib.String_Access
855+ function Wait_Factor (Command : GNATCOLL.JSON.JSON_Value) return Integer is
856+ Command_Factor : constant String :=
857+ (if Command.Has_Field (" waitFactor" ) then
858+ Command.Get (" waitFactor" )
859+ else
860+ " " );
861+ Env_Factor : constant GNAT.OS_Lib.String_Access
850862 := Getenv (" ALS_WAIT_FACTOR" );
863+ Factor : constant String :=
864+ (if Command_Factor /= " " then
865+ Command_Factor
866+ elsif Env_Factor /= null then
867+ Env_Factor.all
868+ else
869+ " " );
851870 begin
852- if Factor = null or else Factor. all = " " then
871+ if Factor = " " then
853872 return 1 ;
854873 else
855- return Integer'Value (Factor. all );
874+ return Integer'Value (Factor);
856875 end if ;
857876 end Wait_Factor ;
858877
0 commit comments