-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Покрытие через внешние тесты #1357
Open
dmpas
wants to merge
5
commits into
develop
Choose a base branch
from
feature/testrunner-coverage
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+196
−0
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/*---------------------------------------------------------- | ||
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"); | ||
} | ||
|
||
[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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="JunitXml.TestLogger" Version="3.0.124" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0"/> | ||
<PackageReference Include="xunit" Version="2.4.1"/> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\OneScript.StandardLibrary\OneScript.StandardLibrary.csproj" /> | ||
<ProjectReference Include="..\..\ScriptEngine.HostedScript\ScriptEngine.HostedScript.csproj" /> | ||
<ProjectReference Include="..\..\ScriptEngine\ScriptEngine.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/*---------------------------------------------------------- | ||
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; | ||
using ScriptEngine.HostedScript; | ||
using ScriptEngine.HostedScript.Extensions; | ||
using ScriptEngine.Hosting; | ||
using ScriptEngine.Machine; | ||
using ScriptEngine.Machine.Contexts; | ||
|
||
namespace TestRunner; | ||
|
||
[ContextClass("ПроверкиЗначений")] | ||
public class TestRunnerHelper : AutoContext<TestRunnerHelper> | ||
{ | ||
|
||
public const string GetTestSubName = "ПолучитьСписокТестов"; | ||
|
||
private static ScriptingEngine _instance; | ||
|
||
private static ScriptingEngine Instance | ||
{ | ||
get | ||
{ | ||
if (_instance == null) | ||
{ | ||
_instance = DefaultEngineBuilder | ||
.Create() | ||
.SetDefaultOptions() | ||
.SetupEnvironment(e => | ||
{ | ||
e.AddStandardLibrary() | ||
.UseTemplateFactory(new DefaultTemplatesFactory()); | ||
}) | ||
.Build(); | ||
|
||
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); | ||
|
||
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(); | ||
|
||
var getTestsIndex = testInstance.GetMethodNumber(GetTestSubName); | ||
var tmp1 = testRunnerInstance.GetMethodNumber("ПроверитьРавенство"); | ||
dmpas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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<IValue>()); | ||
} | ||
} | ||
|
||
[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); | ||
} | ||
|
||
[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); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
бррр
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
я с ходу не нашёл, откуда вытащить корень исходника.