From 2c64a6bddf4275f66765ad492023c5a420a65ce7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=A9sar=20Sagaert?= Date: Thu, 27 Mar 2025 13:50:24 +0100 Subject: [PATCH] feat: percentage progress of tests when in TTY (#1917) * feat: add percentage progress of tests when in TTY * Right-align pct * Actually right-align --------- Co-authored-by: Alejandro R. Mosteo --- src/alire/alire-test_runner.adb | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/alire/alire-test_runner.adb b/src/alire/alire-test_runner.adb index 4acf4e61..6654ea70 100644 --- a/src/alire/alire-test_runner.adb +++ b/src/alire/alire-test_runner.adb @@ -1,5 +1,6 @@ with Ada.Containers.Indefinite_Ordered_Maps; with Ada.Containers.Indefinite_Vectors; +with Ada.Strings.Fixed; with Ada.Text_IO; with GNAT.OS_Lib; with System.Multiprocessors; @@ -251,6 +252,26 @@ package body Alire.Test_Runner is Success : Boolean; Remaining : Portable_Path_Vector := Test_List; + Completed : Long_Integer := 0; -- Tests already completed + + ------------------ + -- Put_Progress -- + ------------------ + + procedure Put_Progress is + -- convenience function to print a percentage box when running + -- in a terminal + use Ada.Strings.Fixed; + Len : constant Long_Integer := Long_Integer (Test_List.Length); + -- rounding division + Percentage : constant Long_Integer := + (if Len = 0 then 0 else (Completed * 100 + Len / 2) / Len); + begin + Ada.Text_IO.Put + ("[" & Tail (Percentage'Image, 4) & "% ]" & ASCII.CR); + Ada.Text_IO.Flush; + Completed := Completed + 1; + end Put_Progress; begin @@ -261,6 +282,12 @@ package body Alire.Test_Runner is end loop; loop + if CLIC.TTY.Is_TTY then + -- print completion percentage to indicate progress + Put_Progress; + delay 0.5; + end if; + -- wait for one test to finish Wait_Process (Pid, Success); @@ -286,7 +313,7 @@ package body Alire.Test_Runner is if not Remaining.Is_Empty then -- start up a new test - Spawn_Test (Portable_Path (Remaining.Last_Element)); + Spawn_Test (Remaining.Last_Element); Remaining.Delete_Last; end if; end loop; -- 2.39.5