11-- ----------------------------------------------------------------------------
22-- Language Server Protocol --
33-- --
4- -- Copyright (C) 2018-2019 , AdaCore --
4+ -- Copyright (C) 2018-2023 , AdaCore --
55-- --
66-- This is free software; you can redistribute it and/or modify it under --
77-- terms of the GNU General Public License as published by the Free Soft- --
@@ -21,35 +21,72 @@ with Ada.Strings.Unbounded;
2121with Ada.Text_IO ;
2222with GNATCOLL.JSON ;
2323
24- with Tester.Macros ;
25- with Tester.Tests ;
24+ with VSS.Command_Line ;
25+ with VSS.Strings ;
26+ with VSS.Strings.Conversions ;
27+ with VSS.String_Vectors ;
2628
2729with Spawn.Environments ;
2830
31+ with Tester.Macros ;
32+ with Tester.Tests ;
33+
2934procedure Tester.Run is
35+
36+ package Options is
37+ -- Command line options and arguments
38+
39+ Debug : constant VSS.Command_Line.Binary_Option :=
40+ (Short_Name => " d" ,
41+ Long_Name => " debug" ,
42+ Description => " disable timeouts then pause after server start" );
43+
44+ On_Hang : constant VSS.Command_Line.Value_Option :=
45+ (Short_Name => " " ,
46+ Long_Name => " on-hang-script" ,
47+ Value_Name => " command_and_args" ,
48+ Description => " the command to launch if the test hangs" );
49+
50+ File : constant VSS.Command_Line.Positional_Option :=
51+ (Name => " test.json" ,
52+ Description => " JSON test script" );
53+ end Options ;
54+
3055 Env : constant Spawn.Environments.Process_Environment :=
3156 Spawn.Environments.System_Environment;
3257
3358 JSON : GNATCOLL.JSON.JSON_Value;
3459begin
35- if not (Ada.Command_Line.Argument_Count = 1
36- or else (Ada.Command_Line.Argument_Count = 2
37- and then Ada.Command_Line.Argument (1 ) = " --debug" ))
38- then
39- Ada.Text_IO.Put_Line (" Usage:" );
40- Ada.Text_IO.Put_Line
41- (" " & Ada.Command_Line.Command_Name & " [options] test.json" );
42- Ada.Text_IO.New_Line;
43- Ada.Text_IO.Put_Line (" Options are:" );
44- Ada.Text_IO.Put_Line
45- (" --debug disable timeouts and pause after server start" );
46- Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
47- return ;
60+ VSS.Command_Line.Add_Option (Options.Debug);
61+ VSS.Command_Line.Add_Option (Options.On_Hang);
62+ VSS.Command_Line.Add_Option (Options.File);
63+ VSS.Command_Line.Process; -- This terminates process on option's error
64+
65+ if not Options.File.Is_Specified then
66+ declare
67+ use type VSS.Strings.Virtual_String;
68+ Usage : VSS.String_Vectors.Virtual_String_Vector;
69+ begin
70+ Usage.Append (" Usage:" );
71+ Usage.Append
72+ (" tester-run [options] " & Options.File.Name);
73+ Usage.Append (" " );
74+ Usage.Append (" Options are:" );
75+ Usage.Append
76+ (" --" & Options.Debug.Long_Name
77+ & " (-" & Options.Debug.Short_Name & " )"
78+ & " " & Options.Debug.Description);
79+ Usage.Append
80+ (" --" & Options.On_Hang.Long_Name
81+ & " =" & Options.On_Hang.Value_Name
82+ & " " & Options.On_Hang.Description);
83+ VSS.Command_Line.Report_Error (Usage.Join_Lines (VSS.Strings.LF));
84+ end ;
4885 end if ;
4986
5087 declare
51- File : constant String := Ada.Command_Line.Argument
52- (Ada.Command_Line.Argument_Count );
88+ File : constant String := VSS.Strings.Conversions.To_UTF_8_String
89+ (Options.File.Value );
5390 Input : Ada.Text_IO.File_Type;
5491 Text : Ada.Strings.Unbounded.Unbounded_String;
5592 begin
@@ -73,7 +110,10 @@ begin
73110 declare
74111 Test : Tester.Tests.Test;
75112 begin
76- Test.Run (JSON.Get, Debug => Ada.Command_Line.Argument_Count = 2 );
113+ Test.Run
114+ (JSON.Get,
115+ On_Hang => Options.On_Hang.Value,
116+ Debug => Options.Debug.Is_Specified);
77117 end ;
78118 end ;
79119end Tester.Run ;
0 commit comments