libgpr2_24.0.0_eda3c693/testsuite/tests/options/src/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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
with Ada.Containers;
--
--  Copyright (C) 2019-2023, AdaCore
--
--  SPDX-License-Identifier: Apache-2.0
--

with Ada.Directories;
with Ada.Exceptions;
with Ada.Strings.Unbounded;

with GNAT.IO; use GNAT.IO;

with GPR2;
with GPR2.Containers;
with GPR2.Context;
with GPR2.File_Readers;
with GPR2.KB;
with GPR2.Log;
with GPR2.Options;
with GPR2.Path_Name;
with GPR2.Path_Name.Set;
with GPR2.Project.Tree;
procedure test is

   Options : GPR2.Options.Object;

   procedure Print_Test_OK is
   begin
      Put_Line ("Test OK");
      Put_Line ("");
   end Print_Test_OK;

   procedure Add_Switch_Pre_Check is
   begin
      Options.Add_Switch (GPR2.Options.Unchecked_Shared_Lib_Imports);
   end Add_Switch_Pre_Check;

   procedure Base_Pre_Check is
      Base : GPR2.KB.Object := Options.Base;
      pragma Unreferenced (Base);
   begin
      null;
   end Base_Pre_Check;

   procedure Build_Path_Pre_Check is
      Build_Path : GPR2.Path_Name.Object := Options.Build_Path;
      pragma Unreferenced (Build_Path);
   begin
      null;
   end Build_Path_Pre_Check;

   procedure Check_Shared_Lib_Pre_Check is
      Check_Shared_Lib : Boolean := Options.Check_Shared_Lib;
      pragma Unreferenced (Check_Shared_Lib);
   begin
      null;
   end Check_Shared_Lib_Pre_Check;

   procedure Config_Project_Pre_Check is
      Config_Project : GPR2.Path_Name.Object := Options.Config_Project;
      pragma Unreferenced (Config_Project);
   begin
      null;
   end Config_Project_Pre_Check;

   procedure Config_Project_Has_Error_Pre_Check is
      Config_Project_Has_Error :Boolean := Options.Config_Project_Has_Error;
      pragma Unreferenced (Config_Project_Has_Error);
   begin
      null;
   end Config_Project_Has_Error_Pre_Check;

   procedure Config_Project_Log_Pre_Check is
      Config_Project_Log : GPR2.Log.Object := Options.Config_Project_Log;
      pragma Unreferenced (Config_Project_Log);
   begin
      null;
   end Config_Project_Log_Pre_Check;

   procedure Context_Pre_Check is
      Context : GPR2.Context.Object := Options.Context;
      pragma Unreferenced (Context);
   begin
      null;
   end Context_Pre_Check;

   procedure Filename_Pre_Check is
      Filename : GPR2.Path_Name.Object := Options.Filename;
      pragma Unreferenced (Filename);
   begin
      null;
   end Filename_Pre_Check;

   procedure Finalize_Pre_Check is
   begin
      Options.Finalize;
   end Finalize_Pre_Check;

   procedure Implicit_With_Pre_Check is
      Implicit_With : GPR2.Path_Name.Set.Object := Options.Implicit_With;
      pragma Unreferenced (Implicit_With);
   begin
      null;
   end Implicit_With_Pre_Check;

   procedure Load_Project_Pre_Check is
      Tree : GPR2.Project.Tree.Object;
      Loaded : Boolean := Options.Load_Project (Tree);
      pragma Unreferenced (Loaded);
   begin
      null;
   end Load_Project_Pre_Check;

   procedure On_Extra_Arg_Pre_Check is
      On_Extra_Arg : Boolean := Options.On_Extra_Arg ("extra-arg");
      pragma Unreferenced (On_Extra_Arg);
   begin
      null;
   end On_Extra_Arg_Pre_Check;

   procedure Project_File_Pre_Check is
      Project_File : GPR2.Path_Name.Object := Options.Project_File;
      pragma Unreferenced (Project_File);
   begin
      null;
   end Project_File_Pre_Check;

   procedure Project_Is_Defined_Pre_Check is
      Project_Is_Defined : Boolean := Options.Project_Is_Defined;
      pragma Unreferenced (Project_Is_Defined);
   begin
      null;
   end Project_Is_Defined_Pre_Check;

   procedure RTS_Map_Pre_Check is
      RTS_Map : GPR2.Containers.Lang_Value_Map := Options.RTS_Map;
      pragma Unreferenced (RTS_Map);
   begin
      null;
   end RTS_Map_Pre_Check;

   procedure Src_Subdirs_Unbounded_Pre_Check is
      Src_Subdirs : Ada.Strings.Unbounded.Unbounded_String := Options.Src_Subdirs;
      pragma Unreferenced (Src_Subdirs);
   begin
      null;
   end Src_Subdirs_Unbounded_Pre_Check;

   procedure Src_Subdirs_Pre_Check is
      Src_Subdirs : GPR2.Optional_Name_Type := Options.Src_Subdirs;
      pragma Unreferenced (Src_Subdirs);
   begin
      null;
   end Src_Subdirs_Pre_Check;

   procedure Subdirs_Unbounded_Pre_Check is
      Subdirs : Ada.Strings.Unbounded.Unbounded_String := Options.Subdirs;
      pragma Unreferenced (Subdirs);
   begin
      null;
   end Subdirs_Unbounded_Pre_Check;

   procedure Subdirs_Pre_Check is
      Subdirs : GPR2.Optional_Name_Type := Options.Subdirs;
      pragma Unreferenced (Subdirs);
   begin
      null;
   end Subdirs_Pre_Check;

   procedure Target_Pre_Check is
      Target : GPR2.Name_Type := Options.Target;
      pragma Unreferenced (Target);
   begin
      null;
   end Target_Pre_Check;

   procedure Pre_Check_Test (Test : access procedure; Name : String; Finalized : Boolean :=  False) is
   begin
      Put_Line ("Testing " & Name);
      Options := GPR2.Options.Empty_Options;
      if Finalized then
         Options.Add_Switch (GPR2.Options.No_Project);
         Options.Finalize;
      end if;

      begin
         Test.all;
      exception
         when E : others =>
            Put_Line (Name & " => " & Ada.Exceptions.Exception_Name (E));
            Print_Test_OK;
      end;
   end Pre_Check_Test;

   procedure Pre_Check_Tests is
   begin
      Pre_Check_Test (Add_Switch_Pre_Check'Access, "Add_Switch pre check", True);
      Pre_Check_Test (Base_Pre_Check'Access, "Base pre check", False);
      Pre_Check_Test (Build_Path_Pre_Check'Access, "Build_Path pre check", False);
      Pre_Check_Test (Check_Shared_Lib_Pre_Check'Access, "Check_Shared_Lib pre check", False);
      Pre_Check_Test (Config_Project_Pre_Check'Access, "Config_Project_Pre_Check pre check", False);
      Pre_Check_Test (Config_Project_Has_Error_Pre_Check'Access, "Config_Project_Has_Error pre check", False);
      Pre_Check_Test (Config_Project_Log_Pre_Check'Access, "Config_Project_Log pre check", False);
      Pre_Check_Test (Context_Pre_Check'Access, "Context pre check", False);
      Pre_Check_Test (Filename_Pre_Check'Access, "Filename pre check", False);
      Pre_Check_Test (Finalize_Pre_Check'Access, "Finalize pre check", True);
      Pre_Check_Test (Implicit_With_Pre_Check'Access, "Implicit_With pre check", False);
      Pre_Check_Test (Load_Project_Pre_Check'Access, "Load_Project pre check", False);
      Pre_Check_Test (On_Extra_Arg_Pre_Check'Access, "On_Extra_Arg pre check", True);
      Pre_Check_Test (Project_File_Pre_Check'Access, "Project_File pre check", False);
      Pre_Check_Test (Project_Is_Defined_Pre_Check'Access, "Project_Is_Defined pre check", False);
      Pre_Check_Test (RTS_Map_Pre_Check'Access, "RTS_Map pre check", False);
      Pre_Check_Test (Src_Subdirs_Unbounded_Pre_Check'Access, "Src_Subdirs_Unbounded pre check", False);
      Pre_Check_Test (Src_Subdirs_Pre_Check'Access, "Src_Subdirs pre check", False);
      Pre_Check_Test (Subdirs_Unbounded_Pre_Check'Access, "Subdirs_Unbounded pre check", False);
      Pre_Check_Test (Subdirs_Pre_Check'Access, "Subdirs pre check", False);
      Pre_Check_Test (Target_Pre_Check'Access, "Target pre check", False);
   end Pre_Check_Tests;

   procedure Test_Add_Switch_DB is
   begin
      Put_Line ("Testing Add_Switch --db test.gpr");
      Options := GPR2.Options.Empty_Options;
      Options.Add_Switch (GPR2.Options.DB, "test.gpr");
      Print_Test_OK;

      Put_Line ("Testing Add_Switch --db src");
      Options := GPR2.Options.Empty_Options;
      Options.Add_Switch (GPR2.Options.DB, "src");
      Print_Test_OK;

      Put_Line ("Testing Add_Switch --db unexisting");
      Options := GPR2.Options.Empty_Options;

      begin
         Options.Add_Switch (GPR2.Options.DB, "unexisting");
      exception
         when E : GPR2.Options.Usage_Error =>
            Put_Line (Ada.Exceptions.Exception_Name (E) & " = > " & Ada.Exceptions.Exception_Message (E));
            Print_Test_OK;
      end;
   end Test_Add_Switch_DB;

   procedure Test_Add_Switch_P is
   begin
      Put_Line ("Testing Add_Switch -Pfirst -Psecond");
      Options := GPR2.Options.Empty_Options;
      Options.Add_Switch (GPR2.Options.P, "first");

      begin
         Options.Add_Switch (GPR2.Options.P, "second");
      exception
         when E : GPR2.Options.Usage_Error =>
            Put_Line (Ada.Exceptions.Exception_Name (E) & " = > " & Ada.Exceptions.Exception_Message (E));
            Print_Test_OK;
      end;

      Put_Line ("Testing Add_Switch extra.gpr -Ptest");
      Options := GPR2.Options.Empty_Options;
      Put_Line ("On_Extra_Arg (""extra.gpr"") => " & GPR2.Options.On_Extra_Arg (Options, "extra.gpr")'Image);

      begin
         Options.Add_Switch (GPR2.Options.P, "test");
      exception
         when E : GPR2.Options.Usage_Error =>
            Put_Line (Ada.Exceptions.Exception_Name (E) & " = > " & Ada.Exceptions.Exception_Message (E));
            Print_Test_OK;
      end;
   end Test_Add_Switch_P;

   procedure Test_Add_Switch_X is
   begin
      Put_Line ("Testing Add_Switch -X name:value");
      Options := GPR2.Options.Empty_Options;

      begin
         Options.Add_Switch (GPR2.Options.X, "name:value");
      exception
         when E : GPR2.Options.Usage_Error =>
            Put_Line (Ada.Exceptions.Exception_Name (E) & " = > " & Ada.Exceptions.Exception_Message (E));
            Print_Test_OK;
      end;
   end Test_Add_Switch_X;

   procedure Test_On_Extra_Arg is
      Name1     : constant String := "extra1.gpr";
      Name2     : constant String := "extra2.gpr";
      Other_Arg : constant String := "other-arg";
   begin
      Put_Line ("Testing On_Extra_Arg other-arg extra1.gpr other-arg extra2.gpr");

      Options := GPR2.Options.Empty_Options;
      Put_Line ("On_Extra_Arg (""" & Other_Arg & """) => " & GPR2.Options.On_Extra_Arg (Options, Other_Arg)'Image);
      Put_Line ("On_Extra_Arg (""" & Name1 & """) => " & GPR2.Options.On_Extra_Arg (Options, Name1)'Image);
      Put_Line ("On_Extra_Arg (""" & Other_Arg & """) => " & GPR2.Options.On_Extra_Arg (Options, Other_Arg)'Image);

      begin
         Put_Line ("On_Extra_Arg (""" & Name2 & """) => " & GPR2.Options.On_Extra_Arg (Options, Name2)'Image);
      exception
         when E : GPR2.Options.Usage_Error =>
            Put_Line (Ada.Exceptions.Exception_Name (E) & " = > " & Ada.Exceptions.Exception_Message (E));
            Print_Test_OK;
      end;

      Put_Line ("Testing Add_Switch -Ptest extra.gpr");
      Options := GPR2.Options.Empty_Options;
      Options.Add_Switch (GPR2.Options.P, "test");

      begin
         Put_Line ("On_Extra_Arg (""extra.gpr"") => " & GPR2.Options.On_Extra_Arg (Options, "extra.gpr")'Image);
      exception
         when E : GPR2.Options.Usage_Error =>
            Put_Line (Ada.Exceptions.Exception_Name (E) & " = > " & Ada.Exceptions.Exception_Message (E));
            Print_Test_OK;
      end;
   end Test_On_Extra_Arg;

   procedure Test_Add_Switch_RTS_Map is
      use GPR2;

      RTS : GPR2.Containers.Lang_Value_Map;
      Other_Language : constant Language_Id := +"otherlanguage";
   begin
      Put_Line ("Testing --RTS=adaRuntime1 --RTS:otherLanguage=otherRuntime1");
      Options := GPR2.Options.Empty_Options;
      Options.Add_Switch (GPR2.Options.No_Project);
      Options.Add_Switch (GPR2.Options.RTS, "adaRuntime1");
      Options.Add_Switch (GPR2.Options.RTS, "otherRuntime1", "otherLanguage");
      Options.Finalize;
      RTS := Options.RTS_Map;
      Put_Line ("Ada runtime: " & RTS.Element (GPR2.Ada_Language));
      Put_Line ("Other runtime: " & RTS.Element (Other_Language));
      Print_Test_OK;

      Put_Line ("Testing --RTS:ada=adaRuntime0 --RTS:ADA=adaRuntime2 --RTS:otherLanguage=otherRuntime1");
      Options := GPR2.Options.Empty_Options;
      Options.Add_Switch (GPR2.Options.No_Project);
      Options.Add_Switch (GPR2.Options.RTS, "adaRuntime0", "ada");
      Options.Add_Switch (GPR2.Options.RTS, "adaRuntime2", "ADA");
      Options.Add_Switch (GPR2.Options.RTS, "otherRuntime0", "otherLanguage");
      Options.Add_Switch (GPR2.Options.RTS, "otherRuntime2", "OTHERLANGUAGE");
      Options.Finalize;
      RTS := Options.RTS_Map;
      Put_Line ("Ada runtime: " & RTS.Element (GPR2.Ada_Language));
      Put_Line ("Other language runtime: " & RTS.Element (Other_Language));
      Print_Test_OK;
   end Test_Add_Switch_RTS_Map;

   procedure Test_Values is

      procedure Output_Values (Allow_Implicit_Project : String := "")is
         use Ada.Containers;
      begin
         Put_Line ("Filename" & Allow_Implicit_Project & ":" & Options.Filename.Value);
         Put_Line ("Context.Length" & Allow_Implicit_Project & ":" & Options.Context.Length'Image);

         if Options.Implicit_With.Length > 0 then
            Put_Line ("Context'First " & String (Options.Context.First_Key) & "=" & String (Options.Context.First_Element));
         else
            Put_Line ("Context" & Allow_Implicit_Project & ": is empty");
         end if;

         if Options.Config_Project.Is_Defined then
            Put_Line ("Config_Project:" & String (Options.Config_Project.Name));
         else
            Put_Line ("Config_Project" & Allow_Implicit_Project & ": is not defined");
         end if;

         Put_Line ("Build_Path" & Allow_Implicit_Project & ":" & Options.Build_Path.Value);

         declare
            Subdirs     : constant GPR2.Optional_Name_Type := Options.Subdirs;
            Src_Subdirs : constant GPR2.Optional_Name_Type := Options.Src_Subdirs;
         begin
            Put_Line ("Subdirs" & Allow_Implicit_Project & ":" & String (Subdirs));
            Put_Line ("Subdirs (unbounded)" & Allow_Implicit_Project & ":" & Ada.Strings.Unbounded.To_String (Options.Subdirs));
            Put_Line ("Src_Subdirs" & Allow_Implicit_Project & ":" & String (Src_Subdirs));
            Put_Line ("Src_Subdirs (unbounded)" & Allow_Implicit_Project & ":" & Ada.Strings.Unbounded.To_String (Options.Src_Subdirs));
         end;
         Put_Line ("Check_Shared_Lib" & Allow_Implicit_Project & ":" & Options.Check_Shared_Lib'Image);

         if Options.Implicit_With.Length > 0 then
            Put_Line ("Implicit_With'First" & String (Options.Implicit_With.First_Element.Name));
         else
            Put_Line ("Implicit_With" & Allow_Implicit_Project & ": is empty");
         end if;

         Put_Line ("Target" & Allow_Implicit_Project & ":" & String (Options.Target));
         Put_Line ("RTS_Map.Length" & Allow_Implicit_Project & ":" & Options.RTS_Map.Length'Image);
         Put_Line ("Base.Is_Default_Db" & Allow_Implicit_Project & ":" & Options.Base.Is_Default_Db'Image);
         Put_Line ("Project_Is_Defined" & Allow_Implicit_Project & ":" & Options.Project_Is_Defined'Image);
      end Output_Values;

   begin
      Put_Line ("Testing default values (--no-project)");
      Options := GPR2.Options.Empty_Options;
      Options.Add_Switch (GPR2.Options.No_Project);
      Options.Finalize (Allow_Implicit_Project => False);
      Output_Values;
      Options := GPR2.Options.Empty_Options;
      Options.Add_Switch (GPR2.Options.No_Project);
      Options.Finalize;
      Output_Values ("(Allow_Implicit_Project)");
      Print_Test_OK;

      Put_Line ("Testing values");
      Options := GPR2.Options.Empty_Options;
      Options.Add_Switch (GPR2.Options.AP, "./path-added");
      Options.Add_Switch (GPR2.Options.Autoconf, "autoconf.cgpr");
      Options.Add_Switch (GPR2.Options.Db_Minus);
      Options.Add_Switch (GPR2.Options.Implicit_With, "implicit.gpr");
      Options.Add_Switch (GPR2.Options.Src_Subdirs, "Src_Subdirs");
      Options.Add_Switch (GPR2.Options.Subdirs, "Subdirs");
      Options.Add_Switch (GPR2.Options.Target, "arm-elf");
      Options.Add_Switch (GPR2.Options.Unchecked_Shared_Lib_Imports);
      Options.Add_Switch (GPR2.Options.X, "key=value");
      Options.Finalize;
      Output_Values;
      Options := GPR2.Options.Empty_Options;
      Options.Add_Switch (GPR2.Options.Config, "config.cgpr");
      Options.Finalize;
      Put_Line ("Config_Project (--config):" & String (Options.Config_Project.Name));
      Print_Test_OK;
   end Test_Values;

   procedure Test_Finalize is

      procedure Print_Path (Name : String; Path_Name : GPR2.Path_Name.Object) is
      begin
         if Path_Name.Is_Defined then
            Put_Line (Name & ":" & String (Path_Name.Name));
         else
            Put_Line (Name & " is Undefined");
         end if;
      end Print_Path;

      procedure Print_Paths is
      begin
         Print_Path ("Filename", Options.Filename);
         Print_Path ("Build_Path", Options.Build_Path);
      end Print_Paths;

      procedure Test (Current_Directory : String; Allow_Implicit_Project : Boolean := True;Quiet : Boolean := False) is
      begin
         Ada.Directories.Set_Directory (Current_Directory);
         Put_Line ("Testing Finalize no arguments at " & Ada.Directories.Current_Directory
                  & " with Allow_Implicit_Project=" & Allow_Implicit_Project'Image );
         Options := GPR2.Options.Empty_Options;
         Options.Finalize (Allow_Implicit_Project, Quiet);
         Print_Paths;
         Print_Test_OK;
      end Test;

   begin
      Put_Line ("Testing Finalize --no-project -Ptest");
      Options := GPR2.Options.Empty_Options;
      Options.Add_Switch (GPR2.Options.No_Project);
      Options.Add_Switch (GPR2.Options.P, "test");

      begin
         Options.Finalize;
      exception
         when E : GPR2.Options.Usage_Error =>
            Put_Line (Ada.Exceptions.Exception_Name (E) & " = > " & Ada.Exceptions.Exception_Message (E));
            Print_Test_OK;
      end;

      Put_Line ("Testing Finalize --root-dir=root  -Ptest");
      Options := GPR2.Options.Empty_Options;
      Options.Add_Switch (GPR2.Options.Root_Dir, "root");
      Options.Add_Switch (GPR2.Options.P, "test");

      begin
         Options.Finalize;
      exception
         when E : GPR2.Options.Usage_Error =>
            Put_Line (Ada.Exceptions.Exception_Name (E) & " = > " & Ada.Exceptions.Exception_Message (E));
            Print_Test_OK;
      end;

      Test (".");
      Test ("./new-current-directory/default");
      Test ("../two-gpr");
      Test ("../two-gpr", Quiet => True);
      Test ("../no-gpr");
      Test ("../..", Allow_Implicit_Project => False);

      Put_Line ("Testing Finalize -Ptest");
      Options := GPR2.Options.Empty_Options;
      Options.Add_Switch (GPR2.Options.P, "test");
      Options.Finalize;
      Print_Paths;
      Print_Test_OK;

      Put_Line ("Testing Finalize --relocate-build-tree=relocated -Ptest");
      Options := GPR2.Options.Empty_Options;
      Options.Add_Switch (GPR2.Options.P, "test");
      Options.Add_Switch (GPR2.Options.Relocate_Build_Tree, "relocated");
      Options.Finalize;
      Print_Paths;
      Print_Test_OK;

      Put_Line ("Testing Finalize --no-project --relocate-build-tree=relocated");
      Options := GPR2.Options.Empty_Options;
      Options.Add_Switch (GPR2.Options.No_Project);
      Options.Add_Switch (GPR2.Options.Relocate_Build_Tree, "relocated");
      Options.Finalize;
      Print_Paths;
      Print_Test_OK;

      Put_Line ("Testing Finalize --no-project --relocate-build-tree=relocated --root-dir=.");
      Options := GPR2.Options.Empty_Options;
      Options.Add_Switch (GPR2.Options.No_Project);
      Options.Add_Switch (GPR2.Options.Relocate_Build_Tree, "relocated");
      Options.Add_Switch (GPR2.Options.Root_Dir, Ada.Directories.Current_Directory & ".");
      Options.Finalize;
      Print_Paths;
      Print_Test_OK;
   end Test_Finalize;


   procedure Test_Load_Project is
      Tree : GPR2.Project.Tree.Object;

      procedure Test (Name : String;
                      Tree             : in out GPR2.Project.Tree.Object;
                      Absent_Dir_Error : GPR2.Project.Tree.Error_Level :=
                        GPR2.Project.Tree.Warning;
                      File_Reader      : GPR2.File_Readers.File_Reader_Reference :=
                        GPR2.File_Readers.No_File_Reader_Reference;
                      Quiet            : Boolean := False) is
         Loaded : Boolean;

         procedure Output_Messages (Log : GPR2.Log.Object) is
         begin
            for C in Log.Iterate
              (Information => False,
               Warning     => True,
               Error       => True,
               Lint        => False,
               Read        => False,
               Unread      => True)
            loop
               Put_Line (Log (C).Format);
            end loop;
         end Output_Messages;
      begin
         Put_Line ("Testing Load Project " & Name);
         Loaded := Options.Load_Project
                     (Tree             => Tree,
                      Absent_Dir_Error => Absent_Dir_Error,
                      File_Reader      => File_Reader,
                      Quiet            => Quiet);
         Put_Line ("Load_Project returned " & Loaded'Image);

         if Options.Config_Project_Has_Error then
            Output_Messages (Options.Config_Project_Log);
         end if;

         if Tree.Log_Messages.Has_Error then
            Output_Messages (Tree.Log_Messages.all);
         end if;

         if not Loaded then
            Put_Line ("Target:" & String (Tree.Target));
            Put_Line ("Runtime(Ada):" & String (Tree.Runtime (GPR2.Ada_Language)));
            Put_Line ("Subdirs:" & String (Tree.Subdirs));

            if Tree.Has_Src_Subdirs then
               Put_Line ("Src_Subdirs:" & String (Tree.Src_Subdirs));
            end if;

            Put_Line ("Build_Path:" & String (Tree.Build_Path.Name));
            Put_Line ("Object_Directory:" & String (Tree.Root_Project.Object_Directory.Name));
         end if;
         Print_Test_OK;
      end Test;

   begin
      Options := GPR2.Options.Empty_Options;
      Options.Add_Switch (GPR2.Options.AP, "added-path");
      Options.Add_Switch (GPR2.Options.P, "load-project/test");
      Options.Add_Switch (GPR2.Options.Autoconf, "autoconf.cgpr");
      Options.Add_Switch (GPR2.Options.Src_Subdirs, "src_subdirs");
      Options.Add_Switch (GPR2.Options.Subdirs, "subdirs");
      Options.Add_Switch (GPR2.Options.X, "BUILD=Debug");
      Options.Finalize;
      Test ("-aP added-path -Pload-project/test --autoconf=other-autoconf.cgpr --subdirs=subdirs --src_subdirs=srcsubdirs -XBUILD=Debug", Tree);

      Options := GPR2.Options.Empty_Options;
      Options.Add_Switch (GPR2.Options.AP, "added-path");
      Options.Add_Switch (GPR2.Options.AP, "load-project");
      Options.Add_Switch (GPR2.Options.Root_Dir, ".");
      Options.Add_Switch (GPR2.Options.Relocate_Build_Tree, "relocated");
      Options.Add_Switch (GPR2.Options.P, "test");
      Options.Add_Switch (GPR2.Options.Autoconf, "other-autoconf.cgpr");
      Options.Add_Switch (GPR2.Options.X, "BUILD=Debug");
      Options.Finalize;
      Test ("-aP added-path -aP load-project --root-dir=. --relocate-build-tree=relocated -Ptest --autoconf=autoconf.cgpr -XBUILD=Debug", Tree, Quiet => True);

      Options := GPR2.Options.Empty_Options;
      Options.Add_Switch (GPR2.Options.AP, "added-path");
      Options.Add_Switch (GPR2.Options.P, "load-project/test");
      Options.Add_Switch (GPR2.Options.Config, "autoconf.cgpr");
      Options.Add_Switch (GPR2.Options.Src_Subdirs, "src_subdirs");
      Options.Add_Switch (GPR2.Options.Subdirs, "subdirs");
      Options.Add_Switch (GPR2.Options.X, "BUILD=Release");
      Options.Finalize;
      Test ("-aP added-path -Pload-project/test --config=autoconf.cgpr --subdirs=subdirs --src_subdirs=srcsubdirs -XBUILD=Debug", Tree);

      Options := GPR2.Options.Empty_Options;
      Options.Add_Switch (GPR2.Options.AP, "added-path");
      Options.Add_Switch (GPR2.Options.P, "load-project/test");
      Options.Add_Switch (GPR2.Options.Target, String (Tree.Target));
      Options.Add_Switch (GPR2.Options.Config, "autoconf.cgpr");
      Options.Add_Switch (GPR2.Options.X, "BUILD=Release");
      Options.Finalize;
      Test ("-aP added-path -Pload-project/test --config=autoconf.cgpr --subdirs=subdirs --src_subdirs=srcsubdirs -XBUILD=Debug --target " & String (Tree.Target), Tree);

      Options := GPR2.Options.Empty_Options;
      Options.Add_Switch (GPR2.Options.AP, "added-path");
      Options.Add_Switch (GPR2.Options.P, "load-project/test");
      Options.Add_Switch (GPR2.Options.Target, "unknown-target");
      Options.Add_Switch (GPR2.Options.Config, "autoconf.cgpr");
      Options.Add_Switch (GPR2.Options.Src_Subdirs, "src_subdirs");
      Options.Add_Switch (GPR2.Options.Subdirs, "subdirs");
      Options.Add_Switch (GPR2.Options.X, "BUILD=Release");
      Options.Finalize;
      Test ("-aP added-path -Pload-project/test --config=autoconf.cgpr --subdirs=subdirs --src_subdirs=srcsubdirs -XBUILD=Debug --target unknown-target", Tree);
   end Test_Load_Project;

begin
   Pre_Check_Tests;
   Test_Add_Switch_DB;
   Test_Add_Switch_P;
   Test_Add_Switch_X;
   Test_On_Extra_Arg;
   Test_Add_Switch_RTS_Map;
   Test_Values;
   Test_Finalize;
   Test_Load_Project;
end test;