Skip to content

Commit b2382e8

Browse files
committed
Merge branch 'leo/38-cont_aggr' into 'master'
Add test for container aggregates and generalized array aggregates See merge request eng/cov/gnatcoverage!230 The test for container aggregates does nothing useful, in a convoluted way simply for the sake of introducing decisions in the expressions of the keys of the aggregates. The test also fails as Libadalang doesn't support the `[use Key_Expression]` syntax as of yet, so gnatcov fails to instrument the source file.
2 parents 9861776 + e598f40 commit b2382e8

File tree

20 files changed

+347
-0
lines changed

20 files changed

+347
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
pragma Ada_2022;
2+
3+
package body Pkg is
4+
5+
function Absolute (Input : Int_Arr) return Int_Arr is
6+
begin
7+
if Input = [] then -- # empty_aggr_guard
8+
return []; -- # empty_aggr_st
9+
elsif Input'Length = 1 then -- # single_elt_guard
10+
return -- # single_elt_st
11+
[(declare Elt : Integer renames Input (Input'First); -- # single_elt_st
12+
begin (if Elt > 0 then Elt else -Elt))]; -- # single_elt_dc
13+
else
14+
return [for Idx in Input'Range => -- # multi_elt_st
15+
(declare Elt : Integer renames Input (Idx) ; -- # multi_elt_st
16+
begin (if Elt > 0 then Elt else -Elt))]; -- # multi_elt_dc
17+
end if;
18+
end Absolute;
19+
20+
end Pkg;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package Pkg is
2+
3+
type Int_Arr is array (Positive range <>) of Integer;
4+
5+
function Absolute (Input : Int_Arr) return Int_Arr;
6+
7+
end Pkg;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
with Pkg; use Pkg;
2+
3+
procedure Test_0 is
4+
begin
5+
null;
6+
end Test_0;
7+
8+
--# pkg.adb
9+
--
10+
-- /empty_aggr_guard/ l- ## s-
11+
-- /empty_aggr_st/ l- ## s-
12+
-- /single_elt_guard/ l- ## s-
13+
-- /single_elt_st/ l- ## s-
14+
-- /single_elt_dc/ l- ## 0
15+
-- /multi_elt_st/ l- ## s-
16+
-- /multi_elt_dc/ l- ## 0
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
pragma Ada_2022;
2+
3+
with Pkg; use Pkg;
4+
5+
with Support; use Support;
6+
7+
procedure Test_Empty is
8+
begin
9+
Assert (Absolute ([]) = []);
10+
end Test_Empty;
11+
12+
--# pkg.adb
13+
--
14+
-- /empty_aggr_guard/ l! ## dF-
15+
-- /empty_aggr_st/ l+ ## 0
16+
-- /single_elt_guard/ l- ## s-
17+
-- /single_elt_st/ l- ## s-
18+
-- /single_elt_dc/ l- ## 0
19+
-- /multi_elt_st/ l- ## s-
20+
-- /multi_elt_dc/ l- ## 0
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
pragma Ada_2022;
2+
3+
with Pkg; use Pkg;
4+
5+
with Support; use Support;
6+
7+
procedure Test_Full is
8+
begin
9+
Assert (Absolute ([]) = []);
10+
Assert (Absolute ([9]) = [9]);
11+
Assert (Absolute ([-8]) = [8]);
12+
Assert (Absolute ([-3, 2]) = [3, 2]);
13+
end Test_Full;
14+
15+
--# pkg.adb
16+
--
17+
-- /empty_aggr_guard/ l+ ## 0
18+
-- /empty_aggr_st/ l+ ## 0
19+
-- /single_elt_guard/ l+ ## 0
20+
-- /single_elt_st/ l+ ## 0
21+
-- /single_elt_dc/ l+ ## 0
22+
-- /multi_elt_st/ l+ ## 0
23+
-- /multi_elt_dc/ l+ ## 0
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
pragma Ada_2022;
2+
3+
with Pkg; use Pkg;
4+
5+
with Support; use Support;
6+
7+
procedure Test_Multi is
8+
begin
9+
Assert (Absolute ([9, 4]) = [9, 4]);
10+
end Test_Multi;
11+
12+
--# pkg.adb
13+
--
14+
-- /empty_aggr_guard/ l! ## dT-
15+
-- /empty_aggr_st/ l- ## s-
16+
-- /single_elt_guard/ l! ## dT-
17+
-- /single_elt_st/ l- ## s-
18+
-- /single_elt_dc/ l- ## 0
19+
-- /multi_elt_st/ l+ ## 0
20+
-- /multi_elt_dc/ l! ## dF-
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
pragma Ada_2022;
2+
3+
with Pkg; use Pkg;
4+
5+
with Support; use Support;
6+
7+
procedure Test_Single is
8+
begin
9+
Assert (Absolute ([9]) = [9]);
10+
end Test_Single;
11+
12+
--# pkg.adb
13+
--
14+
-- /empty_aggr_guard/ l! ## dT-
15+
-- /empty_aggr_st/ l- ## s-
16+
-- /single_elt_guard/ l! ## dF-
17+
-- /single_elt_st/ l+ ## 0
18+
-- /single_elt_dc/ l! ## dF-
19+
-- /multi_elt_st/ l- ## s-
20+
-- /multi_elt_dc/ l- ## 0
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
** DC for decisions nested in generalized array aggregates **
2+
3+
Check proper handling and decision coverage computing for decisions nested in
4+
generalized array aggregates. Pkg implements a function presenting three forms
5+
of generalized array aggregates, i.e. a positional empty aggregate, a single
6+
element positional aggregate and a iterated component association aggregate.
7+
8+
The test drivers are articulated as follows:
9+
- Test_0 ensures only statement violations are reported when the
10+
function is not called,
11+
- Test_Empty ensures that decision coverage can be computed on a decision
12+
containing an empty generalized array aggregate,
13+
- Test_Single ensures that decisions nested within a single element positional
14+
aggregate are correctly processed,
15+
- Test_Multi ensures that decisions nested within iterated component
16+
associations in a generalized array aggregate are properly processed.
17+
- Test_Full ensures all the above can be covered simultaneously.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
Test correct support for generalized array aggregates, including iterated
3+
component associations.
4+
"""
5+
6+
7+
from SCOV.tc import TestCase
8+
from SCOV.tctl import CAT
9+
from SUITE.context import thistest
10+
11+
12+
TestCase(category=CAT.decision).run()
13+
thistest.result()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
pragma Ada_2022;
2+
3+
with Ada.Containers; use Ada.Containers;
4+
5+
with Pkg; use Pkg;
6+
7+
with Support; use Support;
8+
9+
procedure Check (Input : Int_Set) is
10+
use Int_Maps;
11+
Res : constant Int_Map := Overly_Complex_Identity_Build (Input);
12+
begin
13+
Assert (Input.Length = Res.Length);
14+
Assert ((for all Val of Input =>
15+
(declare Cur : constant Cursor := Res.Find (Val);
16+
begin Has_Element (Cur)
17+
and then Key (Cur) = Val
18+
and then Element (Cur) = Val)));
19+
end Check;

0 commit comments

Comments
 (0)