diff --git a/il2c.sln b/il2c.sln index 66ce49cf..29f8ee61 100644 --- a/il2c.sln +++ b/il2c.sln @@ -50,8 +50,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IL2C.Core.Test.BasicTypes", {2CBC90EC-5581-452F-8231-086E4553D20E} = {2CBC90EC-5581-452F-8231-086E4553D20E} EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IL2C.Core.Test.Common", "tests\IL2C.Core.Test.Common\IL2C.Core.Test.Common.csproj", "{6811E378-50B3-4206-BB48-1E56A2F2D90E}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IL2C.Core.Test.ILConverters", "tests\IL2C.Core.Test.ILConverters\IL2C.Core.Test.ILConverters.csproj", "{DC306000-300C-4E65-826C-2E41C6445CA9}" ProjectSection(ProjectDependencies) = postProject {BB7FA204-433A-416B-B9D0-9A79DF874284} = {BB7FA204-433A-416B-B9D0-9A79DF874284} @@ -146,10 +144,6 @@ Global {A6072CD1-A526-45F2-BB88-D1040AC3A7E8}.Debug|Any CPU.Build.0 = Debug|Any CPU {A6072CD1-A526-45F2-BB88-D1040AC3A7E8}.Release|Any CPU.ActiveCfg = Release|Any CPU {A6072CD1-A526-45F2-BB88-D1040AC3A7E8}.Release|Any CPU.Build.0 = Release|Any CPU - {6811E378-50B3-4206-BB48-1E56A2F2D90E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6811E378-50B3-4206-BB48-1E56A2F2D90E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6811E378-50B3-4206-BB48-1E56A2F2D90E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6811E378-50B3-4206-BB48-1E56A2F2D90E}.Release|Any CPU.Build.0 = Release|Any CPU {DC306000-300C-4E65-826C-2E41C6445CA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DC306000-300C-4E65-826C-2E41C6445CA9}.Debug|Any CPU.Build.0 = Debug|Any CPU {DC306000-300C-4E65-826C-2E41C6445CA9}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -192,7 +186,6 @@ Global EndGlobalSection GlobalSection(NestedProjects) = preSolution {A6072CD1-A526-45F2-BB88-D1040AC3A7E8} = {5710A57F-57F8-4D50-8C78-82E2DFDCB613} - {6811E378-50B3-4206-BB48-1E56A2F2D90E} = {5710A57F-57F8-4D50-8C78-82E2DFDCB613} {DC306000-300C-4E65-826C-2E41C6445CA9} = {5710A57F-57F8-4D50-8C78-82E2DFDCB613} {E397A251-4373-4A8E-AA13-3891282DEDC7} = {5710A57F-57F8-4D50-8C78-82E2DFDCB613} {C26C4683-9840-4307-8774-F1F952E3591B} = {D105E6CD-626A-4C04-8AF6-0AA34A4E9CF4} diff --git a/tests/IL2C.Core.Test.BasicTypes/IL2C.Core.Test.BasicTypes.csproj b/tests/IL2C.Core.Test.BasicTypes/IL2C.Core.Test.BasicTypes.csproj index f4e0de9f..ee517a8b 100644 --- a/tests/IL2C.Core.Test.BasicTypes/IL2C.Core.Test.BasicTypes.csproj +++ b/tests/IL2C.Core.Test.BasicTypes/IL2C.Core.Test.BasicTypes.csproj @@ -17,6 +17,7 @@ Library False enable + true $(DefineConstants);$(OS) IL2C.Core.Test.BasicTypes @@ -38,10 +39,12 @@ + + diff --git a/tests/IL2C.Core.Test.Common/IL2C.Core.Test.Common.csproj b/tests/IL2C.Core.Test.Common/IL2C.Core.Test.Common.csproj deleted file mode 100644 index b9b2cc9d..00000000 --- a/tests/IL2C.Core.Test.Common/IL2C.Core.Test.Common.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - net48;net6.0 - Library - enable - - IL2C.Core.Test.Common - - - - - - - - - - - diff --git a/tests/IL2C.Core.Test.Common/Templates/TestMain.cs b/tests/IL2C.Core.Test.Common/Templates/TestMain.cs new file mode 100644 index 00000000..87fd6f3d --- /dev/null +++ b/tests/IL2C.Core.Test.Common/Templates/TestMain.cs @@ -0,0 +1,50 @@ +//////////////////////////////////////////////////////////////////////////// +// +// IL2C - A translator for ECMA-335 CIL/MSIL to C language. +// Copyright (c) Kouji Matsui (@kozy_kekyo, @kekyo@mastodon.cloud) +// +// Licensed under Apache-v2: https://opensource.org/licenses/Apache-2.0 +// +//////////////////////////////////////////////////////////////////////////// + +using System; + +namespace IL2C.Tests +{ + public static class TestMain + { + public static int Main() + { + try + { +#if {mainIsVoid} + //////////////////////// + // Execute target function. + + {mainSymbol}(); +#else + //////////////////////// + // Execute target function. + + var actual = {mainSymbol}(); + + //////////////////////// + // Check result. + + if (actual != {expected}) + { + Console.WriteLine(actual?.ToString()); + return 1; + } +#endif + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + return 2; + } + + return 0; + } + } +} diff --git a/tests/IL2C.Core.Test.Common/TestCaseAttribute.cs b/tests/IL2C.Core.Test.Common/TestCaseAttribute.cs index db110d5f..048d505a 100644 --- a/tests/IL2C.Core.Test.Common/TestCaseAttribute.cs +++ b/tests/IL2C.Core.Test.Common/TestCaseAttribute.cs @@ -159,12 +159,12 @@ public RunOnOSs RunOnOSs this.runOnOSs = value; var ignores = new List(); - if (Utilities.IsRunningOnWindows && + if (TestUtilities.IsRunningOnWindows && !value.HasFlag(RunOnOSs.Windows)) { ignores.Add("NotWindows"); } - if (!Utilities.IsRunningOnWindows && + if (!TestUtilities.IsRunningOnWindows && !value.HasFlag(RunOnOSs.Posix)) { ignores.Add("NotPosix"); @@ -195,12 +195,12 @@ public RunOnPlatforms RunOnPlatforms this.runOnPlatforms = value; var ignores = new List(); - if (!Utilities.IsRunningOnMono && + if (!TestUtilities.IsRunningOnMono && !value.HasFlag(RunOnPlatforms.DotNet)) { ignores.Add("NotDotNet"); } - if (Utilities.IsRunningOnMono && + if (TestUtilities.IsRunningOnMono && !value.HasFlag(RunOnPlatforms.Mono)) { ignores.Add("NotMono"); @@ -237,58 +237,5 @@ public void AfterTest(ITest test) { // TODO: delegates to test native code. } - -#if false - private static object?[] ConvertToArgumentsType(object?[] args, Type[] argumentTypes) => - args.Zip(argumentTypes, ConvertToArgumentType).ToArray(); - - private static object? ConvertToArgumentType(object? value, Type argumentType) - { - // This is helper function that convert between raw value type and argument type. - // Because .NET attribute can't have complex type arguments. - if (value == null) - { - return null; - } - else if (value.GetType() == argumentType) - { - return value; - } - else if (argumentType == typeof(IntPtr)) - { - if (value is int) - { - return new IntPtr((int)value); - } - else if (value is long) - { - return new IntPtr((long)value); - } - else - { - throw new InvalidCastException(); - } - } - else if (argumentType == typeof(UIntPtr)) - { - if (value is uint) - { - return new UIntPtr((uint)value); - } - else if (value is ulong) - { - return new UIntPtr((ulong)value); - } - else - { - throw new InvalidCastException(); - } - } - else - { - return Convert.ChangeType(value, argumentType); - } - } -#endif } } diff --git a/tests/IL2C.Core.Test.Common/Utilities.cs b/tests/IL2C.Core.Test.Common/TestUtilities.cs similarity index 94% rename from tests/IL2C.Core.Test.Common/Utilities.cs rename to tests/IL2C.Core.Test.Common/TestUtilities.cs index 401bf774..3ac9c549 100644 --- a/tests/IL2C.Core.Test.Common/Utilities.cs +++ b/tests/IL2C.Core.Test.Common/TestUtilities.cs @@ -15,7 +15,7 @@ namespace IL2C { [IgnoreTranslation] - public static class Utilities + public static class TestUtilities { public static readonly bool IsRunningOnWindows = Environment.OSVersion.Platform == PlatformID.Win32NT; diff --git a/tests/IL2C.Core.Test.ILConverters/IL2C.Core.Test.ILConverters.csproj b/tests/IL2C.Core.Test.ILConverters/IL2C.Core.Test.ILConverters.csproj index e21e040b..93908afa 100644 --- a/tests/IL2C.Core.Test.ILConverters/IL2C.Core.Test.ILConverters.csproj +++ b/tests/IL2C.Core.Test.ILConverters/IL2C.Core.Test.ILConverters.csproj @@ -17,6 +17,7 @@ Library False enable + true $(DefineConstants);$(OS) IL2C.Core.Test.ILConverters @@ -38,6 +39,7 @@ + diff --git a/tests/IL2C.Core.Test.RuntimeSystems/IL2C.Core.Test.RuntimeSystems.csproj b/tests/IL2C.Core.Test.RuntimeSystems/IL2C.Core.Test.RuntimeSystems.csproj index a3ef22be..8a23debd 100644 --- a/tests/IL2C.Core.Test.RuntimeSystems/IL2C.Core.Test.RuntimeSystems.csproj +++ b/tests/IL2C.Core.Test.RuntimeSystems/IL2C.Core.Test.RuntimeSystems.csproj @@ -17,6 +17,7 @@ Library False enable + true $(DefineConstants);$(OS) IL2C.Core.Test.RuntimeSystems @@ -38,6 +39,7 @@ +