/// <summary> /// Matches the current test path against the Tests settings. The first setting to accept a file wins. /// </summary> private bool IsTestPathIncluded(string testFilePath, ChutzpahTestSettingsFile chutzpahTestSettings, out SettingsFileTestPath matchingTestPath) { matchingTestPath = null; // If those test filters are given then accept the test path if (!chutzpahTestSettings.Tests.Any()) { return(true); } testFilePath = UrlBuilder.NormalizeFilePath(testFilePath); foreach (var pathSettings in chutzpahTestSettings.Tests.Where(x => x != null)) { var includePatterns = pathSettings.Includes.Select(x => UrlBuilder.NormalizeFilePath(x)).ToList(); var excludePatterns = pathSettings.Excludes.Select(x => UrlBuilder.NormalizeFilePath(x)).ToList(); // The path we assume default to the chuzpah.json directory if the Path property is not set var testPath = string.IsNullOrEmpty(pathSettings.Path) ? pathSettings.SettingsFileDirectory : pathSettings.Path; testPath = UrlBuilder.NormalizeFilePath(testPath); testPath = testPath != null?Path.Combine(pathSettings.SettingsFileDirectory, testPath) : null; // If a file path is given just match the test file against it to see if we should urn var filePath = fileProbe.FindFilePath(testPath); if (filePath != null) { if (filePath.Equals(testFilePath, StringComparison.OrdinalIgnoreCase)) { matchingTestPath = pathSettings; ChutzpahTracer.TraceInformation("Test file {0} matched test file path from settings file", testFilePath); return(true); } } // If a folder path is given then match the test file path that is in that folder with the optional include/exclude paths var folderPath = UrlBuilder.NormalizeFilePath(fileProbe.FindFolderPath(testPath)); if (folderPath != null) { if (testFilePath.Contains(folderPath)) { var shouldIncludeFile = (!includePatterns.Any() || includePatterns.Any(pat => NativeImports.PathMatchSpec(testFilePath, pat))) && (!excludePatterns.Any() || !excludePatterns.Any(pat => NativeImports.PathMatchSpec(testFilePath, pat))); if (shouldIncludeFile) { ChutzpahTracer.TraceInformation( "Test file {0} matched folder {1} with includes {2} and excludes {3} patterns from settings file", testFilePath, folderPath, string.Join(",", includePatterns), string.Join(",", excludePatterns)); matchingTestPath = pathSettings; return(true); } else { ChutzpahTracer.TraceInformation( "Test file {0} did not match folder {1} with includes {2} and excludes {3} patterns from settings file", testFilePath, folderPath, string.Join(",", includePatterns), string.Join(",", excludePatterns)); } } } } return(false); }
/// <summary> /// Matches the current test path against the Tests settings. The first setting to accept a file wins. /// </summary> private bool IsTestPathIncluded(string testFilePath, ChutzpahTestSettingsFile chutzpahTestSettings, out SettingsFileTestPath matchingTestPath) { matchingTestPath = null; // If those test filters are given then accept the test path if (!chutzpahTestSettings.Tests.Any()) { return true; } testFilePath = FileProbe.NormalizeFilePath(testFilePath); foreach (var pathSettings in chutzpahTestSettings.Tests.Where(x => x != null)) { var includePatterns = pathSettings.Includes.Select(x => FileProbe.NormalizeFilePath(x)).ToList(); var excludePatterns = pathSettings.Excludes.Select(x => FileProbe.NormalizeFilePath(x)).ToList(); // The path we assume default to the chuzpah.json directory if the Path property is not set var testPath = string.IsNullOrEmpty(pathSettings.Path) ? pathSettings.SettingsFileDirectory : pathSettings.Path; testPath = FileProbe.NormalizeFilePath(testPath); testPath = testPath != null ? Path.Combine(pathSettings.SettingsFileDirectory, testPath) : null; // If a file path is given just match the test file against it to see if we should urn var filePath = fileProbe.FindFilePath(testPath); if (filePath != null) { if (filePath.Equals(testFilePath, StringComparison.OrdinalIgnoreCase)) { matchingTestPath = pathSettings; ChutzpahTracer.TraceInformation("Test file {0} matched test file path from settings file", testFilePath); return true; } } // If a folder path is given then match the test file path that is in that folder with the optional include/exclude paths var folderPath = FileProbe.NormalizeFilePath(fileProbe.FindFolderPath(testPath)); if (folderPath != null) { if (testFilePath.Contains(folderPath)) { var shouldIncludeFile = (!includePatterns.Any() || includePatterns.Any(pat => NativeImports.PathMatchSpec(testFilePath, pat))) && (!excludePatterns.Any() || !excludePatterns.Any(pat => NativeImports.PathMatchSpec(testFilePath, pat))); if (shouldIncludeFile) { ChutzpahTracer.TraceInformation( "Test file {0} matched folder {1} with includes {2} and excludes {3} patterns from settings file", testFilePath, folderPath, string.Join(",", includePatterns), string.Join(",", excludePatterns)); matchingTestPath = pathSettings; return true; } else { ChutzpahTracer.TraceInformation( "Test file {0} did not match folder {1} with includes {2} and excludes {3} patterns from settings file", testFilePath, folderPath, string.Join(",", includePatterns), string.Join(",", excludePatterns)); } } } } return false; }