protected TestResult GetUnitTestsResultFromExecutionResult( ref int originalTestsPassed, IChecker checker, ProcessExecutionResult processExecutionResult, TestContext test, bool isFirstRun) { var endMessage = string.Empty; if (processExecutionResult.Type == ProcessExecutionResultType.Success) { var(message, testsPassed) = UnitTestStrategiesHelper.GetTestResult( processExecutionResult.ReceivedOutput, TestsRegex, originalTestsPassed, isFirstRun, this.ExtractTestsCountFromMatchCollection); originalTestsPassed = testsPassed; endMessage = message; } return(this.CheckAndGetTestResult(test, processExecutionResult, checker, endMessage)); }
protected override IExecutionResult <TestResult> RunUnitTests( string consoleRunnerPath, IExecutionContext <TestsInputModel> executionContext, IExecutor executor, IChecker checker, IExecutionResult <TestResult> result, string csProjFilePath, string additionalExecutionArguments) { var projectDirectory = Path.GetDirectoryName(csProjFilePath); var testedCodePath = $"{projectDirectory}\\{UnitTestStrategiesHelper.TestedCodeFileNameWithExtension}"; var originalTestsPassed = -1; var count = 0; var compilerPath = this.GetCompilerPathFunc(executionContext.CompilerType); var tests = executionContext.Input.Tests.OrderBy(x => x.IsTrialTest).ThenBy(x => x.OrderBy); foreach (var test in tests) { File.WriteAllText(this.SetupFixturePath, SetupFixtureTemplate); File.WriteAllText(testedCodePath, test.Input); // Compiling var compilerResult = this.Compile( executionContext.CompilerType, compilerPath, executionContext.AdditionalCompilerArguments, csProjFilePath); result.IsCompiledSuccessfully = compilerResult.IsCompiledSuccessfully; result.CompilerComment = compilerResult.CompilerComment; if (!compilerResult.IsCompiledSuccessfully) { return(result); } // Delete tests before execution so the user can't acces them FileHelpers.DeleteFiles(testedCodePath, this.SetupFixturePath); var arguments = new List <string> { compilerResult.OutputFile }; arguments.AddRange(additionalExecutionArguments.Split(' ')); var processExecutionResult = executor.Execute( consoleRunnerPath, string.Empty, executionContext.TimeLimit, executionContext.MemoryLimit, arguments, null, false, true); var testResultsRegex = new Regex(TestResultsRegex); var processExecutionTestResult = UnitTestStrategiesHelper.GetTestResult( processExecutionResult.ReceivedOutput, testResultsRegex, originalTestsPassed, count == 0, this.ExtractTotalAndPassedTestsCount); var message = processExecutionTestResult.message; originalTestsPassed = processExecutionTestResult.originalTestsPassed; var testResult = this.CheckAndGetTestResult(test, processExecutionResult, checker, message); result.Results.Add(testResult); count++; } return(result); }
protected override IExecutionResult <TestResult> RunUnitTests( string consoleRunnerPath, IExecutionContext <TestsInputModel> executionContext, IExecutor executor, IChecker checker, IExecutionResult <TestResult> result, string csProjFilePath, string additionalExecutionArguments) { var additionalExecutionArgumentsArray = additionalExecutionArguments .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var compilerPath = this.GetCompilerPathFunc(executionContext.CompilerType); var testedCodePath = FileHelpers.BuildPath( this.NUnitLiteConsoleAppDirectory, UnitTestStrategiesHelper.TestedCodeFileNameWithExtension); var originalTestsPassed = -1; var tests = executionContext.Input.Tests.OrderBy(x => x.IsTrialTest).ThenBy(x => x.OrderBy).ToList(); for (var i = 0; i < tests.Count; i++) { var test = tests[i]; this.SaveSetupFixture(this.NUnitLiteConsoleAppDirectory); File.WriteAllText(testedCodePath, test.Input); // Compiling var compilerResult = this.Compile( executionContext.CompilerType, compilerPath, executionContext.AdditionalCompilerArguments, consoleRunnerPath); result.IsCompiledSuccessfully = compilerResult.IsCompiledSuccessfully; result.CompilerComment = compilerResult.CompilerComment; if (!compilerResult.IsCompiledSuccessfully) { return(result); } // Delete tests before execution so the user can't acces them FileHelpers.DeleteFiles(testedCodePath, this.SetupFixturePath); var arguments = new List <string> { compilerResult.OutputFile }; arguments.AddRange(additionalExecutionArgumentsArray); var processExecutionResult = executor.Execute( compilerPath, string.Empty, executionContext.TimeLimit, executionContext.MemoryLimit, arguments, workingDirectory: null, useProcessTime: false, useSystemEncoding: true); if (!string.IsNullOrWhiteSpace(processExecutionResult.ErrorOutput)) { throw new InvalidProcessExecutionOutputException(processExecutionResult.ErrorOutput); } var testResultsRegex = new Regex(TestResultsRegex); var processExecutionTestResult = UnitTestStrategiesHelper.GetTestResult( processExecutionResult.ReceivedOutput, testResultsRegex, originalTestsPassed, i == 0, this.ExtractTotalAndPassedTestsCount); var message = processExecutionTestResult.message; originalTestsPassed = processExecutionTestResult.originalTestsPassed; var testResult = this.CheckAndGetTestResult(test, processExecutionResult, checker, message); result.Results.Add(testResult); if (i < tests.Count - 1) { // Recreate NUnitLite Console App .csproj file, deleted after compilation, to compile again this.CreateNUnitLiteConsoleAppCsProjFile(this.nUnitLiteConsoleAppCsProjTemplate); } } return(result); }