public DiffResult ScanDiff() { var diffResult = new DiffResult() { ChangedFiles = new Collection <string>(), TestsChanged = false }; // A git repository has been detected, calculate the diff to filter var commit = _gitInfoProvider.DetermineCommit(); if (commit == null) { throw new Stryker.Core.Exceptions.StrykerInputException("Could not determine a commit to check for diff. Please check you have provided the correct value for --git-source"); } foreach (var patchChanges in _gitInfoProvider.Repository.Diff.Compare <Patch>(commit.Tree, DiffTargets.Index | DiffTargets.WorkingDirectory)) { string diffPath = FilePathUtils.NormalizePathSeparators(Path.Combine(_gitInfoProvider.RepositoryPath, patchChanges.Path)); diffResult.ChangedFiles.Add(diffPath); if (diffPath.StartsWith(_options.BasePath) && diffPath.EndsWith(".cs")) { diffResult.TestsChanged = true; } } return(diffResult); }
public void OnAllMutantsTested(IReadOnlyProjectComponent reportComponent) { var mutationReport = JsonReport.Build(_options, reportComponent); var filename = _options.ReportFileName + ".html"; var reportPath = Path.Combine(_options.OutputPath, "reports", filename); reportPath = FilePathUtils.NormalizePathSeparators(reportPath); WriteHtmlReport(reportPath, mutationReport.ToJsonHtmlSafe()); // to make path clickable it should always start with: file:/// var reportUri = reportPath.Replace("\\", "/"); reportUri = reportUri.StartsWith("/") ? reportUri : "/" + reportUri; reportUri = "file://" + reportUri; if (_options.ReportTypeToOpen == Options.Inputs.ReportType.Html) { _processWrapper.Open(reportUri); } else { _consoleWriter.Write(Output.Cyan("Hint: by passing \"--open-report or -o\" the report will open automatically once Stryker is done.")); } _consoleWriter.WriteLine(Output.Green($"\nYour html report has been generated at:\n" + $"{reportUri}\n" + $"You can open it in your browser of choice.")); }
private void InitializeVsTestConsole() { var testBinariesPaths = _projectInfo.TestProjectAnalyzerResults.Select(testProject => _projectInfo.GetTestBinariesPath(testProject)).ToList(); var testBinariesLocations = new List <string>(); _sources = new List <string>(); foreach (var path in testBinariesPaths) { if (!_fileSystem.File.Exists(path)) { throw new GeneralStrykerException($"The test project binaries could not be found at {path}, exiting..."); } testBinariesLocations.Add(Path.GetDirectoryName(path)); _sources.Add(FilePathUtils.NormalizePathSeparators(path)); } testBinariesLocations.Add(_vsTestHelper.GetDefaultVsTestExtensionsPath(_vsTestHelper.GetCurrentPlatformVsTestToolPath())); try { // Set roll forward on no candidate fx so vstest console can start on incompatible dotnet core runtimes Environment.SetEnvironmentVariable("DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX", "2"); _vsTestConsole.StartSession(); _vsTestConsole.InitializeExtensions(testBinariesLocations); } catch (Exception e) { throw new GeneralStrykerException("Stryker failed to connect to vstest.console", e); } _discoveredTests = DiscoverTests(); }
private string DetermineProjectUnderTestWithNameFilter(string projectUnderTestNameFilter, IEnumerable <string> projectReferences) { var stringBuilder = new StringBuilder(); var referenceChoice = BuildReferenceChoice(projectReferences); var projectReferencesMatchingNameFilter = projectReferences.Where(x => x.ToLower().Contains(projectUnderTestNameFilter.ToLower())); if (!projectReferencesMatchingNameFilter.Any()) { stringBuilder.Append("No project reference matched your --project-file="); stringBuilder.AppendLine(projectUnderTestNameFilter); stringBuilder.Append(referenceChoice); AppendExampleIfPossible(stringBuilder, projectReferences, projectUnderTestNameFilter); throw new StrykerInputException(ErrorMessage, stringBuilder.ToString()); } else if (projectReferencesMatchingNameFilter.Count() > 1) { stringBuilder.Append("More than one project reference matched your --project-file="); stringBuilder.Append(projectUnderTestNameFilter); stringBuilder.AppendLine(" argument to specify the project to mutate, please specify the name more detailed."); stringBuilder.Append(referenceChoice); AppendExampleIfPossible(stringBuilder, projectReferences, projectUnderTestNameFilter); throw new StrykerInputException(ErrorMessage, stringBuilder.ToString()); } return(FilePathUtils.NormalizePathSeparators(projectReferencesMatchingNameFilter.Single())); }
private IEnumerable <string> ValidateTestProjects(IEnumerable <string> paths) { foreach (var path in paths ?? Enumerable.Empty <string>()) { yield return(FilePathUtils.NormalizePathSeparators(Path.GetFullPath(path))); } }
public InputFileResolverTests() { _currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); _filesystemRoot = Path.GetPathRoot(_currentDirectory); _basePath = Path.Combine(_filesystemRoot, "TestProject"); sourceFile = File.ReadAllText(_currentDirectory + "/TestResources/ExampleSourceFile.cs"); testProjectPath = FilePathUtils.NormalizePathSeparators(Path.Combine(_filesystemRoot, "TestProject", "TestProject.csproj")); alternateTestProjectPath = FilePathUtils.NormalizePathSeparators(Path.Combine(_filesystemRoot, "TestProject", "AlternateTestProject.csproj")); projectUnderTestPath = FilePathUtils.NormalizePathSeparators(Path.Combine(_filesystemRoot, "ExampleProject", "ExampleProject.csproj")); defaultTestProjectFileContents = @"<Project Sdk=""Microsoft.NET.Sdk""> <PropertyGroup> <TargetFramework>netcoreapp2.0</TargetFramework> <IsPackable>false</IsPackable> </PropertyGroup> <ItemGroup> <PackageReference Include=""Microsoft.NET.Test.Sdk"" Version = ""15.5.0"" /> <PackageReference Include=""xunit"" Version=""2.3.1"" /> <PackageReference Include=""xunit.runner.visualstudio"" Version=""2.3.1"" /> <DotNetCliToolReference Include=""dotnet-xunit"" Version=""2.3.1"" /> </ItemGroup> <ItemGroup> <ProjectReference Include=""..\ExampleProject\ExampleProject.csproj"" /> </ItemGroup> </Project>"; }
private void InitializeVsTestConsole() { var testBinariesPath = _projectInfo.GetTestBinariesPath(); if (!_fileSystem.File.Exists(testBinariesPath)) { throw new ApplicationException($"The test project binaries could not be found at {testBinariesPath}, exiting..."); } var testBinariesLocation = Path.GetDirectoryName(testBinariesPath); _sources = new List <string>() { FilePathUtils.NormalizePathSeparators(testBinariesPath) }; try { _vsTestConsole.StartSession(); _vsTestConsole.InitializeExtensions(new List <string> { testBinariesLocation, _vsTestHelper.GetDefaultVsTestExtensionsPath(_vsTestHelper.GetCurrentPlatformVsTestToolPath()) }); } catch (Exception e) { throw new ApplicationException("Stryker failed to connect to vstest.console", e); } _discoveredTests = DiscoverTests(); }
public void StrykerCLI_WithConfigFile_ShouldStartStrykerWithConfigFileOptions(string argName) { var filePattern = new FilePattern(Glob.Parse(FilePathUtils.NormalizePathSeparators("**/Test.cs")), true, new[] { TextSpan.FromBounds(1, 100), TextSpan.FromBounds(200, 300) }); StrykerOptions actualOptions = null; var runResults = new StrykerRunResult(new StrykerOptions(), 0.3); var mock = new Mock <IStrykerRunner>(MockBehavior.Strict); mock.Setup(x => x.RunMutationTest(It.IsAny <StrykerOptions>(), It.IsAny <IEnumerable <LogMessage> >())) .Callback <StrykerOptions, IEnumerable <LogMessage> >((c, m) => actualOptions = c) .Returns(runResults) .Verifiable(); var target = new StrykerCLI(mock.Object); target.Run(new string[] { argName, "filled-stryker-config.json" }); mock.VerifyAll(); actualOptions.DevMode.ShouldBe(true); actualOptions.AdditionalTimeoutMS.ShouldBe(9999); actualOptions.LogOptions.LogLevel.ShouldBe(LogEventLevel.Verbose); actualOptions.ProjectUnderTestNameFilter.ShouldBe("ExampleProject.csproj"); actualOptions.Reporters.ShouldHaveSingleItem(); actualOptions.Reporters.ShouldContain(Reporter.ConsoleReport); actualOptions.ConcurrentTestRunners.ShouldBe(1); actualOptions.Thresholds.Break.ShouldBe(20); actualOptions.Thresholds.Low.ShouldBe(30); actualOptions.Thresholds.High.ShouldBe(40); actualOptions.FilePatterns.Count().ShouldBe(2); actualOptions.FilePatterns.ShouldContain(filePattern); actualOptions.Optimizations.ShouldBe(OptimizationFlags.CoverageBasedTest | OptimizationFlags.AbortTestOnKill); }
private string ValidateOutputPath(string basePath) { if (string.IsNullOrWhiteSpace(basePath)) { return(""); } var outputPath = Path.Combine(basePath, "StrykerOutput", DateTime.Now.ToString("yyyy-MM-dd.HH-mm-ss")); _fileSystem.Directory.CreateDirectory(FilePathUtils.NormalizePathSeparators(outputPath)); // Create output dir with gitignore var gitignorePath = FilePathUtils.NormalizePathSeparators(Path.Combine(basePath, "StrykerOutput", ".gitignore")); if (!_fileSystem.File.Exists(gitignorePath)) { try { using var _ = _fileSystem.File.Create(gitignorePath, 1, FileOptions.Asynchronous); using var file = _fileSystem.File.CreateText(gitignorePath); file.WriteLine("*"); } catch (IOException) { _logger.LogDebug("Couldn't create gitignore file at {0}, probably because it already exists", gitignorePath); } } return(outputPath); }
private string CreateOutputPath(string basePath, IFileSystem fileSystem) { var strykerDir = "StrykerOutput"; var outputPath = Path.Combine(basePath, strykerDir, DateTime.Now.ToString("yyyy-MM-dd.HH-mm-ss")); // outputpath should always be created fileSystem.Directory.CreateDirectory(FilePathUtils.NormalizePathSeparators(outputPath)); // add gitignore if it didn't exist yet var gitignorePath = FilePathUtils.NormalizePathSeparators(Path.Combine(basePath, strykerDir, ".gitignore")); if (!fileSystem.File.Exists(gitignorePath)) { try { fileSystem.File.WriteAllText(gitignorePath, "*"); } catch (IOException e) { Console.WriteLine($"Could't create gitignore file because of error {e.Message}. \n" + "If you use any diff compare features this may mean that stryker logs show up as changes."); } } return(outputPath); }
private void InitializeVsTestConsole() { var testBinariesPath = _projectInfo.GetTestBinariesPath(); if (!_fileSystem.File.Exists(testBinariesPath)) { throw new ApplicationException($"The test project binaries could not be found at {testBinariesPath}, exiting..."); } var testBinariesLocation = Path.GetDirectoryName(testBinariesPath); _sources = new List <string>() { FilePathUtils.NormalizePathSeparators(testBinariesPath) }; try { // Set roll forward on no candidate fx so vstest console can start on incompatible dotnet core runtimes Environment.SetEnvironmentVariable("DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX", "2"); _vsTestConsole.StartSession(); _vsTestConsole.InitializeExtensions(new List <string> { testBinariesLocation, _vsTestHelper.GetDefaultVsTestExtensionsPath(_vsTestHelper.GetCurrentPlatformVsTestToolPath()) }); } catch (Exception e) { throw new ApplicationException("Stryker failed to connect to vstest.console", e); } _discoveredTests = DiscoverTests(); }
/// <summary> /// Parses a given file pattern string. /// Format: (!)<glob>({<spanStart>..<spanEnd>})* /// </summary> /// <param name="pattern">The pattern to parse.</param> /// <returns>The <see cref="FilePattern"/></returns> public static FilePattern Parse(string pattern) { var exclude = false; IReadOnlyCollection <TextSpan> textSpans; if (pattern.StartsWith('!')) { exclude = true; pattern = pattern.Substring(1, pattern.Length - 1); } var textSpanGroupMatch = _textSpanGroupRegex.Match(pattern); if (!textSpanGroupMatch.Success) { // If there are no spans specified, we add one that will cover the whole file. textSpans = new[] { _textSpanMaxValue }; } else { // If we have one ore more spans we parse them. var textSpansMatches = _textSpanRegex.Matches(textSpanGroupMatch.Value); textSpans = textSpansMatches .Select(x => TextSpan.FromBounds(int.Parse(x.Groups[1].Value), int.Parse(x.Groups[2].Value))) .Reduce() .ToList(); pattern = pattern.Substring(0, pattern.Length - textSpanGroupMatch.Length); } var glob = Glob.Parse(FilePathUtils.NormalizePathSeparators(pattern)); return(new FilePattern(glob, exclude, textSpans)); }
// initialize the test context and mock objects public VsTestRunnersTest() { var currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var filesystemRoot = Path.GetPathRoot(currentDirectory); var sourceFile = File.ReadAllText(currentDirectory + "/TestResources/ExampleSourceFile.cs"); var testProjectPath = FilePathUtils.NormalizePathSeparators(Path.Combine(filesystemRoot !, "TestProject", "TestProject.csproj")); var projectUnderTestPath = FilePathUtils.NormalizePathSeparators(Path.Combine(filesystemRoot, "ExampleProject", "ExampleProject.csproj")); const string defaultTestProjectFileContents = @"<Project Sdk=""Microsoft.NET.Sdk""> <PropertyGroup> <TargetFramework>netcoreapp2.0</TargetFramework> <IsPackable>false</IsPackable> </PropertyGroup> <ItemGroup> <PackageReference Include=""Microsoft.NET.Test.Sdk"" Version = ""15.5.0"" /> <PackageReference Include=""xunit"" Version=""2.3.1"" /> <PackageReference Include=""xunit.runner.visualstudio"" Version=""2.3.1"" /> <DotNetCliToolReference Include=""dotnet-xunit"" Version=""2.3.1"" /> </ItemGroup> <ItemGroup> <ProjectReference Include=""..\ExampleProject\ExampleProject.csproj"" /> </ItemGroup> </Project>"; _testAssemblyPath = FilePathUtils.NormalizePathSeparators(Path.Combine(filesystemRoot, "_firstTest", "bin", "Debug", "TestApp.dll")); _executorUri = new Uri("exec://nunit"); var firstTest = BuildCase("T0"); var secondTest = BuildCase("T1"); var content = new CsharpFolderComposite(); _fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { projectUnderTestPath, new MockFileData(defaultTestProjectFileContents) },
private string ValidateOutputPath(string basePath) { if (string.IsNullOrWhiteSpace(basePath)) { return(""); } var outputPath = Path.Combine(basePath, "StrykerOutput", DateTime.Now.ToString("yyyy-MM-dd.HH-mm-ss")); _fileSystem.Directory.CreateDirectory(FilePathUtils.NormalizePathSeparators(outputPath)); // Create output dir with gitignore var gitignorePath = FilePathUtils.NormalizePathSeparators(Path.Combine(basePath, "StrykerOutput", ".gitignore")); if (!_fileSystem.File.Exists(gitignorePath)) { try { _fileSystem.File.WriteAllText(gitignorePath, "*"); } catch (IOException e) { _logger.LogWarning("Could't create gitignore file because of error {error}. \n" + "If you use any diff compare features this may mean that stryker logs show up as changes.", e.Message); } } return(outputPath); }
// initialize the test context and mock objects public VsTestRunnersShould() { var currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var filesystemRoot = Path.GetPathRoot(currentDirectory); var sourceFile = File.ReadAllText(currentDirectory + "/TestResources/ExampleSourceFile.cs"); var testProjectPath = FilePathUtils.NormalizePathSeparators(Path.Combine(filesystemRoot, "TestProject", "TestProject.csproj")); var projectUnderTestPath = FilePathUtils.NormalizePathSeparators(Path.Combine(filesystemRoot, "ExampleProject", "ExampleProject.csproj")); const string defaultTestProjectFileContents = @"<Project Sdk=""Microsoft.NET.Sdk""> <PropertyGroup> <TargetFramework>netcoreapp2.0</TargetFramework> <IsPackable>false</IsPackable> </PropertyGroup> <ItemGroup> <PackageReference Include=""Microsoft.NET.Test.Sdk"" Version = ""15.5.0"" /> <PackageReference Include=""xunit"" Version=""2.3.1"" /> <PackageReference Include=""xunit.runner.visualstudio"" Version=""2.3.1"" /> <DotNetCliToolReference Include=""dotnet-xunit"" Version=""2.3.1"" /> </ItemGroup> <ItemGroup> <ProjectReference Include=""..\ExampleProject\ExampleProject.csproj"" /> </ItemGroup> </Project>"; _testAssemblyPath = Path.Combine(filesystemRoot, "_firstTest", "bin", "Debug", "TestApp.dll"); var firstTest = new TestCase("myFirsTest", new Uri("exec://nunit"), _testAssemblyPath); var secondTest = new TestCase("myOtherTest", new Uri("exec://nunit"), _testAssemblyPath); _targetProject = new ProjectInfo() { TestProjectAnalyzerResults = new List <ProjectAnalyzerResult> { new ProjectAnalyzerResult(null, null) { AssemblyPath = _testAssemblyPath, TargetFrameworkVersionString = "toto" } }, ProjectUnderTestAnalyzerResult = new ProjectAnalyzerResult(null, null) { AssemblyPath = Path.Combine(filesystemRoot, "app", "bin", "Debug", "AppToTest.dll"), TargetFrameworkVersionString = "toto" } }; _fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { projectUnderTestPath, new MockFileData(defaultTestProjectFileContents) }, { Path.Combine(filesystemRoot, "ExampleProject", "Recursive.cs"), new MockFileData(sourceFile) }, { Path.Combine(filesystemRoot, "ExampleProject", "OneFolderDeeper", "Recursive.cs"), new MockFileData(sourceFile) }, { testProjectPath, new MockFileData(defaultTestProjectFileContents) }, { _testAssemblyPath, new MockFileData("Bytecode") }, { Path.Combine(filesystemRoot, "app", "bin", "Debug", "AppToTest.dll"), new MockFileData("Bytecode") }, }); _mutant = new Mutant { Id = 1 }; _testCases = new[] { firstTest, secondTest }; }
public DotnetTestRunner(string path, IProcessExecutor processProxy, OptimizationFlags flags, ILogger logger = null) { _logger = logger ?? ApplicationLogging.LoggerFactory.CreateLogger <DotnetTestRunner>(); _flags = flags; _path = Path.GetDirectoryName(FilePathUtils.NormalizePathSeparators(path)); _projectFile = path; _processExecutor = processProxy; CoverageMutants = new TestCoverageInfos(); }
private void UpdateMutantsWithBaselineStatus(IEnumerable <Mutant> mutants, IReadOnlyFileLeaf file) { if (!_baseline.Files.ContainsKey(FilePathUtils.NormalizePathSeparators(file.RelativePath))) { return; } SourceFile baselineFile = _baseline.Files[FilePathUtils.NormalizePathSeparators(file.RelativePath)]; if (baselineFile is { })
public void ShouldNormalizePaths() { var paths = new[] { "/c/root/bla/test.csproj" }; var expected = new[] { Path.GetFullPath(FilePathUtils.NormalizePathSeparators(paths[0])) }; var input = new TestProjectsInput { SuppliedInput = paths }; input.Validate().ShouldBe(expected); }
private string ValidateSolutionPath(string basePath, string solutionPath) { if (string.IsNullOrWhiteSpace(basePath) || string.IsNullOrWhiteSpace(solutionPath)) { return(null); } solutionPath = FilePathUtils.NormalizePathSeparators(Path.Combine(basePath, solutionPath)); return(solutionPath); }
public DotnetTestRunner(string path, IProcessExecutor processProxy, OptimizationFlags flags, IEnumerable <string> testBinariesPaths) { _logger = ApplicationLogging.LoggerFactory.CreateLogger <DotnetTestRunner>(); _flags = flags; _projectFile = FilePathUtils.NormalizePathSeparators(path); _processExecutor = processProxy; _testBinariesPaths = testBinariesPaths; _server = new CommunicationServer("CoverageCollector"); _server.SetLogger((msg) => _logger.LogDebug(msg)); _server.RaiseNewClientEvent += ConnectionEstablished; _server.Listen(); }
public IEnumerable <string> FindSharedProjects(XDocument document) { var importStatements = document.Elements().Descendants() .Where(projectElement => string.Equals(projectElement.Name.LocalName, "Import", StringComparison.OrdinalIgnoreCase)); var sharedProjects = importStatements .SelectMany(importStatement => importStatement.Attributes( XName.Get("Project"))) .Select(importFileLocation => FilePathUtils.NormalizePathSeparators(importFileLocation.Value)) .Where(importFileLocation => importFileLocation.EndsWith(".projitems")); return(sharedProjects); }
private string ValidateOutputPath(string basePath) { if (string.IsNullOrWhiteSpace(basePath)) { return(""); } var outputPath = Path.Combine(basePath, "StrykerOutput", DateTime.Now.ToString("yyyy-MM-dd.HH-mm-ss")); _fileSystem.Directory.CreateDirectory(FilePathUtils.NormalizePathSeparators(outputPath)); return(outputPath); }
private IEnumerable <FilePattern> ValidateDiffIgnoreFiles(IEnumerable <string> diffIgnoreFiles) { var mappedDiffIgnoreFiles = new List <FilePattern>(); if (diffIgnoreFiles != null) { foreach (var pattern in diffIgnoreFiles) { mappedDiffIgnoreFiles.Add(FilePattern.Parse(FilePathUtils.NormalizePathSeparators(pattern))); } } return(mappedDiffIgnoreFiles); }
public string DetermineProjectUnderTest(IEnumerable <string> projectReferences, string projectUnderTestNameFilter) { var referenceChoise = BuildReferenceChoise(projectReferences); var stringBuilder = new StringBuilder(); if (string.IsNullOrEmpty(projectUnderTestNameFilter)) { if (projectReferences.Count() > 1) { stringBuilder.AppendLine("Test project contains more than one project references. Please add the --project-file=[projectname] argument to specify which project to mutate."); stringBuilder.Append(referenceChoise); AppendExampleIfPossible(stringBuilder, projectReferences); throw new StrykerInputException(ErrorMessage, stringBuilder.ToString()); } if (!projectReferences.Any()) { stringBuilder.AppendLine("No project references found. Please add a project reference to your test project and retry."); throw new StrykerInputException(ErrorMessage, stringBuilder.ToString()); } return(projectReferences.Single()); } else { var searchResult = projectReferences.Where(x => x.ToLower().Contains(projectUnderTestNameFilter.ToLower())).ToList(); if (!searchResult.Any()) { stringBuilder.Append("No project reference matched your --project-file="); stringBuilder.AppendLine(projectUnderTestNameFilter); stringBuilder.Append(referenceChoise); AppendExampleIfPossible(stringBuilder, projectReferences, projectUnderTestNameFilter); throw new StrykerInputException(ErrorMessage, stringBuilder.ToString()); } else if (searchResult.Count() > 1) { stringBuilder.Append("More than one project reference matched your --project-file="); stringBuilder.Append(projectUnderTestNameFilter); stringBuilder.AppendLine(" argument to specify the project to mutate, please specify the name more detailed."); stringBuilder.Append(referenceChoise); AppendExampleIfPossible(stringBuilder, projectReferences, projectUnderTestNameFilter); throw new StrykerInputException(ErrorMessage, stringBuilder.ToString()); } return(FilePathUtils.NormalizePathSeparators(searchResult.Single())); } }
public async Task Save(JsonReport report, string version) { var reportDirectory = FilePathUtils.NormalizePathSeparators( Path.Combine(_options.BasePath, _outputPath, version)); _fileSystem.Directory.CreateDirectory(reportDirectory); var reportPath = Path.Combine(reportDirectory, "stryker-report.json"); await using var reportStream = _fileSystem.File.Create(reportPath); await report.SerializeAsync(reportStream); _logger.LogDebug("Baseline report has been saved to {ReportPath}", reportPath); }
public void RunAllExitCode0SuccessShouldBeTrue() { var processMock = new Mock <IProcessExecutor>(MockBehavior.Strict); processMock.SetupProcessMockToReturn("Testrun successful"); string path = FilePathUtils.NormalizePathSeparators("c://test"); var target = new DotnetTestRunner(path, processMock.Object, OptimizationFlags.NoOptimization, new string[] { "C://test//mytest.dll" }); var result = target.RunAll(null, null); Assert.True(result.Success); processMock.Verify(m => m.Start(path, "dotnet", It.Is <string>(s => s.Contains("vstest C://test//mytest.dll")), It.IsAny <IEnumerable <KeyValuePair <string, string> > >(), It.IsAny <int>())); }
public void RunAllExceptionStatusCodeSuccessShouldBeFalse() { var processMock = new Mock <IProcessExecutor>(MockBehavior.Strict); processMock.SetupProcessMockToReturn("Testrun failed other way", -100); string path = FilePathUtils.NormalizePathSeparators("c://test"); var target = new DotnetTestRunner(path, processMock.Object, OptimizationFlags.NoOptimization, new[] { "C://test//mytest.dll" }); var result = target.RunAll(null, null, null); Assert.Equal(1, result.FailingTests.Count); processMock.Verify(m => m.Start(path, "dotnet", It.Is <string>(s => s.Contains("vstest")), It.IsAny <IEnumerable <KeyValuePair <string, string> > >(), It.IsAny <int>())); }
public void Parse_should_parse_correctly(string spanPattern, string glob, bool isExclude, int[] spans) { // Arrange var textSpans = Enumerable.Range(0, spans.Length) .GroupBy(i => Math.Floor(i / 2d)) .Select(x => TextSpan.FromBounds(spans[x.First()], spans[x.Skip(1).First()])); // Act var result = FilePattern.Parse(spanPattern); // Assert result.Glob.ToString().ShouldBe(FilePathUtils.NormalizePathSeparators(glob)); result.IsExclude.ShouldBe(isExclude); result.TextSpans.SequenceEqual(textSpans).ShouldBe(true); }
public async Task Save(JsonReport report, string version) { var reportPath = FilePathUtils.NormalizePathSeparators( Path.Combine(_options.BasePath, _outputPath, version)); var reportJson = report.ToJson(); _fileSystem.Directory.CreateDirectory(reportPath); using StreamWriter outputWriter = _fileSystem.File.CreateText(Path.Combine(reportPath, $"stryker-report.json")); await outputWriter.WriteAsync(reportJson); _logger.LogDebug($"Baseline report has been saved to {Path.Combine(reportPath, $"stryker-report.json")}"); }
public void InputFileResolver_ShouldChooseGivenTestProjectFileIfPossible_AtFullPath() { var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { Path.Combine(_filesystemRoot, "ExampleProject", "ExampleProject.csproj"), new MockFileData(defaultTestProjectFileContents) }, { Path.Combine(_filesystemRoot, "ExampleProject", "SubFolder", "TestProject.csproj"), new MockFileData(defaultTestProjectFileContents) }, { Path.Combine(_filesystemRoot, "ExampleProject", "Recursive.cs"), new MockFileData("content") } }); var target = new InputFileResolver(fileSystem, null); var actual = target.FindProjectFile(Path.Combine(_filesystemRoot, "ExampleProject"), FilePathUtils.NormalizePathSeparators(Path.Combine(_filesystemRoot, "ExampleProject", "SubFolder", "TestProject.csproj"))); actual.ShouldBe(Path.Combine(_filesystemRoot, "ExampleProject", "SubFolder", "TestProject.csproj")); }