gpr_unit_provider_23.0.0_87c3b1c4/testsuite/tests/project_unit_provider_invalid/main.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
with Ada.Exceptions;                  use Ada.Exceptions;
with Ada.Strings.Wide_Wide_Unbounded; use Ada.Strings.Wide_Wide_Unbounded;
with Ada.Text_IO;                     use Ada.Text_IO;

with Langkit_Support.Diagnostics; use Langkit_Support.Diagnostics;
with Langkit_Support.Text;        use Langkit_Support.Text;

with Libadalang.Analysis;         use Libadalang.Analysis;
with Libadalang.Common;           use Libadalang.Common;
with Libadalang.GPR2_Provider;    use Libadalang.GPR2_Provider;

with GPR2.Path_Name;
with GPR2.Project.Tree;
with GPR2.Context;

procedure Main is

   Tree : GPR2.Project.Tree.Object;

   function Load_Project (File : String) return Unit_Provider_Reference;

   function "+" (S : Wide_Wide_String) return Unbounded_Wide_Wide_String
      renames To_Unbounded_Wide_Wide_String;
   function "+" (S : Unbounded_Wide_Wide_String) return Wide_Wide_String
      renames To_Wide_Wide_String;

   ------------------
   -- Load_Project --
   ------------------

   function Load_Project (File : String) return Unit_Provider_Reference is
   begin
      Tree.Load_Autoconf
        (Filename => GPR2.Path_Name.Create_File (GPR2.Filename_Type (File)),
         Context  => GPR2.Context.Empty);
      return Create_Project_Unit_Provider (Tree, Tree.Root_Project);
   end Load_Project;

   Ctx  : constant Analysis_Context :=
      Create_Context (Unit_Provider => Load_Project ("p.gpr"));
   Unit : Analysis_Unit;

   Filenames : array (Positive range <>) of Unbounded_Wide_Wide_String :=
     (+(1 => Wide_Wide_Character'Val (233)),
      +"unknown_unit");

begin
   for File of Filenames loop
      Put_Line ("Trying to get unit: " & Image (+File, With_Quotes => True));
      begin
         Unit := Get_From_Provider (Ctx, +File, Unit_Specification);

         Put_Line ("   ...   got no exception.");
         if Has_Diagnostics (Unit) then
            Put_Line ("   ...   but we got diagnostics:");
            for D of Diagnostics (Unit) loop
               Put_Line ("   " & To_Pretty_String (D));
            end loop;
         end iF;
      exception
         when Exc : Invalid_Unit_Name_Error =>
            Put_Line ("   ... got an exception:");
            Put_Line ("   " & Exception_Name (Exc));
            Put_Line ("   " & Exception_Message (Exc));
      end;
   end loop;

   Put_Line ("Done.");
end Main;