public void Process(ReferencedFile referencedFile) { if (!referencedFile.IsFileUnderTest) { return; } var isCoffeeFile = referencedFile.Path.EndsWith(Constants.CoffeeScriptExtension, StringComparison.OrdinalIgnoreCase); var regExp = isCoffeeFile ? RegexPatterns.QUnitTestRegexCoffeeScript : RegexPatterns.QUnitTestRegexJavaScript; var lines = fileSystem.GetLines(referencedFile.Path); int lineNum = 1; foreach (var line in lines) { var match = regExp.Match(line); while (match.Success) { var testName = match.Groups["Test"].Value; if (!string.IsNullOrWhiteSpace(testName)) { var testFunc = match.Groups["Tf"]; referencedFile.FilePositions.Add(lineNum, testFunc.Index + 1); } match = match.NextMatch(); } lineNum++; } }
public override Regex GetTestPattern(ReferencedFile referencedFile, string testFileText, ChutzpahTestSettingsFile settings) { var mochaFrameworkDefinition = MochaDefinition.GetInterfaceType(settings, referencedFile.Path, testFileText); var isCoffeeFile = referencedFile.Path.EndsWith(Constants.CoffeeScriptExtension, StringComparison.OrdinalIgnoreCase); switch (mochaFrameworkDefinition) { case Constants.MochaQunitInterface: return isCoffeeFile ? RegexPatterns.MochaTddOrQunitTestRegexCoffeeScript : RegexPatterns.MochaTddOrQunitTestRegexJavaScript; case Constants.MochaBddInterface: return isCoffeeFile ? RegexPatterns.MochaBddTestRegexCoffeeScript : RegexPatterns.MochaBddTestRegexJavaScript; case Constants.MochaTddInterface: return isCoffeeFile ? RegexPatterns.MochaTddOrQunitTestRegexCoffeeScript : RegexPatterns.MochaTddOrQunitTestRegexJavaScript; case Constants.MochaExportsInterface: return isCoffeeFile ? RegexPatterns.MochaExportsTestRegexCoffeeScript : RegexPatterns.MochaExportsTestRegexJavaScript; default: return isCoffeeFile ? RegexPatterns.MochaBddTestRegexCoffeeScript : RegexPatterns.MochaBddTestRegexJavaScript; } }
public ExternalStylesheet(ReferencedFile referencedFile) : base(referencedFile, "link", false) { Attributes.Add("rel", "stylesheet"); Attributes.Add("type", "text/css"); Attributes.Add("href", GetAbsoluteFileUrl(referencedFile)); }
public ShortcutIcon(ReferencedFile referencedFile) : base(referencedFile, "link", false) { Attributes.Add("rel", "shortcut icon"); Attributes.Add("type", "image/png"); Attributes.Add("href", GetAbsoluteFileUrl(referencedFile)); }
public void Process(IFrameworkDefinition frameworkDefinition, ReferencedFile referencedFile, string testFileText, ChutzpahTestSettingsFile settings) { if (!referencedFile.IsFileUnderTest) { return; } var regExp = settings.TestPatternRegex ?? GetTestPattern(referencedFile,testFileText, settings); var lines = fileSystem.GetLines(referencedFile.Path); int lineNum = 1; foreach (var line in lines) { var match = regExp.Match(line); while (match.Success) { var testNameGroup = match.Groups["TestName"]; var testName = testNameGroup.Value; if (!string.IsNullOrWhiteSpace(testName)) { referencedFile.FilePositions.Add(lineNum, testNameGroup.Index + 1, testName); } match = match.NextMatch(); } lineNum++; } }
public override Regex GetTestPattern(ReferencedFile referencedFile, string testFileText, ChutzpahTestSettingsFile settings) { var isCoffeeFile = referencedFile.Path.EndsWith(Constants.CoffeeScriptExtension, StringComparison.OrdinalIgnoreCase); var regExp = isCoffeeFile ? RegexPatterns.QUnitTestRegexCoffeeScript : RegexPatterns.QUnitTestRegexJavaScript; return regExp; }
private static void AddLineNumber(ReferencedFile referencedFile, int testIndex, JsTestCase jsTestCase) { if (referencedFile != null && referencedFile.FilePositions.Contains(testIndex)) { var position = referencedFile.FilePositions[testIndex]; jsTestCase.TestCase.Line = position.Line; jsTestCase.TestCase.Column = position.Column; } }
public void Process(ReferencedFile referencedFile) { if (!referencedFile.IsFileUnderTest) { return; } var isCoffeeFile = referencedFile.Path.EndsWith(Constants.CoffeeScriptExtension, StringComparison.OrdinalIgnoreCase); var lines = this.fileSystem.GetLines(referencedFile.Path); var contents = string.Join(Environment.NewLine, lines); var coffeeScriptTestPatterns = new[] { RegexPatterns.MochaBddTestRegexCoffeeScript, RegexPatterns.MochaTddOrQunitTestRegexCoffeeScript, RegexPatterns.MochaExportsTestRegexCoffeeScript }; var javaScriptTestPatterns = new[] { RegexPatterns.MochaBddTestRegexJavaScript, RegexPatterns.MochaTddOrQunitTestRegexJavaScript, RegexPatterns.MochaExportsTestRegexJavaScript }; var patterns = isCoffeeFile ? coffeeScriptTestPatterns : javaScriptTestPatterns; var regExp = patterns.FirstOrDefault(p => p.IsMatch(contents)); if (regExp == null) return; int lineNum = 1; foreach (var line in lines) { var match = regExp.Match(line); while (match.Success) { var testName = match.Groups["Test"].Value; if (!string.IsNullOrWhiteSpace(testName)) { var testFunc = match.Groups["Tf"]; referencedFile.FilePositions.Add(lineNum, testFunc.Index + 1); } match = match.NextMatch(); } lineNum++; } }
protected void WriteGeneratedReferencedFile(ReferencedFile referencedFile, string generatedContent, IList<string> temporaryFiles) { var folderPath = Path.GetDirectoryName(referencedFile.Path); var fileName = Path.GetFileNameWithoutExtension(referencedFile.Path) + ".js"; var newFilePath = Path.Combine(folderPath, string.Format(Constants.ChutzpahTemporaryFileFormat, Thread.CurrentThread.ManagedThreadId, fileName)); fileSystem.WriteAllText(newFilePath, generatedContent); referencedFile.GeneratedFilePath = newFilePath; temporaryFiles.Add(newFilePath); }
public int?[] GetOriginalFileLineExecutionCounts(int?[] generatedSourceLineExecutionCounts, int sourceLineCount, ReferencedFile referencedFile) { if (generatedSourceLineExecutionCounts == null) { throw new ArgumentNullException("generatedSourceLineExecutionCounts"); } if (referencedFile == null) { throw new ArgumentNullException("referencedFile"); } else if (string.IsNullOrWhiteSpace(referencedFile.SourceMapFilePath)) { return generatedSourceLineExecutionCounts; } else if (!fileSystem.FileExists(referencedFile.SourceMapFilePath)) { throw new ArgumentException("mapFilePath", string.Format("Cannot find map file '{0}'", referencedFile.SourceMapFilePath)); } var consumer = this.GetConsumer(fileSystem.GetText(referencedFile.SourceMapFilePath)); var accumulated = new List<int?>(new int?[sourceLineCount + 1]); for (var i = 1; i < generatedSourceLineExecutionCounts.Length; i++) { int? generatedCount = generatedSourceLineExecutionCounts[i]; if (generatedCount == null) { continue; } var matches = consumer.OriginalPositionsFor(i); if (matches.Any()) { foreach (var match in matches) { if (match.File.ToLower() != fileSystem.GetFileName(referencedFile.Path.ToLower())) continue; accumulated[match.LineNumber] = (accumulated[match.LineNumber] ?? 0) + generatedCount.Value; } } } return accumulated.ToArray(); }
public void Process(IFrameworkDefinition frameworkDefinition, ReferencedFile referencedFile, string testFileText, ChutzpahTestSettingsFile settings) { if (!referencedFile.IsFileUnderTest) { return; } var regExp = settings.TestPatternRegex ?? GetTestPattern(referencedFile, testFileText, settings); int lineNum = 1; using (var reader = new StringReader(testFileText)) { string line; while ((line = reader.ReadLine()) != null) { var match = regExp.Match(line); while (match.Success) { var testNameGroup = match.Groups["TestName"]; var testName = testNameGroup.Value; if (!string.IsNullOrWhiteSpace(testName)) { referencedFile.FilePositions.Add(lineNum, testNameGroup.Index + 1, testName); } match = match.NextMatch(); } lineNum++; } } }
/// <summary> /// Is this a source mapping for the current referenced file /// </summary> private bool IsCurrentFile(string relativePath, ReferencedFile referencedFile) { var candidatePath = FileProbe.NormalizeFilePath(new Uri(Path.Combine(Path.GetDirectoryName(referencedFile.SourceMapFilePath), relativePath)).AbsolutePath); return referencedFile.Path.Equals(candidatePath, StringComparison.OrdinalIgnoreCase); }
public Script(ReferencedFile referencedFile) : base(referencedFile, "script", true) { Attributes.Add("type", "text/javascript"); Attributes.Add("src", GetAbsoluteFileUrl(referencedFile)); }
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 "file:///" + FileProbe.EncodeFilePath(referencePath); } return referencePath; }
public Html(ReferencedFile referencedFile, IFileSystemWrapper fileSystem) : base(referencedFile, null, false) { contents = fileSystem.GetText(referencedFile.Path); }
/// <summary> /// Determines if this generator can handle the referencefile. /// This must be overridden in the base class /// </summary> public abstract bool CanHandleFile(ReferencedFile referencedFile);
private static IEnumerable<ReferencedFile> FlattenReferenceGraph(ReferencedFile rootFile) { var flattenedFileList = new List<ReferencedFile>(); foreach (ReferencedFile childFile in rootFile.ReferencedFiles) { flattenedFileList.AddRange(FlattenReferenceGraph(childFile)); } flattenedFileList.Add(rootFile); return flattenedFileList; }
private IList<TestHarnessItem> ChooseRefList(ReferencedFile referencedFile, string referencePath) { var codeCoverageEnabled = (!chutzpahTestSettings.EnableCodeCoverage.HasValue && testOptions.CoverageOptions.Enabled) || (chutzpahTestSettings.EnableCodeCoverage.HasValue && chutzpahTestSettings.EnableCodeCoverage.Value); // If CodeCoverage is enabled and we are in Execution mode make sure we load requirejs before the code coverage files var referencedFileName = Path.GetFileName(referencedFile.Path); var amdLoader = codeCoverageEnabled && !string.IsNullOrEmpty(referencedFileName) && RegexPatterns.IsRequireJsFileName.IsMatch(referencedFileName) && testOptions.TestExecutionMode == TestExecutionMode.Execution; IList<TestHarnessItem> list = null; if (referencedFile.IsTestFrameworkFile) { list = TestFrameworkDependencies; } else if (referencedFile.IsCodeCoverageDependency || amdLoader) { list = CodeCoverageDependencies; } else if (referencePath.EndsWith(Constants.CssExtension, StringComparison.OrdinalIgnoreCase)) { list = ReferencedStyles; } else if (referencePath.EndsWith(Constants.JavaScriptExtension, StringComparison.OrdinalIgnoreCase)) { list = ReferencedScripts; } else if (referencePath.EndsWith(Constants.HtmlScriptExtension, StringComparison.OrdinalIgnoreCase) || referencePath.EndsWith(Constants.HtmScriptExtension, StringComparison.OrdinalIgnoreCase) || referencePath.EndsWith(Constants.CSHtmlScriptExtension, StringComparison.OrdinalIgnoreCase)) { list = ReferencedHtmlTemplates; } return list; }
public Html(ReferencedFile referencedFile, IFileSystemWrapper fileSystem) : base(referencedFile, null, false) { contents = fileSystem.GetText(referencedFile.Path); if(referencedFile.TemplateOptions.Mode == TemplateMode.Script) { contents = string.Format(scriptTagWrapper, referencedFile.TemplateOptions.Id, referencedFile.TemplateOptions.Type, contents); } }
public abstract Regex GetTestPattern(ReferencedFile referencedFile, string testFileText, ChutzpahTestSettingsFile settings);
public override bool CanHandleFile(ReferencedFile referencedFile) { return referencedFile.Path.EndsWith(Constants.CoffeeScriptExtension, StringComparison.OrdinalIgnoreCase); }
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, 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> /// Processes a referenced file according to the framework's needs. /// </summary> /// <param name="referencedFile">A referenced file to process.</param> public void Process(ReferencedFile referencedFile) { if (FileProcessors != null) { foreach (IReferencedFileProcessor item in FileProcessors) { item.Process(referencedFile); } } }
private ReferencedFile VisitReferencedFile( string absoluteFilePath, IFrameworkDefinition definition, HashSet<string> discoveredPaths, ICollection<ReferencedFile> referencedFiles, ChutzpahTestSettingsFile chutzpahTestSettings, ReferencePathSettings pathSettings) { // If the file doesn't exit exist or we have seen it already then return if (discoveredPaths.Contains(absoluteFilePath)) return null; var referencedFile = new ReferencedFile { Path = absoluteFilePath, IsLocal = true, IsTestFrameworkFile = pathSettings.IsTestFrameworkFile, IncludeInTestHarness = pathSettings.IncludeInTestHarness || chutzpahTestSettings.TestHarnessReferenceMode == TestHarnessReferenceMode.Normal, TemplateOptions = pathSettings.TemplateOptions }; ChutzpahTracer.TraceInformation( "Added file '{0}' to referenced files. Local: {1}, IncludeInTestHarness: {2}", referencedFile.Path, referencedFile.IsLocal, referencedFile.IncludeInTestHarness); referencedFiles.Add(referencedFile); discoveredPaths.Add(referencedFile.Path); // Remmember this path to detect reference loops ChutzpahTracer.TraceInformation("Processing referenced file '{0}' for expanded references", absoluteFilePath); if (pathSettings.ExpandReferenceComments) { referencedFile.ReferencedFiles = ExpandNestedReferences(discoveredPaths, definition, absoluteFilePath, chutzpahTestSettings); } return referencedFile; }
private IList<TestHarnessItem> ChooseRefList(ReferencedFile referencedFile, string referencePath) { // If CodeCoverage is enabled make sure we load requirejs before the code coverage files var amdLoader = testOptions.CoverageOptions.Enabled && RegexPatterns.IsRequireJsFileName.IsMatch(Path.GetFileName(referencedFile.Path)); IList<TestHarnessItem> list = null; if (referencedFile.IsTestFrameworkDependency) { list = TestFrameworkDependencies; } else if (referencedFile.IsCodeCoverageDependency || amdLoader) { list = CodeCoverageDependencies; } else if (referencePath.EndsWith(Constants.CssExtension, StringComparison.OrdinalIgnoreCase)) { list = ReferencedStyles; } else if (referencePath.EndsWith(Constants.JavaScriptExtension, StringComparison.OrdinalIgnoreCase)) { list = ReferencedScripts; } else if (referencePath.EndsWith(Constants.HtmlScriptExtension, StringComparison.OrdinalIgnoreCase) || referencePath.EndsWith(Constants.HtmScriptExtension, StringComparison.OrdinalIgnoreCase)) { list = ReferencedHtmlTemplates; } return list; }
/// <summary> /// Processes a referenced file according to the framework's needs. /// </summary> /// <param name="referencedFile">A referenced file to process.</param> /// <param name="testFileText"></param> /// <param name="settings"></param> public void Process(ReferencedFile referencedFile, string testFileText, ChutzpahTestSettingsFile settings) { if (FileProcessors != null) { foreach (IReferencedFileProcessor item in FileProcessors) { item.Process(this, referencedFile, testFileText, settings); } } }
internal TestHarnessItem(ReferencedFile referencedFile, string tagName, bool explicitEndTag) : this(tagName, explicitEndTag) { ReferencedFile = referencedFile; }
public void Process(IFrameworkDefinition frameworkDefinition, ReferencedFile referencedFile, string testFileText, ChutzpahTestSettingsFile settings) { referencedFile.FrameworkReplacements = frameworkDefinition.GetFrameworkReplacements(settings, referencedFile.Path, testFileText); }
public StreamingTestFileContext(ReferencedFile referencedFile, TestContext testContext, bool coverageEnabled) { SeenTests = new HashSet<Tuple<string, string>>(); ReferencedFile = referencedFile; TestContext = testContext; TestFileSummary = new TestFileSummary(referencedFile.Path); if (coverageEnabled) { TestFileSummary.CoverageObject = new CoverageData(); } }