/// <summary> /// Resolved a path relative to the settings file if it is not absolute /// </summary> private string ResolveFolderPath(ChutzpahTestSettingsFile settings, string path, bool createIfNeeded = false) { string relativeLocationPath = Path.Combine(settings.SettingsFileDirectory, path ?? ""); string absoluteFilePath = fileProbe.FindFolderPath(relativeLocationPath); if (createIfNeeded && absoluteFilePath == null) { fileSystem.CreateDirectory(relativeLocationPath); absoluteFilePath = fileProbe.FindFolderPath(relativeLocationPath); } return(absoluteFilePath); }
/// <summary> /// Resolved a path relative to the settings file if it is not absolute /// </summary> private string ResolveFolderPath(ChutzpahTestSettingsFile settings, string path) { string relativeLocationPath = Path.Combine(settings.SettingsFileDirectory, path ?? ""); string absoluteFilePath = fileProbe.FindFolderPath(relativeLocationPath); return(absoluteFilePath ?? relativeLocationPath); }
private IDictionary <string, string> BuildEnvironmentVariables() { var envVars = new Dictionary <string, string>(); var chutzpahNodeModules = fileProbe.FindFolderPath(PackagesPath); envVars.Add("NODE_PATH", chutzpahNodeModules); return(envVars); }
private void ProcessFilePathAsReference( HashSet <string> discoveredPaths, IFrameworkDefinition definition, string relativeProcessingPath, ChutzpahTestSettingsFile chutzpahTestSettings, string referencePath, List <ReferencedFile> referencedFiles, ReferencePathSettings pathSettings) { ChutzpahTracer.TraceInformation("Investigating reference file path '{0}'", referencePath); // Check test settings and adjust the path if it is rooted (e.g. /some/path) referencePath = AdjustPathIfRooted(chutzpahTestSettings, referencePath); var referenceUri = new Uri(referencePath, UriKind.RelativeOrAbsolute); string referenceFileName = Path.GetFileName(referencePath); // Ignore test runner, since we use our own. if (definition.ReferenceIsDependency(referenceFileName, chutzpahTestSettings)) { ChutzpahTracer.TraceInformation( "Ignoring reference file '{0}' as a duplicate reference to {1}", referenceFileName, definition.FrameworkKey); return; } var isRelativeUri = !referenceUri.IsAbsoluteUri; // If this either a relative uri or a file uri if (isRelativeUri || referenceUri.IsFile) { var relativeProcessingPathFolder = fileSystem.FolderExists(relativeProcessingPath) ? relativeProcessingPath : Path.GetDirectoryName(relativeProcessingPath); string relativeReferencePath = Path.Combine(relativeProcessingPathFolder, referencePath); // Check if reference is a file string absoluteFilePath = fileProbe.FindFilePath(relativeReferencePath); if (absoluteFilePath != null) { VisitReferencedFile(absoluteFilePath, definition, discoveredPaths, referencedFiles, chutzpahTestSettings, pathSettings); return; } // Check if reference is a folder string absoluteFolderPath = fileProbe.FindFolderPath(relativeReferencePath); if (absoluteFolderPath != null) { var includePatterns = pathSettings.Includes.Select(x => UrlBuilder.NormalizeFilePath(x)).ToList(); var excludePatterns = pathSettings.Excludes.Select(x => UrlBuilder.NormalizeFilePath(x)).ToList(); // Find all files in this folder including sub-folders. This can be ALOT of files. // Only a subset of these files Chutzpah might understand so many of these will be ignored. var childFiles = fileSystem.GetFiles(absoluteFolderPath, "*.*", SearchOption.AllDirectories); var validFiles = from file in childFiles let normalizedFile = UrlBuilder.NormalizeFilePath(file) where !fileProbe.IsTemporaryChutzpahFile(file) && (!includePatterns.Any() || includePatterns.Any(pat => NativeImports.PathMatchSpec(normalizedFile, pat))) && (!excludePatterns.Any() || !excludePatterns.Any(pat => NativeImports.PathMatchSpec(normalizedFile, pat))) select file; validFiles.ForEach(file => VisitReferencedFile(file, definition, discoveredPaths, referencedFiles, chutzpahTestSettings, pathSettings)); return; } // At this point we know that this file/folder does not exist! ChutzpahTracer.TraceWarning("Referenced file '{0}' which was resolved to '{1}' does not exist", referencePath, relativeReferencePath); } else if (referenceUri.IsAbsoluteUri) { var referencedFile = new ReferencedFile { Path = referencePath, IsLocal = false, IncludeInTestHarness = true, IsTestFrameworkFile = pathSettings.IsTestFrameworkFile, TemplateOptions = pathSettings.TemplateOptions }; ChutzpahTracer.TraceInformation( "Added file '{0}' to referenced files. Local: {1}, IncludeInTestHarness: {2}", referencedFile.Path, referencedFile.IsLocal, referencedFile.IncludeInTestHarness); referencedFiles.Add(referencedFile); } }
/// <summary> /// Matches the current test path against the Tests settings. The first setting to accept a file wins. /// </summary> /// <param name="testFilePath"></param> /// <param name="chutzpahTestSettings"></param> /// <returns></returns> private bool IsTestPathIncluded(string testFilePath, ChutzpahTestSettingsFile chutzpahTestSettings) { // 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 includePattern = FileProbe.NormalizeFilePath(pathSettings.Include); var excludePattern = FileProbe.NormalizeFilePath(pathSettings.Exclude); // The path we assume default to the chuzpah.json directory if the Path property is not set var testPath = string.IsNullOrEmpty(pathSettings.Path) ? chutzpahTestSettings.SettingsFileDirectory : pathSettings.Path; testPath = FileProbe.NormalizeFilePath(testPath); testPath = testPath != null?Path.Combine(chutzpahTestSettings.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)) { 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 = (includePattern == null || NativeImports.PathMatchSpec(testFilePath, includePattern)) && (excludePattern == null || !NativeImports.PathMatchSpec(testFilePath, excludePattern)); if (shouldIncludeFile) { ChutzpahTracer.TraceInformation( "Test file {0} matched folder {1} with include {2} and exclude {3} patterns from settings file", testFilePath, folderPath, includePattern, excludePattern); return(true); } else { ChutzpahTracer.TraceInformation( "Test file {0} did not match folder {1} with include {2} and exclude {3} patterns from settings file", testFilePath, folderPath, includePattern, excludePattern); } } } } return(false); }
private static void ValidateTestHarnessLocationMode(ChutzpahTestSettingsFile settings, IFileProbe fileProbe) { if (settings.TestHarnessLocationMode == TestHarnessLocationMode.Custom) { if (settings.TestHarnessDirectory != null) { string relativeLocationPath = Path.Combine(settings.SettingsFileDirectory, settings.TestHarnessDirectory); string absoluteFilePath = fileProbe.FindFolderPath(relativeLocationPath); settings.TestHarnessDirectory = absoluteFilePath; } if (settings.TestHarnessDirectory == null) { settings.TestHarnessLocationMode = TestHarnessLocationMode.TestFileAdjacent; ChutzpahTracer.TraceWarning("Unable to find custom test harness directory at {0}", settings.TestHarnessDirectory); } } }