Skip to content

Commit f79787f

Browse files
committed
U315-010 Use Python to make symbol link in the test.
Print stderr/stdout of launched command for debug purpose. Add an Python example to the README.md
1 parent 55f056e commit f79787f

File tree

5 files changed

+113
-9
lines changed

5 files changed

+113
-9
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ vscode-test:
132132

133133
check: all
134134
set -e; \
135+
export PYTHON=$(PYTHON); \
135136
if [ `$(PYTHON) -c "import sys;print('e3' in sys.modules)"` = "True" ]; then\
136137
(cd testsuite ; sh run.sh ) ; \
137138
else \

source/tester/tester-tests.adb

Lines changed: 99 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@
1717

1818
with Ada.Command_Line;
1919
with Ada.Directories;
20+
with Ada.Streams;
2021
with Ada.Text_IO;
2122
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
2223
with GNAT.OS_Lib; use GNAT.OS_Lib;
2324

2425
with GNATCOLL.Utils; use GNATCOLL.Utils;
2526
with GNATCOLL.JSON; use GNATCOLL.JSON;
2627

28+
with VSS.Stream_Element_Vectors;
29+
with VSS.Strings.Conversions;
30+
with VSS.Strings.Converters.Decoders;
31+
2732
with Spawn.Processes.Monitor_Loop;
2833

2934
package body Tester.Tests is
@@ -168,6 +173,13 @@ package body Tester.Tests is
168173
function To_Program (Name : String) return String;
169174
-- Take base name of the command and find it on PATH
170175

176+
procedure Print (V : VSS.Stream_Element_Vectors.Stream_Element_Vector);
177+
-- Print V as string.
178+
179+
----------------
180+
-- To_Program --
181+
----------------
182+
171183
function To_Program (Name : String) return String is
172184
Found : GNAT.OS_Lib.String_Access :=
173185
GNAT.OS_Lib.Locate_Exec_On_Path (Name);
@@ -181,10 +193,20 @@ package body Tester.Tests is
181193
Cmd : constant String := To_Program (GNATCOLL.JSON.Get (List, 1).Get);
182194
Args : Spawn.String_Vectors.UTF_8_String_Vector;
183195

184-
type Shell_Listener is new Spawn.Processes.Process_Listener with record
185-
Done : Boolean := False;
196+
type Shell_Listener is limited new Spawn.Processes.Process_Listener with
197+
record
198+
Process : Spawn.Processes.Process;
199+
Done : Boolean := False;
200+
Stdout : VSS.Stream_Element_Vectors.Stream_Element_Vector;
201+
Stderr : VSS.Stream_Element_Vectors.Stream_Element_Vector;
186202
end record;
187203

204+
overriding procedure Standard_Output_Available
205+
(Self : in out Shell_Listener);
206+
207+
overriding procedure Standard_Error_Available
208+
(Self : in out Shell_Listener);
209+
188210
overriding procedure Finished
189211
(Self : in out Shell_Listener;
190212
Exit_Code : Integer);
@@ -193,6 +215,10 @@ package body Tester.Tests is
193215
(Self : in out Shell_Listener;
194216
Process_Error : Integer);
195217

218+
--------------------
219+
-- Error_Occurred --
220+
--------------------
221+
196222
overriding procedure Error_Occurred
197223
(Self : in out Shell_Listener;
198224
Process_Error : Integer) is
@@ -210,6 +236,10 @@ package body Tester.Tests is
210236
Self.Done := True;
211237
end Error_Occurred;
212238

239+
--------------
240+
-- Finished --
241+
--------------
242+
213243
overriding procedure Finished
214244
(Self : in out Shell_Listener;
215245
Exit_Code : Integer) is
@@ -230,23 +260,85 @@ package body Tester.Tests is
230260
Self.Done := True;
231261
end Finished;
232262

