ada_language_server_22.0.0_ef4bdf41/source/tester/tester-run.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
------------------------------------------------------------------------------
--                         Language Server Protocol                         --
--                                                                          --
--                     Copyright (C) 2018-2019, AdaCore                     --
--                                                                          --
-- This is free software;  you can redistribute it  and/or modify it  under --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion.  This software 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. See the GNU General Public --
-- License for  more details.  You should have  received  a copy of the GNU --
-- General  Public  License  distributed  with  this  software;   see  file --
-- COPYING3.  If not, go to http://www.gnu.org/licenses for a complete copy --
-- of the license.                                                          --
------------------------------------------------------------------------------

with Ada.Command_Line;
with Ada.Directories;
with Ada.Strings.Unbounded;
with Ada.Text_IO;
with GNATCOLL.JSON;

with Tester.Macros;
with Tester.Tests;

with Spawn.Environments;

procedure Tester.Run is
   Env  : constant Spawn.Environments.Process_Environment :=
     Spawn.Environments.System_Environment;

   JSON : GNATCOLL.JSON.JSON_Value;
begin
   if not (Ada.Command_Line.Argument_Count = 1
     or else (Ada.Command_Line.Argument_Count = 2
              and then Ada.Command_Line.Argument (1) = "--debug"))
   then
      Ada.Text_IO.Put_Line ("Usage:");
      Ada.Text_IO.Put_Line
        ("   " & Ada.Command_Line.Command_Name & " [options] test.json");
      Ada.Text_IO.New_Line;
      Ada.Text_IO.Put_Line ("Options are:");
      Ada.Text_IO.Put_Line
        ("  --debug  disable timeouts and pause after server start");
      Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
      return;
   end if;

   declare
      File  : constant String := Ada.Command_Line.Argument
        (Ada.Command_Line.Argument_Count);
      Input : Ada.Text_IO.File_Type;
      Text  : Ada.Strings.Unbounded.Unbounded_String;
   begin
      if not Ada.Directories.Exists (File) then
         Ada.Text_IO.Put_Line ("No such file: " & File);
         Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
         return;
      end if;

      Ada.Text_IO.Open (Input, Ada.Text_IO.In_File, File);

      while not Ada.Text_IO.End_Of_File (Input) loop
         Ada.Strings.Unbounded.Append
           (Text, Ada.Text_IO.Get_Line (Input));
      end loop;

      Ada.Text_IO.Close (Input);
      JSON := GNATCOLL.JSON.Read (Text, File);
      Tester.Macros.Expand (JSON, Env, File);

      declare
         Test : Tester.Tests.Test;
      begin
         Test.Run (JSON.Get, Debug => Ada.Command_Line.Argument_Count = 2);
      end;
   end;
end Tester.Run;