libgpr2_24.0.0_eda3c693/testsuite/tests/environment/test.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
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
with Ada.Directories;
with Ada.Environment_Variables;
with Ada.Text_IO; use Ada.Text_IO;

with GNAT.OS_Lib;

with GPR2.Environment;
with GPR2.Log;
with GPR2.Options;
with GPR2.Path_Name;
with GPR2.Project.Tree;

procedure Test is

   PATH : constant String :=
            Ada.Environment_Variables.Value
              ("PATH", "");
   GPR_PROJECT_PATH : constant String :=
                        Ada.Environment_Variables.Value
                          ("GPR_PROJECT_PATH", "");
   ADA_PROJECT_PATH : constant String :=
                        Ada.Environment_Variables.Value
                          ("ADA_PROJECT_PATH", "");
   function Environment
     (Root : GPR2.Filename_Optional) return GPR2.Environment.Object is
      Environment : GPR2.Environment.Object;
      Project_Path_File : constant GPR2.Path_Name.Object :=
                            GPR2.Path_Name.Create_File
                              (Name      => "gpr_project_path_file.txt",
                               Directory => Root);
      File : Ada.Text_IO.File_Type;
      Content : constant String :=
                  GPR2.Path_Name.Create_Directory
                    (Name      => "gpr_project_path_file",
                     Directory => Root).Value;
   begin
      Environment.Insert ("PATH", PATH);
      Ada.Environment_Variables.Set ("PATH", "");

      Environment.Insert
        ("ADA_PROJECT_PATH",
         GPR2.Path_Name.Create_Directory
           (Name      => "ada_project_path",
            Directory => Root).Value
         & GNAT.OS_Lib.Path_Separator
         & ADA_PROJECT_PATH);
      Ada.Environment_Variables.Set ("ADA_PROJECT_PATH", "");

      Environment.Insert
        ("GPR_PROJECT_PATH",
         GPR2.Path_Name.Create_Directory
           (Name      => "gpr_project_path",
            Directory => Root).Value
         & GNAT.OS_Lib.Path_Separator
         & GPR_PROJECT_PATH);
      Ada.Environment_Variables.Set ("GPR_PROJECT_PATH", "");

      Ada.Text_IO.Open
        (File => File,
         Mode => Ada.Text_IO.Out_File,
         Name => Project_Path_File.Value);
      Ada.Text_IO.Put_Line
        (File => File,
         Item => Content);
      Ada.Text_IO.Close (File);
      Environment.Insert
        ("GPR_PROJECT_PATH_FILE", Project_Path_File.Value);
      Ada.Environment_Variables.Set ("GPR_PROJECT_PATH_FILE", "");

      return Environment;
   end Environment;

   Options : GPR2.Options.Object;
   Tree : GPR2.Project.Tree.Object;
begin

   --  testing load_autoconf
   Options.Add_Switch (GPR2.Options.P, "./files/prj");
   Options.Add_Switch (GPR2.Options.AP, "./files/registered");
   Options.Add_Switch (GPR2.Options.Autoconf, "./files/autoconf.cgpr");
   Options.Finalize (Allow_Implicit_Project => False,
                     Quiet                  => True,
                     Environment            => Environment ("files"));
   if not Options.Load_Project (Tree,
                                Quiet => True) then
      GPR2.Log.Output_Messages (Tree.Log_Messages.all);
   end if;

   --  testing load using default project in ./files directory
   Options := GPR2.Options.Empty_Options;
   Options.Add_Switch (GPR2.Options.P,
                       GPR2.Options.Check_For_Default_Project
                         (GPR2.Path_Name.Create_Directory
                            ("./files").Value).Value);
   Options.Add_Switch (GPR2.Options.AP, "./files/registered");
   Options.Add_Switch (GPR2.Options.Config, "./files/autoconf.cgpr");
   Options.Finalize (Allow_Implicit_Project => True,
                     Quiet                  => True,
                     Environment            => Environment ("files"));
   if not Options.Load_Project (Tree) then
      GPR2.Log.Output_Messages (Tree.Log_Messages.all);
   end if;

   --  testing load_autoconf on default project
   Options := GPR2.Options.Empty_Options;
   Ada.Directories.Set_Directory ("./files");
   Options.Add_Switch (GPR2.Options.AP, "./registered");
   Options.Finalize (Allow_Implicit_Project => True,
                     Quiet                  => True,
                     Environment            => Environment ("."));
   if not Options.Load_Project (Tree) then
      GPR2.Log.Output_Messages (Tree.Log_Messages.all);
   end if;

end Test;