ashell_1.3.0_8d2540e0/applet/tests/commands/unsafe/environment/test_environment.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
with
     Shell.Commands.Unsafe,
     Ada.Environment_Variables,
     Ada.Text_IO;

procedure Test_Environment
is
   use Ada.Text_IO;
begin
   Put_Line ("Begin 'Test_Environment' tests.");

   New_Line (2);

   Test_1:
   declare
      Name     : constant String := "aShell_Test_Variable";
      Value    : constant String := "Working";
      Commands : constant String := "env | grep " & Name;
      Expected : constant String := Name & "=" & Value;

      use Shell,
          Shell.Commands,
          Shell.Commands.Unsafe,
          Shell.Commands.Unsafe.Forge;
      Piped_Commands : Command_Array := To_Commands (Commands);
   begin
      Put_Line ("Begin Test 1 ~ Run piped commands => '" & Commands & "'");
      New_Line;

      Ada.Environment_Variables.Set (Name  => Name,
                                     Value => Value);
      Put      ("Expected output: ");
      Put_Line (Expected);
      Put      ("Actual   output: ");

      Start (Piped_Commands);
      delay 1.0;

      for i in Piped_Commands'Range
      loop
         Wait_On (Piped_Commands (i));
      end loop;

      Put_Line (+Output_Of (Results_Of (Piped_Commands (2))));
      Put_Line ("End test 1");
   end Test_1;

   New_Line (2);

   Test_2:
   declare
      Name     : constant String := "aShell_Test_Variable";
      Value    : constant String := "Changed";
      Commands : constant String := "env | grep " & Name;
      Expected : constant String := Name & "=" & Value;

      use Shell,
          Shell.Commands,
          Shell.Commands.Unsafe,
          Shell.Commands.Unsafe.Forge;
      Piped_Commands : Command_Array := To_Commands (Commands);
   begin
      Put_Line ("Begin Test 2 ~ Run piped commands => '" & Commands & "'");
      New_Line;

      Ada.Environment_Variables.Set (Name  => Name,
                                     Value => Value);
      Put      ("Expected output: ");
      Put_Line (Expected);
      Put      ("Actual   output: ");
      Start (Piped_Commands);
      delay 1.0;

      for i in Piped_Commands'Range
      loop
         Wait_On (Piped_Commands (i));
      end loop;

      Put_Line (+Output_Of (Results_Of (Piped_Commands (2))));
      Put_Line ("End test 2");
   end Test_2;

   New_Line (2);
   Put_Line ("End 'Test_Environment' tests.");
end Test_Environment;