From dede078fb99faee50fdf4fb23f17d89160893d16 Mon Sep 17 00:00:00 2001 From: Sergey Batanov Date: Fri, 29 Sep 2023 23:10:55 +0300 Subject: [PATCH 1/5] =?UTF-8?q?=D0=97=D0=B0=D0=BF=D1=83=D1=81=D0=BA=20?= =?UTF-8?q?=D0=B2=D0=BD=D0=B5=D1=88=D0=BD=D0=B8=D1=85=20=D1=82=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=20=D0=B8=D0=B7=20xunit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/1Script.sln | 13 ++++ src/Tests/TestRunner/ExternalTestsRunner.cs | 18 +++++ src/Tests/TestRunner/TestRunner.csproj | 30 ++++++++ src/Tests/TestRunner/TestRunnerHelper.cs | 84 +++++++++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 src/Tests/TestRunner/ExternalTestsRunner.cs create mode 100644 src/Tests/TestRunner/TestRunner.csproj create mode 100644 src/Tests/TestRunner/TestRunnerHelper.cs diff --git a/src/1Script.sln b/src/1Script.sln index 9da3cfeaf..ab6f576ee 100644 --- a/src/1Script.sln +++ b/src/1Script.sln @@ -58,6 +58,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneScript.Dynamic.Tests", " EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneScript.Native", "OneScript.Native\OneScript.Native.csproj", "{90E896C1-FEAE-4C71-8E47-3E3F2D9C926C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestRunner", "Tests\TestRunner\TestRunner.csproj", "{8A3C7DAD-918F-4A4A-B36C-BCECA12D8A14}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -253,6 +255,16 @@ Global {90E896C1-FEAE-4C71-8E47-3E3F2D9C926C}.Release|x86.Build.0 = Release|Any CPU {90E896C1-FEAE-4C71-8E47-3E3F2D9C926C}.LinuxDebug|Any CPU.ActiveCfg = LinuxDebug|Any CPU {90E896C1-FEAE-4C71-8E47-3E3F2D9C926C}.LinuxDebug|Any CPU.Build.0 = LinuxDebug|Any CPU + {8A3C7DAD-918F-4A4A-B36C-BCECA12D8A14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8A3C7DAD-918F-4A4A-B36C-BCECA12D8A14}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8A3C7DAD-918F-4A4A-B36C-BCECA12D8A14}.Debug|x86.ActiveCfg = Debug|Any CPU + {8A3C7DAD-918F-4A4A-B36C-BCECA12D8A14}.Debug|x86.Build.0 = Debug|Any CPU + {8A3C7DAD-918F-4A4A-B36C-BCECA12D8A14}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8A3C7DAD-918F-4A4A-B36C-BCECA12D8A14}.Release|Any CPU.Build.0 = Release|Any CPU + {8A3C7DAD-918F-4A4A-B36C-BCECA12D8A14}.Release|x86.ActiveCfg = Release|Any CPU + {8A3C7DAD-918F-4A4A-B36C-BCECA12D8A14}.Release|x86.Build.0 = Release|Any CPU + {8A3C7DAD-918F-4A4A-B36C-BCECA12D8A14}.LinuxDebug|Any CPU.ActiveCfg = Debug|Any CPU + {8A3C7DAD-918F-4A4A-B36C-BCECA12D8A14}.LinuxDebug|Any CPU.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -263,6 +275,7 @@ Global {6D02017A-189F-45D7-B286-D67536AB4907} = {91059C5B-526C-4B81-B106-99DEFF542D1F} {55890DF2-D13E-4C89-A01D-79CAD6726246} = {91059C5B-526C-4B81-B106-99DEFF542D1F} {0F5E6099-39BA-41CF-B55F-357F7DF4DE00} = {91059C5B-526C-4B81-B106-99DEFF542D1F} + {8A3C7DAD-918F-4A4A-B36C-BCECA12D8A14} = {91059C5B-526C-4B81-B106-99DEFF542D1F} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {A4A871EF-C5A7-478F-907E-31C69A869973} diff --git a/src/Tests/TestRunner/ExternalTestsRunner.cs b/src/Tests/TestRunner/ExternalTestsRunner.cs new file mode 100644 index 000000000..70105be56 --- /dev/null +++ b/src/Tests/TestRunner/ExternalTestsRunner.cs @@ -0,0 +1,18 @@ +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using Xunit; + +namespace TestRunner; + +public class ExternalTestsRunner +{ + [Fact] + public void TypeDescription() + { + TestRunnerHelper.Run(@"typedescription.os"); + } +} \ No newline at end of file diff --git a/src/Tests/TestRunner/TestRunner.csproj b/src/Tests/TestRunner/TestRunner.csproj new file mode 100644 index 000000000..67c852982 --- /dev/null +++ b/src/Tests/TestRunner/TestRunner.csproj @@ -0,0 +1,30 @@ + + + + net6.0 + enable + enable + + false + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + diff --git a/src/Tests/TestRunner/TestRunnerHelper.cs b/src/Tests/TestRunner/TestRunnerHelper.cs new file mode 100644 index 000000000..c2ef572b8 --- /dev/null +++ b/src/Tests/TestRunner/TestRunnerHelper.cs @@ -0,0 +1,84 @@ +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using Xunit; +using System.Reflection; +using OneScript.Commons; +using OneScript.Contexts; +using OneScript.StandardLibrary; +using OneScript.StandardLibrary.Collections; +using ScriptEngine.HostedScript; +using ScriptEngine.HostedScript.Extensions; +using ScriptEngine.Hosting; +using ScriptEngine.Machine; +using ScriptEngine.Machine.Contexts; + +namespace TestRunner; + +[ContextClass("ПроверкиЗначений")] +public class TestRunnerHelper : AutoContext +{ + + public const string GetTestSubName = "ПолучитьСписокТестов"; + + public static void Run(string filename) + { + var engine = DefaultEngineBuilder + .Create() + .SetDefaultOptions() + .SetupEnvironment(e => + { + e.AddStandardLibrary() + .UseTemplateFactory(new DefaultTemplatesFactory()); + }) + .Build(); + + Locale.SystemLanguageISOName = "RU"; + + var rootPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!; + var filepath = Path.Combine(rootPath, "..", "..", "..", "..", "..", "..", "tests", filename); + + var compiler = engine.GetCompilerService(); + compiler.FillSymbols(typeof(UserScriptContextInstance)); + + var testModule = compiler.Compile(engine.Loader.FromFile(filepath)); + engine.Initialize(); + var testInstance = (UserScriptContextInstance)engine.NewObject(testModule); + var testRunnerInstance = new TestRunnerHelper(); + + engine.Dispose(); + + var getTestsIndex = testInstance.GetMethodNumber(GetTestSubName); + var tmp1 = testRunnerInstance.GetMethodNumber("ПроверитьРавенство"); + Assert.NotEqual(-1, getTestsIndex); + + testInstance.CallAsFunction(getTestsIndex, new []{ testRunnerInstance }, out var result); + Assert.NotNull(result); + + var arrayOfNames = (ArrayImpl)result; + Assert.NotNull(arrayOfNames); + foreach (var testName in arrayOfNames) + { + var testSubIndex = testInstance.GetMethodNumber(testName.AsString()); + Assert.NotEqual(-1, testSubIndex); + + testInstance.CallAsProcedure(testSubIndex, Array.Empty()); + } + } + + [ContextMethod("ПроверитьРавенство")] + public void CheckEqual(IValue v1, IValue v2, string extendedInfo = null) + { + Assert.Equal(v1, v2); + } + + [ContextMethod("ПроверитьНеРавенство")] + public void CheckNotEqual(IValue v1, IValue v2, string extendedInfo = null) + { + Assert.NotEqual(v1, v2); + } + +} \ No newline at end of file From 7d252dfdc3688cc76efe4bcb587a0038cc5ade31 Mon Sep 17 00:00:00 2001 From: Sergey Batanov Date: Fri, 29 Sep 2023 23:19:30 +0300 Subject: [PATCH 2/5] =?UTF-8?q?TestRunner=20=D0=B2=D0=BA=D0=BB=D1=8E=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=B2=20UnitTests.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Build_Core.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/Build_Core.csproj b/Build_Core.csproj index f889c371d..d6b939dd7 100644 --- a/Build_Core.csproj +++ b/Build_Core.csproj @@ -252,6 +252,7 @@ + Date: Sat, 30 Sep 2023 00:06:35 +0300 Subject: [PATCH 3/5] JunitXml.TestLogger --- src/Tests/TestRunner/TestRunner.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Tests/TestRunner/TestRunner.csproj b/src/Tests/TestRunner/TestRunner.csproj index 67c852982..7c3949156 100644 --- a/src/Tests/TestRunner/TestRunner.csproj +++ b/src/Tests/TestRunner/TestRunner.csproj @@ -9,6 +9,7 @@ + From d9ca9c9c7ca6ac990d1d3a5a15fa0e1a8e14d813 Mon Sep 17 00:00:00 2001 From: Sergey Batanov Date: Sat, 30 Sep 2023 10:46:56 +0300 Subject: [PATCH 4/5] =?UTF-8?q?=D0=91=D0=BE=D0=BB=D1=8C=D1=88=D0=B5=20?= =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Tests/TestRunner/ExternalTestsRunner.cs | 24 ++++++++++ src/Tests/TestRunner/TestRunnerHelper.cs | 52 +++++++++++++++------ 2 files changed, 63 insertions(+), 13 deletions(-) diff --git a/src/Tests/TestRunner/ExternalTestsRunner.cs b/src/Tests/TestRunner/ExternalTestsRunner.cs index 70105be56..31e556fcc 100644 --- a/src/Tests/TestRunner/ExternalTestsRunner.cs +++ b/src/Tests/TestRunner/ExternalTestsRunner.cs @@ -15,4 +15,28 @@ public void TypeDescription() { TestRunnerHelper.Run(@"typedescription.os"); } + + [Fact] + public void ValueTree() + { + TestRunnerHelper.Run(@"valuetree.os"); + } + + [Fact] + public void ValueTable() + { + TestRunnerHelper.Run(@"valuetable.os"); + } + + [Fact] + public void ValueList() + { + TestRunnerHelper.Run(@"value-list.os"); + } + + [Fact] + public void Math() + { + TestRunnerHelper.Run(@"math.os"); + } } \ No newline at end of file diff --git a/src/Tests/TestRunner/TestRunnerHelper.cs b/src/Tests/TestRunner/TestRunnerHelper.cs index c2ef572b8..bf1b9fd60 100644 --- a/src/Tests/TestRunner/TestRunnerHelper.cs +++ b/src/Tests/TestRunner/TestRunnerHelper.cs @@ -10,6 +10,7 @@ This Source Code Form is subject to the terms of the using OneScript.Contexts; using OneScript.StandardLibrary; using OneScript.StandardLibrary.Collections; +using ScriptEngine; using ScriptEngine.HostedScript; using ScriptEngine.HostedScript.Extensions; using ScriptEngine.Hosting; @@ -24,19 +25,34 @@ public class TestRunnerHelper : AutoContext public const string GetTestSubName = "ПолучитьСписокТестов"; - public static void Run(string filename) + private static ScriptingEngine _instance; + + private static ScriptingEngine Instance { - var engine = DefaultEngineBuilder - .Create() - .SetDefaultOptions() - .SetupEnvironment(e => + get + { + if (_instance == null) { - e.AddStandardLibrary() - .UseTemplateFactory(new DefaultTemplatesFactory()); - }) - .Build(); + _instance = DefaultEngineBuilder + .Create() + .SetDefaultOptions() + .SetupEnvironment(e => + { + e.AddStandardLibrary() + .UseTemplateFactory(new DefaultTemplatesFactory()); + }) + .Build(); - Locale.SystemLanguageISOName = "RU"; + Locale.SystemLanguageISOName = "RU"; + } + + return _instance; + } + } + + public static void Run(string filename) + { + var engine = Instance; var rootPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!; var filepath = Path.Combine(rootPath, "..", "..", "..", "..", "..", "..", "tests", filename); @@ -48,8 +64,6 @@ public static void Run(string filename) engine.Initialize(); var testInstance = (UserScriptContextInstance)engine.NewObject(testModule); var testRunnerInstance = new TestRunnerHelper(); - - engine.Dispose(); var getTestsIndex = testInstance.GetMethodNumber(GetTestSubName); var tmp1 = testRunnerInstance.GetMethodNumber("ПроверитьРавенство"); @@ -80,5 +94,17 @@ public void CheckNotEqual(IValue v1, IValue v2, string extendedInfo = null) { Assert.NotEqual(v1, v2); } - + + [ContextMethod("ПроверитьИстину")] + public void CheckTrue(IValue v1, string extendedInfo = null) + { + Assert.True(v1?.AsBoolean() ?? false); + } + + [ContextMethod("ПроверитьЛожь")] + public void CheckFalse(IValue v1, string extendedInfo = null) + { + Assert.False(v1?.AsBoolean() ?? true); + } + } \ No newline at end of file From 0cd30807ab107eddda3c0cd14a59ed9a8348a7f9 Mon Sep 17 00:00:00 2001 From: Sergey Batanov Date: Sun, 1 Oct 2023 14:25:08 +0300 Subject: [PATCH 5/5] =?UTF-8?q?=D0=9D=D0=B5=D0=B8=D1=81=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D0=B7=D1=83=D0=B5=D0=BC=D1=8B=D0=B9=20=D0=BA=D0=BE=D0=B4?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Tests/TestRunner/TestRunnerHelper.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Tests/TestRunner/TestRunnerHelper.cs b/src/Tests/TestRunner/TestRunnerHelper.cs index bf1b9fd60..34007d7e0 100644 --- a/src/Tests/TestRunner/TestRunnerHelper.cs +++ b/src/Tests/TestRunner/TestRunnerHelper.cs @@ -66,7 +66,6 @@ public static void Run(string filename) var testRunnerInstance = new TestRunnerHelper(); var getTestsIndex = testInstance.GetMethodNumber(GetTestSubName); - var tmp1 = testRunnerInstance.GetMethodNumber("ПроверитьРавенство"); Assert.NotEqual(-1, getTestsIndex); testInstance.CallAsFunction(getTestsIndex, new []{ testRunnerInstance }, out var result);