233-
Shell : Spawn.Processes.Process;
263+
-----------
264+
-- Print --
265+
-----------
266+
267+
procedure Print (V : VSS.Stream_Element_Vectors.Stream_Element_Vector) is
268+
use type Ada.Streams.Stream_Element_Count;
269+
Decoder : VSS.Strings.Converters.Decoders.Virtual_String_Decoder;
270+
Text : VSS.Strings.Virtual_String;
271+
begin
272+
if V.Length > 0 then
273+
Decoder.Initialize (VSS.Strings.To_Virtual_String ("utf-8"));
274+
Text := Decoder.Decode (V);
275+
Ada.Text_IO.Put_Line
276+
(VSS.Strings.Conversions.To_UTF_8_String (Text));
277+
end if;
278+
end Print;
279+
280+
------------------------------
281+
-- Standard_Error_Available --
282+
------------------------------
283+
284+
overriding procedure Standard_Error_Available
285+
(Self : in out Shell_Listener)
286+
is
287+
use type Ada.Streams.Stream_Element_Count;
288+
Data : Ada.Streams.Stream_Element_Array (1 .. 512);
289+
Last : Ada.Streams.Stream_Element_Count;
290+
begin
291+
loop
292+
Self.Process.Read_Standard_Error (Data, Last);
293+
294+
exit when Last < 1;
295+
296+
for X of Data (1 .. Last) loop
297+
Self.Stderr.Append (X);
298+
end loop;
299+
end loop;
300+
end Standard_Error_Available;
301+
302+
-------------------------------
303+
-- Standard_Output_Available --
304+
-------------------------------
305+
306+
overriding procedure Standard_Output_Available
307+
(Self : in out Shell_Listener)
308+
is
309+
use type Ada.Streams.Stream_Element_Count;
310+
Data : Ada.Streams.Stream_Element_Array (1 .. 512);
311+
Last : Ada.Streams.Stream_Element_Count;
312+
begin
313+
loop
314+
Self.Process.Read_Standard_Output (Data, Last);
315+
316+
exit when Last < 1;
317+
318+
for X of Data (1 .. Last) loop
319+
Self.Stdout.Append (X);
320+
end loop;
321+
end loop;
322+
end Standard_Output_Available;
234323

235324
Listener : aliased Shell_Listener;
236325
begin
237326
for J in 2 .. GNATCOLL.JSON.Length (List) loop
238327
Args.Append (GNATCOLL.JSON.Get (List, J).Get);
239328
end loop;
240329

241-
Shell.Set_Listener (Listener'Unchecked_Access);
242-
Shell.Set_Program (Cmd);
243-
Shell.Set_Arguments (Args);
244-
Shell.Start;
330+
Listener.Process.Set_Listener (Listener'Unchecked_Access);
331+
Listener.Process.Set_Program (Cmd);
332+
Listener.Process.Set_Arguments (Args);
333+
Listener.Process.Start;
245334

246335
loop
247336
Spawn.Processes.Monitor_Loop (Timeout => 10);
248337
exit when Listener.Done;
249338
end loop;
339+
340+
Print (Listener.Stdout);
341+
Print (Listener.Stderr);
250342
end Do_Shell;
251343

252344
--------------

testsuite/ada_lsp/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ should be in server response, but some values have a special meaning:
9494

9595
Property value - array of strings.
9696

97-
Tester launches a shell command taking command and arguments from the array.
97+
Tester launches an OS process taking command and arguments from the array.
98+
The primary purpose is to launch a Python like this:
99+
100+
"shell": ["${PYTHON}", "${DIR}/makelink.py" ]
98101

99102
### Command `comment`
100103

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
import os.path
3+
import sys
4+
5+
dir=os.path.dirname(sys.argv[0])
6+
link=os.path.join (dir, 'link')
7+
if not os.path.exists(link):
8+
os.symlink('prj', link)

testsuite/ada_lsp/project_symlinks/test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"the 'link/aaa.ads' file shouldn't be referred as 'prj/aaa.ads'"
77
]
88
}, {
9-
"shell": ["sh", "-c", "rm -rf ${DIR}/link; ln -s prj ${DIR}/link" ]
9+
"shell": ["${PYTHON}", "${DIR}/makelink.py" ]
1010
}, {
1111
"start": {
1212
"cmd": ["${ALS}"]

0 commit comments

Comments
 (0)