From 93822d46635e87db4129fd92775452e3364a3336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Creuse?= Date: Wed, 9 Oct 2024 14:38:21 +0200 Subject: [PATCH] Test: Comment out dangling stub setters Dangling stub setters can reference entites no longer existing in the code base and thus prevent compilation if not commented out. (cherry picked from commit 38d3bdea8e77278a3cbab5d1339e9927cb185eaf) --- src/test-stub.adb | 4 ++-- .../tests/test/36-stub_dangling_setters/new/dep.adb | 8 ++++++++ .../tests/test/36-stub_dangling_setters/new/dep.ads | 5 +++++ .../tests/test/36-stub_dangling_setters/new/root.adb | 10 ++++++++++ .../tests/test/36-stub_dangling_setters/new/root.ads | 5 +++++ .../tests/test/36-stub_dangling_setters/old/dep.adb | 8 ++++++++ .../tests/test/36-stub_dangling_setters/old/dep.ads | 7 +++++++ .../tests/test/36-stub_dangling_setters/old/root.adb | 10 ++++++++++ .../tests/test/36-stub_dangling_setters/old/root.ads | 5 +++++ .../tests/test/36-stub_dangling_setters/prj.gpr | 8 ++++++++ .../tests/test/36-stub_dangling_setters/test.out | 5 +++++ .../tests/test/36-stub_dangling_setters/test.sh | 12 ++++++++++++ .../tests/test/36-stub_dangling_setters/test.yaml | 6 ++++++ 13 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 testsuite/tests/test/36-stub_dangling_setters/new/dep.adb create mode 100644 testsuite/tests/test/36-stub_dangling_setters/new/dep.ads create mode 100644 testsuite/tests/test/36-stub_dangling_setters/new/root.adb create mode 100644 testsuite/tests/test/36-stub_dangling_setters/new/root.ads create mode 100644 testsuite/tests/test/36-stub_dangling_setters/old/dep.adb create mode 100644 testsuite/tests/test/36-stub_dangling_setters/old/dep.ads create mode 100644 testsuite/tests/test/36-stub_dangling_setters/old/root.adb create mode 100644 testsuite/tests/test/36-stub_dangling_setters/old/root.ads create mode 100644 testsuite/tests/test/36-stub_dangling_setters/prj.gpr create mode 100644 testsuite/tests/test/36-stub_dangling_setters/test.out create mode 100644 testsuite/tests/test/36-stub_dangling_setters/test.sh create mode 100644 testsuite/tests/test/36-stub_dangling_setters/test.yaml diff --git a/src/test-stub.adb b/src/test-stub.adb index 63b440d2..90a6626b 100755 --- a/src/test-stub.adb +++ b/src/test-stub.adb @@ -3666,7 +3666,7 @@ package body Test.Stub is S_Put (0, GT_Marker_End); New_Line_Count; - Put_Lines (MD, Comment_Out => False); + Put_Lines (MD, Comment_Out => True); S_Put (0, GT_Marker_Begin); New_Line_Count; @@ -3796,7 +3796,7 @@ package body Test.Stub is S_Put (0, GT_Marker_End); New_Line_Count; - Put_Lines (MD, Comment_Out => False); + Put_Lines (MD, Comment_Out => True); S_Put (0, GT_Marker_Begin); New_Line_Count; diff --git a/testsuite/tests/test/36-stub_dangling_setters/new/dep.adb b/testsuite/tests/test/36-stub_dangling_setters/new/dep.adb new file mode 100644 index 00000000..cd2c3271 --- /dev/null +++ b/testsuite/tests/test/36-stub_dangling_setters/new/dep.adb @@ -0,0 +1,8 @@ +package body Dep is + + function Baz (X : Integer) return Integer is + begin + return X; + end Baz; + +end Dep; diff --git a/testsuite/tests/test/36-stub_dangling_setters/new/dep.ads b/testsuite/tests/test/36-stub_dangling_setters/new/dep.ads new file mode 100644 index 00000000..e75aa1b9 --- /dev/null +++ b/testsuite/tests/test/36-stub_dangling_setters/new/dep.ads @@ -0,0 +1,5 @@ +package Dep is + + function Baz (X : Integer) return Integer; + +end Dep; diff --git a/testsuite/tests/test/36-stub_dangling_setters/new/root.adb b/testsuite/tests/test/36-stub_dangling_setters/new/root.adb new file mode 100644 index 00000000..21929cb7 --- /dev/null +++ b/testsuite/tests/test/36-stub_dangling_setters/new/root.adb @@ -0,0 +1,10 @@ +with Dep; + +package body Root is + + function Foo (X : Integer) return Integer is + begin + return Dep.Baz (X); + end Foo; + +end Root; diff --git a/testsuite/tests/test/36-stub_dangling_setters/new/root.ads b/testsuite/tests/test/36-stub_dangling_setters/new/root.ads new file mode 100644 index 00000000..9face2ce --- /dev/null +++ b/testsuite/tests/test/36-stub_dangling_setters/new/root.ads @@ -0,0 +1,5 @@ +package Root is + + function Foo (X : Integer) return Integer; + +end Root; diff --git a/testsuite/tests/test/36-stub_dangling_setters/old/dep.adb b/testsuite/tests/test/36-stub_dangling_setters/old/dep.adb new file mode 100644 index 00000000..1c1fbfa5 --- /dev/null +++ b/testsuite/tests/test/36-stub_dangling_setters/old/dep.adb @@ -0,0 +1,8 @@ +package body Dep is + + function Bar (X : My_Int) return My_Int is + begin + return X; + end Bar; + +end Dep; diff --git a/testsuite/tests/test/36-stub_dangling_setters/old/dep.ads b/testsuite/tests/test/36-stub_dangling_setters/old/dep.ads new file mode 100644 index 00000000..d5e334f8 --- /dev/null +++ b/testsuite/tests/test/36-stub_dangling_setters/old/dep.ads @@ -0,0 +1,7 @@ +package Dep is + + subtype My_Int is Integer; + + function Bar (X : My_Int) return My_Int; + +end Dep; diff --git a/testsuite/tests/test/36-stub_dangling_setters/old/root.adb b/testsuite/tests/test/36-stub_dangling_setters/old/root.adb new file mode 100644 index 00000000..b9c55edb --- /dev/null +++ b/testsuite/tests/test/36-stub_dangling_setters/old/root.adb @@ -0,0 +1,10 @@ +with Dep; + +package body Root is + + function Foo (X : Integer) return Integer is + begin + return Dep.Bar (X); + end Foo; + +end Root; diff --git a/testsuite/tests/test/36-stub_dangling_setters/old/root.ads b/testsuite/tests/test/36-stub_dangling_setters/old/root.ads new file mode 100644 index 00000000..9face2ce --- /dev/null +++ b/testsuite/tests/test/36-stub_dangling_setters/old/root.ads @@ -0,0 +1,5 @@ +package Root is + + function Foo (X : Integer) return Integer; + +end Root; diff --git a/testsuite/tests/test/36-stub_dangling_setters/prj.gpr b/testsuite/tests/test/36-stub_dangling_setters/prj.gpr new file mode 100644 index 00000000..b3f4e614 --- /dev/null +++ b/testsuite/tests/test/36-stub_dangling_setters/prj.gpr @@ -0,0 +1,8 @@ +project Prj is + + type Source is ("old", "new"); + for Source_Dirs use (external ("SRC_DIR", "old")); + for Object_Dir use "obj"; + +end Prj; + diff --git a/testsuite/tests/test/36-stub_dangling_setters/test.out b/testsuite/tests/test/36-stub_dangling_setters/test.out new file mode 100644 index 00000000..402b9485 --- /dev/null +++ b/testsuite/tests/test/36-stub_dangling_setters/test.out @@ -0,0 +1,5 @@ +Units remaining: 4 Units remaining: 3 warning: (gnattest) Dep.Test_Data.Tests has dangling test(s) +Units remaining: 2 Units remaining: 1 warning: (gnattest) Dep has dangling element(s) + warning: (gnattest) Dep.Stub_Data has dangling setter spec(s) + warning: (gnattest) Dep.Stub_Data has dangling setter body(ies) + diff --git a/testsuite/tests/test/36-stub_dangling_setters/test.sh b/testsuite/tests/test/36-stub_dangling_setters/test.sh new file mode 100644 index 00000000..014b869c --- /dev/null +++ b/testsuite/tests/test/36-stub_dangling_setters/test.sh @@ -0,0 +1,12 @@ +#! /bin/bash + +# Generate a stubbing harness with the old sources, containing a custom type +gnattest -P prj.gpr -q -XSRC_DIR=old --stub + +# Re-generate the harness but with the custom type dissapearing. Any remaining +# references to it will cause a compilation failure +gnattest -P prj.gpr -XSRC_DIR=new --stub + +# Build the harness to check that the unused setters are not causing any +# problems. +gprbuild -P obj/gnattest_stub/harness/test_drivers.gpr -q -XSRC_DIR=new diff --git a/testsuite/tests/test/36-stub_dangling_setters/test.yaml b/testsuite/tests/test/36-stub_dangling_setters/test.yaml new file mode 100644 index 00000000..3e3d9d8c --- /dev/null +++ b/testsuite/tests/test/36-stub_dangling_setters/test.yaml @@ -0,0 +1,6 @@ +description: + Check that dangling setters in a stubbing harness do not cause any compilation + issues. They used to not be commented out, which could result in lingering + references to types or objects no longer present in the codebase. + +driver: shell_script