Skip to content

Commit

Permalink
Merge branch 'topic/machu/236-language-version-flags' into 'master'
Browse files Browse the repository at this point in the history
Append language version flag to `test_driver`

Closes #236

See merge request eng/ide/libadalang-tools!295
  • Loading branch information
Volham22 committed Jan 8, 2025
2 parents 0412a22 + 694f871 commit bfe5c9e
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 29 deletions.
36 changes: 26 additions & 10 deletions src/test-common.adb
Original file line number Diff line number Diff line change
Expand Up @@ -1305,11 +1305,11 @@ package body Test.Common is
Data.Default_Config.Enabled or not Data.File_Configs.Is_Empty;
end Extract_Preprocessor_Config;

-----------------------------------------
-- Write_Preprocessor_Compiler_Package --
-----------------------------------------
------------------------------------
-- Write_Additional_Compiler_Flags --
------------------------------------

procedure Write_Preprocessor_Compiler_Package
procedure Write_Additional_Compiler_Flags
(Preprocessor_Config_Dir : String) is
begin
Preprocessor_Config.Write_Preprocessor_Data_File
Expand All @@ -1324,14 +1324,30 @@ package body Test.Common is
Put_New_Line;
S_Put (9, "Gnattest_Common.Compiler'Default_Switches (""Ada"")");
Put_New_Line;
S_Put (12, "& (""-gnatep="
& Preprocessor_Config_Dir
& GNAT.OS_Lib.Directory_Separator
& Test.Common.Preprocessor_File_Name
& """);");

if Test.Common.Has_Preprocessor then
S_Put (12, "& (""-gnatep="
& Preprocessor_Config_Dir
& GNAT.OS_Lib.Directory_Separator
& Test.Common.Preprocessor_File_Name
& """)");
end if;

S_Put
(12,
"& ("""
& (case Lang_Version is
when Ada_83 => "-gnat83",
when Ada_95 => "-gnat95",
when Ada_2005 => "-gnat2005",
when Ada_2012 => "-gnat2012",
when Ada_2022 => "-gnat2022")
& """)");

S_Put (0, ";");
Put_New_Line;
S_Put (3, "end Compiler;");
end Write_Preprocessor_Compiler_Package;
end Write_Additional_Compiler_Flags;

----------------------------
-- Common_Subp_Node_Filter --
Expand Down
9 changes: 5 additions & 4 deletions src/test-common.ads
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,11 @@ package Test.Common is
-- `Has_Preprocessor` and retrieve the configuration using
-- `Preprocessor_Config` field if possible.

procedure Write_Preprocessor_Compiler_Package
(Preprocessor_Config_Dir : String) with Pre => Has_Preprocessor;
-- Write GPR Compiler package which appends preprocessor flags to the
-- common gnattest compiler flags
procedure Write_Additional_Compiler_Flags
(Preprocessor_Config_Dir : String);
-- Write additional compiler flags if needed such as preprocessing flags
-- and language version. This function only appends flags to the existing
-- one in `gnattest_common.gpr`.

Preprocessor_Config : Libadalang.Preprocessing.Preprocessor_Data;
-- Preprocessor config for the loaded user project.
Expand Down
8 changes: 1 addition & 7 deletions src/test-harness.adb
Original file line number Diff line number Diff line change
Expand Up @@ -1224,13 +1224,7 @@ package body Test.Harness is
S_Put (3, "package Binder renames Gnattest_Common.Binder;");
Put_New_Line;

-- Write a preprocessor definition file and append the `gnatep` flag
-- in the test_driver's project file.
if Test.Common.Has_Preprocessor then
Test.Common.Write_Preprocessor_Compiler_Package (Harness_Dir.all);
else
S_Put (3, "package Compiler renames Gnattest_Common.Compiler;");
end if;
Test.Common.Write_Additional_Compiler_Flags (Harness_Dir.all);

Put_New_Line;
Put_New_Line;
Expand Down
6 changes: 1 addition & 5 deletions src/test-skeleton.adb
Original file line number Diff line number Diff line change
Expand Up @@ -9009,11 +9009,7 @@ package body Test.Skeleton is
S_Put (3, "for Languages use Gnattest_Common'Languages & (""Ada"");");
Put_New_Line;

if Test.Common.Has_Preprocessor then
Test.Common.Write_Preprocessor_Compiler_Package (Harness_Dir_Str.all);
else
S_Put (3, "package Compiler renames Gnattest_Common.Compiler;");
end if;
Test.Common.Write_Additional_Compiler_Flags (Harness_Dir_Str.all);
Put_New_Line;
Put_New_Line;

Expand Down
8 changes: 8 additions & 0 deletions testsuite/tests/test/236-ada-2022-source/build.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
project Build is
for Source_Dirs use ("src");

package Compiler is
for Switches ("ada") use ("-gnat2022");
end Compiler;

end Build;
5 changes: 5 additions & 0 deletions testsuite/tests/test/236-ada-2022-source/src/pkg.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package Pkg is
type Bool_Int is range 0 .. 1;
-- Reverse mapping is only available with Ada 2022
function To_Bool (X : Bool_Int) return Boolean is (Boolean'Val (X));
end Pkg;
7 changes: 7 additions & 0 deletions testsuite/tests/test/236-ada-2022-source/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pkg.ads:4:4: info: corresponding test PASSED
pkg.ads:4:4: info: corresponding test PASSED
pkg.ads:4:4: info: corresponding test PASSED
pkg.ads:4:4: info: corresponding test PASSED
pkg.ads:4:4: info: corresponding test PASSED
pkg.ads:4:4: error: corresponding test FAILED: Test not implemented. (pkg-test_data-tests.adb:45)
6 tests run: 5 passed; 1 failed; 0 crashed.
5 changes: 5 additions & 0 deletions testsuite/tests/test/236-ada-2022-source/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

gnattest -q -gnat2022 -P build.gpr --gen-test-vectors
gprbuild -q -P ./gnattest/harness/test_driver.gpr
./gnattest/harness/test_runner
3 changes: 3 additions & 0 deletions testsuite/tests/test/236-ada-2022-source/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
description: Check that gnattest and TGen handles Ada 2022 sources properly

driver: shell_script
14 changes: 11 additions & 3 deletions testsuite/tests/test/TA07-010/test.out
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ project test_simple is

for Object_Dir use "test_obj";
for Languages use Gnattest_Common'Languages & ("Ada");
package Compiler renames Gnattest_Common.Compiler;
package Compiler extends Gnattest_Common.Compiler is
for Default_Switches ("Ada") use
Gnattest_Common.Compiler'Default_Switches ("Ada")
& ("-gnat2012");
end Compiler;

package Coverage is
for Units use ();
Expand All @@ -34,7 +38,11 @@ project Test_Driver is
package Builder renames Gnattest_Common.Builder;
package Linker renames Gnattest_Common.Linker;
package Binder renames Gnattest_Common.Binder;
package Compiler renames Gnattest_Common.Compiler;
package Compiler extends Gnattest_Common.Compiler is
for Default_Switches ("Ada") use
Gnattest_Common.Compiler'Default_Switches ("Ada")
& ("-gnat2012");
end Compiler;

package Coverage is
for Units use ();
Expand All @@ -44,4 +52,4 @@ project Test_Driver is
for GNATTest_Mapping_File use "gnattest.xml";
end GNATtest;

end Test_Driver;
end Test_Driver;

0 comments on commit bfe5c9e

Please sign in to comment.