private static string BuildHarnessUrl(string absolutePath, bool isRemoteHarness) { if (isRemoteHarness) { return(absolutePath); } else { return(string.Format("\"{0}\"", FileProbe.GenerateFileUrl(absolutePath))); } }
private static string GetAmdPath(string testHarnessDirectory, string filePath, string relativeAmdRootPath) { string amdModulePath = FileProbe.GetRelativePath(testHarnessDirectory, filePath); amdModulePath = Path.Combine(relativeAmdRootPath, amdModulePath) .Replace(Path.GetExtension(filePath), "") .Replace("\\", "/") .Trim('/', '\\'); return(amdModulePath); }
private static string GetAmdPath(string filePath, string amdAppRoot) { string amdModulePath = FileProbe.GetRelativePath(amdAppRoot, filePath); amdModulePath = amdModulePath .Replace(Path.GetExtension(filePath), "") .Replace("\\", "/") .Trim('/', '\\'); return(amdModulePath); }
protected static string GetAbsoluteFileUrl(ReferencedFile referencedFile) { string referencePath = string.IsNullOrEmpty(referencedFile.GeneratedFilePath) ? referencedFile.Path : referencedFile.GeneratedFilePath; if (!RegexPatterns.SchemePrefixRegex.IsMatch(referencePath)) { // Encode the reference path and then decode / (forward slash) and \ (back slash) into / (forward slash) return(FileProbe.GenerateFileUrl(referencePath)); } return(referencePath); }
public bool IsTestFile(string file, ChutzpahSettingsFileEnvironments environments = null) { ChutzpahTracer.TraceInformation("Determining if {0} might be a test file", file); if (string.IsNullOrWhiteSpace(file)) { return(false); } var testFilePath = fileProbe.FindFilePath(file); if (testFilePath == null) { ChutzpahTracer.TraceInformation("Rejecting '{0}' since either it doesnt exist", file); return(false); } var chutzpahTestSettings = settingsService.FindSettingsFile(testFilePath, environments); if (!IsTestPathIncluded(testFilePath, chutzpahTestSettings)) { ChutzpahTracer.TraceInformation("Excluded test file '{0}' given chutzpah.json settings", testFilePath); return(false); } // If the framework or tests filters are set in the settings file then no need to check for // test framework if (!string.IsNullOrEmpty(chutzpahTestSettings.Framework) || chutzpahTestSettings.Tests.Any()) { return(true); } else { string testFileText = fileSystem.GetText(testFilePath); IFrameworkDefinition definition; var info = new PathInfo { Path = file, FullPath = testFilePath, Type = FileProbe.GetFilePathType(testFilePath) }; var frameworkDetetected = TryDetectFramework(info, chutzpahTestSettings, out definition); if (frameworkDetetected) { ChutzpahTracer.TraceInformation("Assuming '{0}' is a test file", file); } return(frameworkDetetected); } }
/// <summary> /// Add the AMD file paths for the Path and GeneratePath fields /// </summary> /// <param name="referencedFiles"></param> /// <param name="testHarnessDirectory"></param> /// <param name="testSettings"></param> public void SetupAmdFilePaths(List <ReferencedFile> referencedFiles, string testHarnessDirectory, ChutzpahTestSettingsFile testSettings) { // If the user set a AMD base path then we must relativize the amd path's using the path from the base path to the test harness directory string relativeAmdRootPath = ""; if (!string.IsNullOrEmpty(testSettings.AMDBasePath)) { relativeAmdRootPath = FileProbe.GetRelativePath(testSettings.AMDBasePath, testHarnessDirectory); } foreach (var referencedFile in referencedFiles) { referencedFile.AmdFilePath = GetAmdPath(testHarnessDirectory, referencedFile.Path, relativeAmdRootPath); if (!string.IsNullOrEmpty(referencedFile.GeneratedFilePath)) { referencedFile.AmdGeneratedFilePath = GetAmdPath(testHarnessDirectory, referencedFile.GeneratedFilePath, relativeAmdRootPath); } } }
public void LaunchFileInBrowser(string file, string browserName = null) { file = FileProbe.GenerateFileUrl(file); var browserAppPath = BrowserPathHelper.GetBrowserPath(browserName); var startInfo = new ProcessStartInfo(); if (!string.IsNullOrEmpty(browserAppPath)) { startInfo.UseShellExecute = true; startInfo.FileName = browserAppPath; startInfo.Arguments = file; } else { startInfo.UseShellExecute = true; startInfo.Verb = "Open"; startInfo.FileName = file; } Process.Start(startInfo); }
private void ResolveCompilePathMap(ChutzpahTestSettingsFile settings, IDictionary <string, string> chutzpahVariables, CompilePathMap pathMap) { var sourcePath = pathMap.SourcePath; bool?sourcePathIsFile = false; // If SourcePath is null then we will assume later on this is the current settings directory pathMap.SourcePath = ResolvePath(settings, sourcePath, out sourcePathIsFile); if (pathMap.SourcePath == null) { throw new FileNotFoundException("Unable to find file/directory specified by SourcePath of {0}", (sourcePath ?? "")); } pathMap.SourcePathIsFile = sourcePathIsFile.HasValue ? sourcePathIsFile.Value : false; // If OutputPath is null then we will assume later on this is the current settings directory // We do not use the resolvePath method here since the path may not exist yet pathMap.OutputPath = FileProbe.NormalizeFilePath(Path.Combine(settings.SettingsFileDirectory, ExpandVariable(chutzpahVariables, pathMap.OutputPath))); if (pathMap.OutputPath == null) { throw new FileNotFoundException("Unable to find file/directory specified by OutputPath of {0}", (pathMap.OutputPath ?? "")); } // Since the output path might not exist yet we need a more complicated way to // determine if it is a file or folder // 1. If the user explicitly told us what it should be using OutputPathType use that // 2. Assume it is a file if it has a .js extension if (pathMap.OutputPathType.HasValue) { pathMap.OutputPathIsFile = pathMap.OutputPathType == CompilePathType.File; } else { pathMap.OutputPathIsFile = pathMap.OutputPath.EndsWith(".js", StringComparison.OrdinalIgnoreCase); } }
/// <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); }
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 => FileProbe.NormalizeFilePath(x)).ToList(); var excludePatterns = pathSettings.Excludes.Select(x => FileProbe.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 = FileProbe.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, }; ChutzpahTracer.TraceInformation( "Added file '{0}' to referenced files. Local: {1}, IncludeInTestHarness: {2}", referencedFile.Path, referencedFile.IsLocal, referencedFile.IncludeInTestHarness); referencedFiles.Add(referencedFile); } }