This repository has been archived by the owner on Mar 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dotnet Core Testrunner für die Konsole.
- Loading branch information
Unknown
authored and
Unknown
committed
Jan 25, 2018
1 parent
e51a9df
commit 8a0f06e
Showing
26 changed files
with
304 additions
and
3,620 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -312,3 +312,4 @@ __pycache__/ | |
0penCover/ | ||
|
||
binaries/ | ||
Releases/ |
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,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
<AssemblyName>consolerunner</AssemblyName> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<LangVersion>7.1</LangVersion> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<LangVersion>7.1</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CommandLineParser" Version="2.2.1" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" /> | ||
<PackageReference Include="Ninject" Version="3.3.4" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\TestRunner\TestRunner.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Binary file not shown.
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,57 @@ | ||
[ | ||
{ | ||
"Input": ["2x^10+2x^3"], | ||
"ExpectedOutput": ["20x^9+6x^2"], | ||
"TrimOutput": true | ||
}, | ||
{ | ||
"Input": ["2x^10 +2x^3"], | ||
"ExpectedOutput": ["20x^9+6x^2"], | ||
"TrimOutput": true | ||
}, | ||
{ | ||
"Input": ["2x^10 + 2x^3"], | ||
"ExpectedOutput": ["20x^9+6x^2"], | ||
"TrimOutput": true | ||
}, | ||
{ | ||
"Input": ["2x^10+ x^3"], | ||
"ExpectedOutput": ["20x^9+6x^2"], | ||
"TrimOutput": true | ||
}, | ||
{ | ||
"Input": ["2x^10 +2x ^3"], | ||
"ExpectedOutput": ["20x^9+6x^2"], | ||
"TrimOutput": true | ||
}, | ||
{ | ||
"Input": ["2x^10+2x^3+10"], | ||
"ExpectedOutput": ["20x^9+6x^2"], | ||
"TrimOutput": true | ||
}, | ||
{ | ||
"Input": ["2x^10+2x^3+sin(x)"], | ||
"ExpectedOutput": ["20x^9+6x^2-cos(x)"], | ||
"TrimOutput": true | ||
}, | ||
{ | ||
"Input": ["2x^10(2x^3+10)"], | ||
"ExpectedOutput": ["20x^9*6x^2*(2x^3+10)"], | ||
"TrimOutput": true | ||
}, | ||
{ | ||
"Input": ["2x^10(2x^3+10)"], | ||
"ExpectedOutput": ["20x^9*6x^2(2x^3+10)"], | ||
"TrimOutput": true | ||
}, | ||
{ | ||
"Input": ["2x^10(2x^3+10)"], | ||
"ExpectedOutput": ["20x^9*6x^2/(2x^3+10)"], | ||
"TrimOutput": true | ||
}, | ||
{ | ||
"Input": ["2x^-10"], | ||
"ExpectedOutput": ["-20x^-11"], | ||
"TrimOutput": true | ||
} | ||
] |
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,5 @@ | ||
{ | ||
"Command": "./DummyTools/DummyOutput.exe", | ||
"Argument": "-q -f test.txt", | ||
"Test": "./DummyTools/dummy.jsonTest" | ||
} |
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,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Linq; | ||
using TestRunner.Models; | ||
|
||
namespace ConsoleFrontend.Helpers | ||
{ | ||
public static class ExtensionMethods | ||
{ | ||
public static string ToConsoleOutput(this TestResult result) | ||
{ | ||
var builder = new StringBuilder(); | ||
builder.Append($"Duration: {result.Duration}ms"); | ||
builder.Append(Environment.NewLine); | ||
builder.Append($"Started?: {result.RunSuccessful}"); | ||
builder.Append(Environment.NewLine); | ||
builder.Append($"Success: {result.OutputMatches}"); | ||
builder.Append(Environment.NewLine); | ||
|
||
if (result.Exception != null) | ||
{ | ||
builder.Append($"Exception:{Environment.NewLine}{result.Exception}"); | ||
builder.Append(Environment.NewLine); | ||
} | ||
|
||
if (result.OutputMatches == false) | ||
{ | ||
builder.AppendLine($"Reason: {result.FailReason}"); | ||
builder.AppendLine($"Expected:"); | ||
builder.AppendLine(string.Join(Environment.NewLine, result.ExpectedOutput)); | ||
builder.AppendLine("Received:"); | ||
builder.Append(string.Join(Environment.NewLine, result.Output)); | ||
} | ||
|
||
return builder.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,25 @@ | ||
using CommandLine; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace ConsoleFrontend.Helpers | ||
{ | ||
internal class ConfigOptions | ||
{ | ||
[Option('c', "config", Required = true, HelpText = "Configuration file containing command, argument and test reference.")] | ||
public string ConfigFile { get; set; } | ||
} | ||
|
||
internal class StartupOptions | ||
{ | ||
[Option('a', "argument", Required = false, HelpText = "Arguments to pass to the command.")] | ||
public string Argument { get; set; } | ||
[Option('c', "command", Required = true, HelpText = "Command to run. Should be double quoted.")] | ||
public string Command { get; set; } | ||
[Option('t', "test", Required = true, HelpText = "Name of the jsonTest file.")] | ||
public string Test { get; set; } | ||
|
||
public bool IsValid => string.IsNullOrWhiteSpace(Command) == false && string.IsNullOrWhiteSpace(Test) == false; | ||
} | ||
} |
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,90 @@ | ||
using CommandLine; | ||
using CommandLine.Text; | ||
using ConsoleFrontend.Helpers; | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using TestRunner.Models; | ||
|
||
namespace ConsoleFrontend | ||
{ | ||
class Program | ||
{ | ||
private static CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource(); | ||
private static CancellationToken _cancellationToken = _cancellationTokenSource.Token; | ||
private const int DefaultExecutionTimeout = 5000; | ||
|
||
static async Task Main(string[] args) | ||
{ | ||
var parser = new Parser(config => config.HelpWriter = null); | ||
var results = parser.ParseArguments<StartupOptions>(args) | ||
.WithParsed(async options => await StartFromStartupOptions(options)) | ||
.WithNotParsed(errors => | ||
Parser.Default.ParseArguments<ConfigOptions>(args) | ||
.WithParsed(async options => await StartFromConfigOptions(options)) | ||
.WithNotParsed(errpors => OnStartupParameterError()) | ||
); | ||
|
||
while (_cancellationToken.IsCancellationRequested == false) | ||
await Task.Delay(250); | ||
} | ||
|
||
private static async Task StartFromStartupOptions(StartupOptions options) | ||
{ | ||
var tests = LoadTestCasesFromFile(options.Test); | ||
await Run(options.Command, options.Argument, tests); | ||
} | ||
|
||
private static async Task StartFromConfigOptions(ConfigOptions options) | ||
{ | ||
var content = File.ReadAllText(options.ConfigFile); | ||
var config = JsonConvert.DeserializeObject<StartupOptions>(content); | ||
var tests = LoadTestCasesFromFile(config.Test); | ||
await Run(config.Command, config.Argument, tests); | ||
} | ||
|
||
private static async Task Run(string command, string argument, IEnumerable<TestCase> tests) | ||
{ | ||
var runner = new ProcessTestRunner(); | ||
|
||
int counter = 0; | ||
foreach(var test in tests) | ||
{ | ||
Console.WriteLine($"Starting test {counter++} of {tests.Count()}"); | ||
var result = await runner.Run(command, argument, test.Input, test.ExpectedOutput, DefaultExecutionTimeout); | ||
Console.WriteLine(result.ToConsoleOutput()); | ||
} | ||
|
||
_cancellationTokenSource.Cancel(); | ||
} | ||
|
||
private static IEnumerable<TestCase> LoadTestCasesFromFile(string filename) | ||
{ | ||
// Kein Error Handling, die Exceptions werden automatisch geworfen, wenn die Datei nicht existiert. | ||
var content = File.ReadAllText(filename); | ||
return JsonConvert.DeserializeObject<List<TestCase>>(content); | ||
} | ||
|
||
private static void OnStartupParameterError() | ||
{ | ||
Console.WriteLine("You have not supplied correct startup parameters. You can either use a configuration file written in the following format:"); | ||
Console.WriteLine(); | ||
Console.WriteLine("{"); | ||
Console.WriteLine(" \"command\": \"$Command_To_Run\""); | ||
Console.WriteLine(" \"argument\": \"$Argument_To_Add_To_Command\" (optional)"); | ||
Console.WriteLine(" \"test\": \"$Filename_of_jsonTest-File\""); | ||
Console.WriteLine("}"); | ||
Console.WriteLine(); | ||
Console.WriteLine("And supply the path to the file with '-c'"); | ||
Console.WriteLine(); | ||
Console.WriteLine($"Alternatively, use {Environment.NewLine}\t-c to supply a command (double quoted){Environment.NewLine}\t-a to specify arguments added to the command (double quoted){Environment.NewLine}\t-t path to the jsonTest-file"); | ||
|
||
_cancellationTokenSource.Cancel(); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.