-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit aab9558
Showing
25 changed files
with
1,104 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,17 @@ | ||
namespace Intent.Assertions | ||
{ | ||
public class Assert | ||
{ | ||
public static void AreEqual<T>(T expected, T actual) | ||
{ | ||
if (expected.Equals(actual)) | ||
{ | ||
throw new TestPassedException(); | ||
} | ||
else | ||
{ | ||
throw new TestFailedException($"Expected {expected}, but got {actual}."); | ||
} | ||
} | ||
} | ||
} |
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,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Intent\Intent.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,42 @@ | ||
using System; | ||
using System.Reflection; | ||
using static System.Console; | ||
using static System.ConsoleColor; | ||
|
||
namespace Intent.Console | ||
{ | ||
internal class ConsoleLogger : IRunLogger | ||
{ | ||
public void WriteTestInconclusive(MethodInfo m) | ||
{ | ||
var currentColor = ForegroundColor; | ||
ForegroundColor = Yellow; | ||
WriteLine($"[?] {m.Name} inconclusive"); | ||
ForegroundColor = currentColor; | ||
} | ||
|
||
public void WriteTestPassed(MethodInfo m) | ||
{ | ||
var currentColor = ForegroundColor; | ||
ForegroundColor = Green; | ||
WriteLine($"[+] {m.Name} passed"); | ||
ForegroundColor = currentColor; | ||
} | ||
|
||
public void WriteTestFailure(MethodInfo m, Exception ex) | ||
{ | ||
var currentColor = ForegroundColor; | ||
ForegroundColor = Red; | ||
WriteLine($"[-] {m.Name} failed{Environment.NewLine}{ex}"); | ||
ForegroundColor = currentColor; | ||
} | ||
|
||
public void WriteFrameworkError(Exception ex) | ||
{ | ||
var currentColor = ForegroundColor; | ||
ForegroundColor = DarkRed; | ||
WriteLine($"[-] framework failed{Environment.NewLine}{ex}{Environment.NewLine}{Environment.NewLine}"); | ||
ForegroundColor = currentColor; | ||
} | ||
} | ||
} |
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,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="System.CommandLine.DragonFruit" Version="0.3.0-alpha.20104.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Intent\Intent.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,10 @@ | ||
namespace Intent.Console | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] path) | ||
{ | ||
new Runner().Run(path, new ConsoleLogger()); | ||
} | ||
} | ||
} |
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,8 @@ | ||
{ | ||
"profiles": { | ||
"Intent.Console": { | ||
"commandName": "Project", | ||
"commandLineArgs": "--path \"C:\\Projects\\temp\\Intent\\Some.Tests\\bin\\Debug\\netstandard2.0\\Some.Tests.dll\"" | ||
} | ||
} | ||
} |
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,9 @@ | ||
using System; | ||
|
||
namespace Intent | ||
{ | ||
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Constructor | AttributeTargets.Method)] | ||
public class ExcludeAttribute : Attribute | ||
{ | ||
} | ||
} |
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,13 @@ | ||
using System; | ||
using System.Reflection; | ||
|
||
namespace Intent | ||
{ | ||
public interface IRunLogger | ||
{ | ||
void WriteTestPassed(MethodInfo m); | ||
void WriteTestInconclusive(MethodInfo m); | ||
void WriteTestFailure(MethodInfo m, Exception ex); | ||
void WriteFrameworkError(Exception ex); | ||
} | ||
} |
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,7 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</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,11 @@ | ||
using System; | ||
|
||
namespace Intent | ||
{ | ||
public class TestFailedException : Exception | ||
{ | ||
public TestFailedException(string message) : base(message) | ||
{ | ||
} | ||
} | ||
} |
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,11 @@ | ||
using System; | ||
|
||
namespace Intent | ||
{ | ||
public class TestPassedException : Exception | ||
{ | ||
public TestPassedException() | ||
{ | ||
} | ||
} | ||
} |
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,14 @@ | ||
using System; | ||
|
||
namespace Intent | ||
{ | ||
public enum TestResult | ||
{ | ||
None = 0, | ||
Passed, | ||
Inconclusive, | ||
Skipped, | ||
Failed, | ||
Error, | ||
} | ||
} |
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,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="16.5.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\..\..\..\Projects\temp\Intent\Intent\Intent.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,61 @@ | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; | ||
using VsTestResult = Microsoft.VisualStudio.TestPlatform.ObjectModel.TestResult; | ||
using System; | ||
using System.Reflection; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
|
||
namespace Intent.TestAdapter | ||
{ | ||
internal class VsLoggerAdapter : IRunLogger | ||
{ | ||
private IFrameworkHandle _handle; | ||
private IMessageLogger _logger; | ||
private Uri _uri; | ||
|
||
public VsLoggerAdapter(IFrameworkHandle handle, Uri uri) | ||
{ | ||
_handle = handle; | ||
_logger = handle; | ||
_uri = uri; | ||
} | ||
|
||
public void WriteFrameworkError(Exception ex) | ||
{ | ||
_logger.SendMessage(TestMessageLevel.Error, ex.ToString()); | ||
} | ||
|
||
public void WriteTestFailure(MethodInfo m, Exception ex) | ||
{ | ||
|
||
var tc = new TestCase(m.Name, _uri, m.DeclaringType.Assembly.Location); | ||
_handle.RecordResult(new VsTestResult(tc) | ||
{ | ||
DisplayName = m.Name.Replace("_", " "), | ||
Outcome = TestOutcome.Failed, | ||
ErrorMessage = ex.Message, | ||
ErrorStackTrace = ex.StackTrace | ||
}); | ||
} | ||
|
||
public void WriteTestInconclusive(MethodInfo m) | ||
{ | ||
var tc = new TestCase(m.Name, _uri, m.DeclaringType.Assembly.Location); | ||
_handle.RecordResult(new VsTestResult(tc) | ||
{ | ||
DisplayName = m.Name.Replace("_", " "), | ||
Outcome = TestOutcome.Skipped | ||
}); | ||
} | ||
|
||
public void WriteTestPassed(MethodInfo m) | ||
{ | ||
var tc = new TestCase(m.Name, _uri, m.DeclaringType.Assembly.Location); | ||
_handle.RecordResult(new VsTestResult(tc) | ||
{ | ||
DisplayName = m.Name.Replace("_", " "), | ||
Outcome = TestOutcome.Passed | ||
}); | ||
} | ||
} | ||
} |
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,56 @@ | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
|
||
namespace Intent.TestAdapter | ||
{ | ||
[DefaultExecutorUri(VsTestExecutor.Id)] | ||
//[FileExtension(".exe")] | ||
//[FileExtension(".dll")] | ||
public class VsTestDiscoverer : ITestDiscoverer | ||
{ | ||
public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink) | ||
{ | ||
logger.SendMessage(TestMessageLevel.Informational, "Intent 1.0"); | ||
foreach (var p in sources) | ||
{ | ||
try | ||
{ | ||
var asm = Assembly.LoadFrom(p); | ||
if (asm.IsExcluded()) | ||
continue; | ||
|
||
var ts = asm.GetTypes().SkipExcluded(); | ||
foreach (var t in ts) | ||
{ | ||
var ms = t.GetMethods().SkipExcluded(); | ||
foreach (var m in ms) | ||
{ | ||
try | ||
{ | ||
var discoveredTest = new TestCase(m.Name, VsTestExecutor.Uri, p) | ||
{ | ||
DisplayName = m.Name.Replace("_", " ") | ||
}; | ||
|
||
logger.SendMessage(TestMessageLevel.Informational, $"Found test '{discoveredTest.DisplayName}'."); | ||
discoverySink.SendTestCase(discoveredTest); | ||
} | ||
catch (Exception ex) | ||
{ | ||
logger.SendMessage(TestMessageLevel.Error, ex.ToString()); | ||
} | ||
} | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
logger.SendMessage(TestMessageLevel.Error, ex.ToString()); | ||
} | ||
} | ||
} | ||
} | ||
} |
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,38 @@ | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Intent.TestAdapter | ||
{ | ||
[ExtensionUri(Id)] | ||
public class VsTestExecutor : ITestExecutor | ||
{ | ||
public const string Id = "executor://intent.testadapter"; | ||
public static readonly Uri Uri = new Uri(Id); | ||
|
||
public void Cancel() | ||
{ | ||
// noop | ||
} | ||
|
||
public void RunTests(IEnumerable<TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle) | ||
{ | ||
var sources = tests.Select(t => t.Source).Distinct().ToList(); | ||
RunTests(sources, runContext, frameworkHandle); | ||
} | ||
|
||
public void RunTests(IEnumerable<string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle) | ||
{ | ||
IMessageLogger logger = frameworkHandle; | ||
logger.SendMessage(TestMessageLevel.Informational, "Intent 1.0"); | ||
|
||
if (runContext.KeepAlive) | ||
frameworkHandle.EnableShutdownAfterTestRun = true; | ||
|
||
new Runner().Run(sources, new VsLoggerAdapter(frameworkHandle, Uri)); | ||
} | ||
} | ||
} |
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,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" /> | ||
<PackageReference Include="coverlet.collector" Version="1.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Intent.Console\Intent.Console.csproj" /> | ||
<ProjectReference Include="..\Some.Tests\Some.Tests.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,13 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Intent.Tests | ||
{ | ||
[TestClass] | ||
public class UnitTest1 | ||
{ | ||
[TestMethod] | ||
public void TestMethod1() | ||
{ | ||
} | ||
} | ||
} |
Oops, something went wrong.