libgpr2_24.0.0_eda3c693/testsuite/tests/custom_attr_no_pack/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
with Ada.Assertions;
with Ada.Text_IO; use Ada.Text_IO;

with GPR2.Context;
with GPR2.Project.Tree;
with GPR2.Project.Registry.Attribute;
with GPR2.Project.Registry.Pack;

procedure Main is
   package Attr renames GPR2.Project.Registry.Attribute;
   package Pack renames GPR2.Project.Registry.Pack;
   Ctx : GPR2.Context.Object;
   PT  : GPR2.Project.Tree.Object;

   Qualified_Name : GPR2.Q_Attribute_Id
     := (Pack => GPR2."+" ("Foo"),
         Attr => GPR2."+" ("Bar"));

   procedure Case_1 is
   begin
      Attr.Add
        (Name                 => Qualified_Name,
         Index_Type           => Attr.No_Index,
         Value                => Attr.Single,
         Value_Case_Sensitive => True,
         Is_Allowed_In        => Attr.Everywhere);
   exception
      when Ada.Assertions.Assertion_Error =>
         Put_Line (Item => "raised ADA.ASSERTIONS.ASSERTION_ERROR :"
                   & " failed precondition");
      when others =>
         Put_Line (Item => "Unexpected exception");
   end Case_1;

   procedure Case_2 is
   begin
      Pack.Add (Name     => Qualified_Name.Pack,
                Projects => Pack.Everywhere);
      Attr.Add
        (Name                 => Qualified_Name,
         Index_Type           => Attr.No_Index,
         Value                => Attr.Single,
         Value_Case_Sensitive => True,
         Is_Allowed_In        => Attr.Everywhere);
   end Case_2;
begin
   Put_Line (Item => "Case 1 - Adding a custom attribute without pack");
   Case_1;
   if not Pack.Exists (Name => GPR2."+" ("Foo"))
     and then not Attr.Exists (Q_Name => Qualified_Name)
   then
      Put_Line (Item => "Test OK !");
   else
      Put_Line (Item => "Test KO !");
   end if;

   Put_Line (Item => "Case 2 - Adding a custom attribute with pack");
   Case_2;
   if Pack.Exists (Name => GPR2."+" ("Foo"))
     and then Attr.Exists (Q_Name => Qualified_Name)
   then
      Put_Line (Item => "Test OK !");
   else
      Put_Line (Item => "Test KO !");
   end if;
end Main;