Пример #1
0
        public virtual void TestFinished(TestCase testCase)
        {
            switch (testCase.TestOutcome)
            {
            case TestOutcome.Passed:
                ChutzpahTracer.TraceInformation("File {0}, Test {1} passed", testCase.InputTestFile, testCase.TestName);
                TestPassed(testCase);
                break;

            case TestOutcome.Failed:
                ChutzpahTracer.TraceInformation("File {0}, Test {1} failed", testCase.InputTestFile, testCase.TestName);
                TestFailed(testCase);
                break;

            case TestOutcome.Skipped:
                ChutzpahTracer.TraceInformation("File {0}, Test {1} skipped", testCase.InputTestFile, testCase.TestName);
                TestSkipped(testCase);
                break;

            default:
                break;
            }

            TestComplete(testCase);
        }
Пример #2
0
        private ICoverageEngine SetupCodeCoverageEngine(
            TestOptions options,
            ChutzpahTestSettingsFile chutzpahTestSettings,
            IFrameworkDefinition definition,
            List <ReferencedFile> referencedFiles)
        {
            ICoverageEngine coverageEngine = GetConfiguredCoverageEngine(options, chutzpahTestSettings);

            if (coverageEngine != null)
            {
                var deps = coverageEngine.GetFileDependencies(definition, chutzpahTestSettings);

                foreach (string item in deps)
                {
                    string sourcePath = Path.Combine(fileProbe.BuiltInDependencyDirectory, item);
                    ChutzpahTracer.TraceInformation(
                        "Added code coverage dependency '{0}' to referenced files",
                        sourcePath);
                    referencedFiles.Add(
                        new ReferencedFile
                    {
                        IsLocal = true,
                        IsCodeCoverageDependency = true,
                        Path = sourcePath,
                        IncludeInTestHarness = true
                    });
                }
            }
            return(coverageEngine);
        }
        private void FireErrorOutput(TestContext testContext, ITestMethodRunnerCallback callback, StreamingTestFileContext testFileContext, JsRunnerOutput jsRunnerOutput)
        {
            var error = jsRunnerOutput as JsError;

            error.Error.InputTestFile = testFileContext.ReferencedFile.Path;
            error.Error.PathFromTestSettingsDirectory = testFileContext.ReferencedFile.PathFromTestSettingsDirectory;
            callback.FileError(testContext, error.Error);
            testFileContext.TestFileSummary.Errors.Add(error.Error);

            if (testFileContext.TestContext.TestFileSettings.CreateFailedTestForFileError.GetValueOrDefault())
            {
                var fileErrorTest = new TestCase();
                fileErrorTest.InputTestFile = testFileContext.ReferencedFile.Path;
                fileErrorTest.PathFromTestSettingsDirectory = testFileContext.ReferencedFile.PathFromTestSettingsDirectory;
                fileErrorTest.TestName = string.Format("!! File Error #{0} - Error encountered outside of test case execution !!", testFileContext.TestFileSummary.Errors.Count);
                fileErrorTest.TestResults.Add(new TestResult {
                    Passed = false, StackTrace = error.Error.StackAsString ?? error.Error.FormatStackObject(), Message = error.Error.Message
                });
                callback.TestStarted(testContext, fileErrorTest);
                callback.TestFinished(testContext, fileErrorTest);

                testFileContext.TestFileSummary.AddTestCase(fileErrorTest);
            }

            ChutzpahTracer.TraceError("Error received from Phantom {0}", error.Error.Message);
        }
Пример #4
0
        public bool RunExecutableAndProcessOutput(string exePath, string arguments, IDictionary <string, string> environmentVars, out string standardOutput, out string standardError)
        {
            Process p = InvokeProcess(exePath, arguments, environmentVars);

            ChutzpahTracer.TraceInformation("Started executable: {0} with PID: {1} using args: {2}", exePath, p.Id, arguments);


            p.WaitForExit(120 * 1000);


            standardOutput = null;
            StringBuilder output = new StringBuilder();

            while (!p.StandardOutput.EndOfStream)
            {
                string line = p.StandardOutput.ReadLine();
                output.AppendLine(line);
            }
            standardOutput = output.ToString();

            standardError = null;
            StringBuilder error = new StringBuilder();

            while (!p.StandardError.EndOfStream)
            {
                string line = p.StandardError.ReadLine();
                error.AppendLine(line);
            }
            standardError = error.ToString();

            ChutzpahTracer.TraceInformation("Ended executable: {0} with PID: {1} using args: {2}", exePath, p.Id, arguments);

            return(p.ExitCode == 0);
        }
Пример #5
0
        private void ResolveAMDBaseUrl(ChutzpahTestSettingsFile settings, IDictionary <string, string> chutzpahVariables)
        {
            if (!string.IsNullOrEmpty(settings.AMDBasePath))
            {
                string absoluteFilePath = ResolveFolderPath(settings, ExpandVariable(chutzpahVariables, settings.AMDBasePath));
                settings.AMDBasePath = absoluteFilePath;

                if (string.IsNullOrEmpty(settings.AMDBasePath))
                {
                    ChutzpahTracer.TraceWarning("Unable to find AMDBasePath at {0}", settings.AMDBasePath);
                }
            }


            if (!string.IsNullOrEmpty(settings.AMDBaseUrlOverride))
            {
                string absoluteFilePath = ResolveFolderPath(settings, ExpandVariable(chutzpahVariables, settings.AMDBaseUrlOverride));
                settings.AMDBaseUrlOverride = absoluteFilePath;

                if (string.IsNullOrEmpty(settings.AMDBaseUrlOverride))
                {
                    ChutzpahTracer.TraceWarning("Unable to find AMDBaseUrlOverride at {0}", settings.AMDBaseUrlOverride);
                }
            }
        }
Пример #6
0
        private static void PlayDeferredEvents(StreamingTestFileContext currentTestFileContext, IList <Action <StreamingTestFileContext> > deferredEvents)
        {
            try
            {
                if (currentTestFileContext == null)
                {
                    return;
                }

                // Since we found a unique match we need to reply and log the events that came before this
                // using this file context

                // We lock here since in the event of a timeout this may be run from the timeout handler while the phantom
                // process is still running
                lock (deferredEvents)
                {
                    foreach (var deferredEvent in deferredEvents)
                    {
                        deferredEvent(currentTestFileContext);
                    }
                }
            }
            catch (Exception e)
            {
                ChutzpahTracer.TraceError(e, "Unable to play deferred events");
            }
        }
Пример #7
0
        private IEnumerable <PathInfo> FindTestFiles(IEnumerable <string> testPaths, TestOptions options)
        {
            IEnumerable <PathInfo> scriptPaths = Enumerable.Empty <PathInfo>();

            // If the path list contains only chutzpah.json files then use those files for getting the list of test paths
            var testPathList = testPaths.Distinct(StringComparer.OrdinalIgnoreCase).ToList();

            if (testPathList.All(testPath => Path.GetFileName(testPath).Equals(Constants.SettingsFileName, StringComparison.OrdinalIgnoreCase)))
            {
                ChutzpahTracer.TraceInformation("Using Chutzpah.json files to find tests");
                foreach (var path in testPathList)
                {
                    var chutzpahJsonPath = fileProbe.FindFilePath(path);
                    if (chutzpahJsonPath == null)
                    {
                        ChutzpahTracer.TraceWarning("Supplied chutzpah.json path {0} does not exist", path);
                    }

                    var settingsFile = testSettingsService.FindSettingsFile(chutzpahJsonPath, options.ChutzpahSettingsFileEnvironments);
                    var pathInfos    = fileProbe.FindScriptFiles(settingsFile);
                    scriptPaths = scriptPaths.Concat(pathInfos);
                }
            }
            else
            {
                scriptPaths = fileProbe.FindScriptFiles(testPathList);
            }
            return(scriptPaths
                   .Where(x => x.FullPath != null)
                   .ToList());;
        }
Пример #8
0
        public ProcessResult <T> RunExecutableAndProcessOutput <T>(string exePath, string arguments, Func <ProcessStream, T> streamProcessor) where T : class
        {
            var p = new Process();

            p.StartInfo.UseShellExecute        = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.CreateNoWindow         = true;
            p.StartInfo.FileName  = exePath;
            p.StartInfo.Arguments = arguments;
            p.StartInfo.StandardOutputEncoding = Encoding.UTF8;
            p.Start();

            ChutzpahTracer.TraceInformation("Started headless browser: {0} with PID: {1} using args: {2}", exePath, p.Id, arguments);

            // Output will be null if the stream reading times out
            var processStream = new ProcessStream(new ProcessWrapper(p), p.StandardOutput);
            var output        = streamProcessor(processStream);

            p.WaitForExit(5000);



            ChutzpahTracer.TraceInformation("Ended headless browser: {0} with PID: {1} using args: {2}", exePath, p.Id, arguments);

            return(new ProcessResult <T>(processStream.TimedOut ? (int)TestProcessExitCode.Timeout : p.ExitCode, output));
        }
Пример #9
0
        private void BuildTestContexts(
            TestOptions options,
            IEnumerable <PathInfo> scriptPaths,
            ParallelOptions parallelOptions,
            CancellationTokenSource cancellationSource,
            int resultCount,
            ConcurrentBag <TestContext> testContexts,
            ITestMethodRunnerCallback callback,
            TestCaseSummary overallSummary)
        {
            Parallel.ForEach(scriptPaths, parallelOptions, testFile =>
            {
                ChutzpahTracer.TraceInformation("Building test context for {0}", testFile.FullPath);

                try
                {
                    if (cancellationSource.IsCancellationRequested)
                    {
                        return;
                    }
                    TestContext testContext;

                    resultCount++;
                    if (testContextBuilder.TryBuildContext(testFile, options, out testContext))
                    {
                        testContexts.Add(testContext);
                    }
                    else
                    {
                        ChutzpahTracer.TraceWarning("Unable to build test context for {0}", testFile.FullPath);
                    }

                    // Limit the number of files we can scan to attempt to build a context for
                    // This is important in the case of folder scanning where many JS files may not be
                    // test files.
                    if (resultCount >= options.FileSearchLimit)
                    {
                        ChutzpahTracer.TraceError("File search limit hit!!!");
                        cancellationSource.Cancel();
                    }
                }
                catch (Exception e)
                {
                    var error = new TestError
                    {
                        InputTestFile = testFile.FullPath,
                        Message       = e.ToString()
                    };

                    overallSummary.Errors.Add(error);
                    callback.FileError(error);

                    ChutzpahTracer.TraceError(e, "Error during building test context for {0}", testFile.FullPath);
                }
                finally
                {
                    ChutzpahTracer.TraceInformation("Finished building test context for {0}", testFile.FullPath);
                }
            });
        }
Пример #10
0
        private IEnumerable <PathInfo> FindTestFiles(IEnumerable <string> testPaths, TestOptions options)
        {
            IEnumerable <PathInfo> scriptPaths = Enumerable.Empty <PathInfo>();

            // If the path list contains only chutzpah.json files then use those files for getting the list of test paths
            var testPathList = testPaths.ToList();

            if (testPathList.All(testPath => Path.GetFileName(testPath).Equals(Constants.SettingsFileName, StringComparison.OrdinalIgnoreCase)))
            {
                ChutzpahTracer.TraceInformation("Using Chutzpah.json files to find tests");
                foreach (var path in testPathList)
                {
                    var chutzpahJsonPath = fileProbe.FindFilePath(path);
                    if (chutzpahJsonPath == null)
                    {
                        ChutzpahTracer.TraceWarning("Supplied chutzpah.json path {0} does not exist", path);
                    }

                    // The FindSettingsFile api takes the directory of the file since it caches this for use in later test runs
                    // this could be cleaned up to have two APIS one which lets you give the direct file
                    var settingsFile = testSettingsService.FindSettingsFile(Path.GetDirectoryName(chutzpahJsonPath));
                    var pathInfos    = fileProbe.FindScriptFiles(settingsFile);
                    scriptPaths = scriptPaths.Concat(pathInfos);
                }
            }
            else
            {
                scriptPaths = fileProbe.FindScriptFiles(testPathList, options.TestingMode);
            }
            return(scriptPaths);
        }
Пример #11
0
        private string GetTestHarnessTemplatePath(IFrameworkDefinition definition, ChutzpahTestSettingsFile chutzpahTestSettings)
        {
            string templatePath = null;

            if (!string.IsNullOrEmpty(chutzpahTestSettings.CustomTestHarnessPath))
            {
                // If CustomTestHarnessPath is absolute path then Path.Combine just returns it
                var harnessPath = Path.Combine(chutzpahTestSettings.SettingsFileDirectory, chutzpahTestSettings.CustomTestHarnessPath);
                var fullPath    = fileProbe.FindFilePath(harnessPath);
                if (fullPath != null)
                {
                    ChutzpahTracer.TraceInformation("Using Custom Test Harness from {0}", fullPath);
                    templatePath = fullPath;
                }
                else
                {
                    ChutzpahTracer.TraceError("Cannot find Custom Test Harness at {0}", chutzpahTestSettings.CustomTestHarnessPath);
                }
            }

            if (templatePath == null)
            {
                templatePath = fileProbe.GetPathInfo(Path.Combine(Constants.TestFileFolder, definition.GetTestHarness(chutzpahTestSettings))).FullPath;

                ChutzpahTracer.TraceInformation("Using builtin Test Harness from {0}", templatePath);
            }
            return(templatePath);
        }
Пример #12
0
        private void ProcessServerSettings(ChutzpahTestSettingsFile settings, IDictionary <string, string> chutzpahVariables)
        {
            if (settings.Engine.GetValueOrDefault() != Engine.Phantom)
            {
                if (settings.Server == null)
                {
                    settings.Server = new ForcedChutzpahWebServerConfiguration();
                }
                else
                {
                    settings.Server.Enabled = true;
                }
            }

            if (settings.Server != null)
            {
                settings.Server.FileCachingEnabled = settings.Server.FileCachingEnabled ?? true;

                settings.Server.DefaultPort = settings.Server.DefaultPort ?? Constants.DefaultWebServerPort;

                string rootPath = null;
                if (!string.IsNullOrEmpty(settings.Server.RootPath))
                {
                    rootPath = settings.Server.RootPath;
                }
                else
                {
                    ChutzpahTracer.TraceInformation("Defaulting the RootPath to the drive root of the chutzpah.json file");
                    rootPath = Path.GetPathRoot(settings.SettingsFileDirectory);
                }

                settings.Server.RootPath = ResolveFolderPath(settings, ExpandVariable(chutzpahVariables, rootPath));
            }
        }
Пример #13
0
        private static void HandleTestProcessExitCode(int exitCode, string inputTestFile, IList <TestError> errors, ITestMethodRunnerCallback callback)
        {
            string errorMessage = null;

            switch ((TestProcessExitCode)exitCode)
            {
            case TestProcessExitCode.AllPassed:
            case TestProcessExitCode.SomeFailed:
                return;

            case TestProcessExitCode.Timeout:
                errorMessage = "Timeout occurred when executing test file";
                break;

            default:
                errorMessage = "Unknown error occurred when executing test file. Received exit code of " + exitCode;
                break;
            }

            if (!string.IsNullOrEmpty(errorMessage))
            {
                var error = new TestError
                {
                    InputTestFile = inputTestFile,
                    Message       = errorMessage
                };

                errors.Add(error);

                callback.FileError(error);
                ChutzpahTracer.TraceError("Headless browser returned with an error: {0}", errorMessage);
            }
        }
Пример #14
0
        private ChutzpahTestSettingsFile FindSettingsFile(string directory, ChutzpahSettingsFileEnvironment environment)
        {
            if (string.IsNullOrEmpty(directory))
            {
                return(ChutzpahTestSettingsFile.Default);
            }

            directory = directory.TrimEnd('/', '\\');

            ChutzpahTestSettingsFile settings;

            if (!ChutzpahSettingsFileCache.TryGetValue(directory, out settings))
            {
                var testSettingsFilePath = fileProbe.FindTestSettingsFile(directory);
                if (string.IsNullOrEmpty(testSettingsFilePath))
                {
                    ChutzpahTracer.TraceInformation("Chutzpah.json file not found given starting directoy {0}", directory);
                    settings = ChutzpahTestSettingsFile.Default;
                }
                else if (!ChutzpahSettingsFileCache.TryGetValue(Path.GetDirectoryName(testSettingsFilePath), out settings))
                {
                    ChutzpahTracer.TraceInformation("Chutzpah.json file found at {0} given starting directoy {1}", testSettingsFilePath, directory);
                    settings = serializer.DeserializeFromFile <ChutzpahTestSettingsFile>(testSettingsFilePath);

                    if (settings == null)
                    {
                        settings = ChutzpahTestSettingsFile.Default;
                    }
                    else
                    {
                        settings.IsDefaultSettings = false;
                    }

                    settings.SettingsFileDirectory = Path.GetDirectoryName(testSettingsFilePath);

                    var chutzpahVariables = BuildChutzpahReplacementVariables(testSettingsFilePath, environment, settings);

                    ResolveTestHarnessDirectory(settings, chutzpahVariables);

                    ResolveAMDBaseUrl(settings, chutzpahVariables);

                    ResolveBatchCompileConfiguration(settings, chutzpahVariables);

                    ProcessPathSettings(settings, chutzpahVariables);

                    ProcessInheritance(environment, settings, chutzpahVariables);

                    // Add a mapping in the cache for the directory that contains the test settings file
                    ChutzpahSettingsFileCache.TryAdd(settings.SettingsFileDirectory, settings);
                }

                // Add mapping in the cache for the original directory tried to skip needing to traverse the tree again
                ChutzpahSettingsFileCache.TryAdd(directory, settings);
            }



            return(settings);
        }
Пример #15
0
        public IList <TestFileSummary> Read(ProcessStream processStream, TestOptions testOptions, TestContext testContext, ITestMethodRunnerCallback callback, bool debugEnabled)
        {
            if (processStream == null)
            {
                throw new ArgumentNullException("processStream");
            }
            if (testOptions == null)
            {
                throw new ArgumentNullException("testOptions");
            }
            if (testContext == null)
            {
                throw new ArgumentNullException("testContext");
            }

            lastTestEvent = DateTime.Now;
            var timeout = (testContext.TestFileSettings.TestFileTimeout ?? testOptions.TestFileTimeoutMilliseconds) + 500; // Add buffer to timeout to account for serialization

            var codeCoverageEnabled = (!testContext.TestFileSettings.EnableCodeCoverage.HasValue && testOptions.CoverageOptions.Enabled) ||
                                      (testContext.TestFileSettings.EnableCodeCoverage.HasValue && testContext.TestFileSettings.EnableCodeCoverage.Value);

            var streamingTestFileContexts = testContext.ReferencedFiles
                                            .Where(x => x.IsFileUnderTest)
                                            .Select(x => new StreamingTestFileContext(x, testContext, codeCoverageEnabled))
                                            .ToList();

            var deferredEvents = new List <Action <StreamingTestFileContext> >();

            var readerTask = Task <IList <TestFileSummary> > .Factory.StartNew(() => ReadFromStream(processStream.StreamReader, testContext, testOptions, streamingTestFileContexts, deferredEvents, callback, debugEnabled));

            while (readerTask.Status == TaskStatus.WaitingToRun ||
                   (readerTask.Status == TaskStatus.Running && (DateTime.Now - lastTestEvent).TotalMilliseconds < timeout))
            {
                Thread.Sleep(100);
            }

            if (readerTask.IsCompleted)
            {
                ChutzpahTracer.TraceInformation("Finished reading stream from test file '{0}'", testContext.FirstInputTestFile);
                return(readerTask.Result);
            }
            else
            {
                // Since we times out make sure we play the deferred events so we do not lose errors
                // We will just attach these events to the first test context at this point since we do
                // not know where they belong
                PlayDeferredEvents(streamingTestFileContexts.FirstOrDefault(), deferredEvents);

                // We timed out so kill the process and return an empty test file summary
                ChutzpahTracer.TraceError("Test file '{0}' timed out after running for {1} milliseconds", testContext.FirstInputTestFile, (DateTime.Now - lastTestEvent).TotalMilliseconds);

                processStream.TimedOut = true;
                processStream.KillProcess();
                return(testContext.ReferencedFiles.Where(x => x.IsFileUnderTest).Select(file => new TestFileSummary(file.Path)).ToList());
            }
        }
Пример #16
0
        private void FireErrorOutput(ITestMethodRunnerCallback callback, TestFileContext testFileContext, JsRunnerOutput jsRunnerOutput)
        {
            var error = jsRunnerOutput as JsError;

            error.Error.InputTestFile = testFileContext.ReferencedFile.Path;
            callback.FileError(error.Error);
            testFileContext.TestFileSummary.Errors.Add(error.Error);

            ChutzpahTracer.TraceError("Eror recieved from Phantom {0}", error.Error.Message);
        }
Пример #17
0
 private void AddTestFrameworkDependencies(IEnumerable <string> deps, List <ReferencedFile> referencedFiles)
 {
     foreach (string item in deps.Reverse())
     {
         string sourcePath = fileProbe.GetPathInfo(Path.Combine(Constants.TestFileFolder, item)).FullPath;
         ChutzpahTracer.TraceInformation("Added framework dependency '{0}' to referenced files", sourcePath);
         referencedFiles.Insert(0, new ReferencedFile {
             IsLocal = true, IsTestFrameworkFile = true, Path = sourcePath, IncludeInTestHarness = true
         });
     }
 }
Пример #18
0
        private void FireTestFinished(ITestMethodRunnerCallback callback, StreamingTestFileContext testFileContext, JsRunnerOutput jsRunnerOutput, int testIndex)
        {
            var jsTestCase = jsRunnerOutput as JsTestCase;

            jsTestCase.TestCase.InputTestFile = testFileContext.ReferencedFile.Path;
            AddLineNumber(testFileContext.ReferencedFile, testIndex, jsTestCase);
            callback.TestFinished(jsTestCase.TestCase);
            testFileContext.TestFileSummary.AddTestCase(jsTestCase.TestCase);

            ChutzpahTracer.TraceInformation("Test Case Finished:'{0}'", jsTestCase.TestCase.GetDisplayName());
        }
Пример #19
0
 private void AddTestFrameworkDependencies(IEnumerable <string> deps, List <ReferencedFile> referencedFiles)
 {
     foreach (string item in deps.Reverse())
     {
         string sourcePath = Path.Combine(fileProbe.BuiltInDependencyDirectory, item);
         ChutzpahTracer.TraceInformation("Added framework dependency '{0}' to referenced files", sourcePath);
         referencedFiles.Insert(0, new ReferencedFile {
             IsLocal = true, IsTestFrameworkFile = true, Path = sourcePath, IncludeInTestHarness = true, IsBuiltInDependency = true
         });
     }
 }
Пример #20
0
        private void ResolveAMDBaseUrl(ChutzpahTestSettingsFile settings)
        {
            if (!string.IsNullOrEmpty(settings.AMDBasePath))
            {
                string absoluteFilePath = ResolveFolderPath(settings, settings.AMDBasePath);
                settings.AMDBasePath = absoluteFilePath;

                if (string.IsNullOrEmpty(settings.AMDBasePath))
                {
                    ChutzpahTracer.TraceWarning("Unable to find AMDBasePath at {0}", settings.AMDBasePath);
                }
            }
        }
Пример #21
0
        public IEnumerable <PathInfo> FindScriptFiles(IEnumerable <string> testPaths, TestingMode testingMode)
        {
            if (testPaths == null)
            {
                yield break;
            }

            foreach (var path in testPaths)
            {
                var pathInfo = GetPathInfo(path);

                switch (pathInfo.Type)
                {
                case PathType.Url:
                    if (testingMode == TestingMode.HTML || testingMode == TestingMode.All)
                    {
                        yield return(pathInfo);
                    }
                    break;

                case PathType.Html:
                case PathType.JavaScript:
                case PathType.CoffeeScript:
                case PathType.TypeScript:
                case PathType.TypeScriptDef:
                    if (!testingMode.FileBelongsToTestingMode(path))
                    {
                        break;
                    }
                    yield return(pathInfo);

                    break;

                case PathType.Folder:
                    var query = from file in fileSystem.GetFiles(pathInfo.FullPath, "*.*", SearchOption.AllDirectories)
                                where file.Length < 260 && !IsTemporaryChutzpahFile(file) && testingMode.FileBelongsToTestingMode(file)
                                select file;
                    foreach (var item in query)
                    {
                        yield return(GetPathInfo(item));
                    }

                    break;

                default:
                    ChutzpahTracer.TraceWarning("Ignoring unsupported test path '{0}'", path);
                    break;
                }
            }
        }
Пример #22
0
 private void ProcessProxy(ChutzpahTestSettingsFile settings, IDictionary <string, string> chutzpahVariables)
 {
     if (!string.IsNullOrEmpty(settings.Proxy))
     {
         if (!ValidationHelper.IsValidProxySetting(settings.Proxy))
         {
             settings.Proxy = string.Empty;
             ChutzpahTracer.TraceInformation("invalid proxy, must be in format of address:port");
         }
         else
         {
             ChutzpahTracer.TraceInformation(string.Format("Proxy setting:{0}", settings.Proxy));
         }
     }
 }
Пример #23
0
        /// <summary>
        /// If the reference path is rooted (e.g. /some/path) and the user chose to adjust it then change it
        /// </summary>
        /// <returns></returns>
        private static string AdjustPathIfRooted(ChutzpahTestSettingsFile chutzpahTestSettings, string referencePath)
        {
            if (chutzpahTestSettings.RootReferencePathMode == RootReferencePathMode.SettingsFileDirectory &&
                (referencePath.StartsWith("/") || referencePath.StartsWith("\\")))
            {
                ChutzpahTracer.TraceInformation(
                    "Changing reference '{0}' to be rooted from settings directory '{1}'",
                    referencePath,
                    chutzpahTestSettings.SettingsFileDirectory);

                referencePath = chutzpahTestSettings.SettingsFileDirectory + referencePath;
            }

            return(referencePath);
        }
Пример #24
0
        private void FireLogOutput(ITestMethodRunnerCallback callback, TestFileContext testFileContext, JsRunnerOutput jsRunnerOutput)
        {
            var log = jsRunnerOutput as JsLog;

            // This is an internal log message
            if (log.Log.Message.StartsWith(internalLogPrefix))
            {
                ChutzpahTracer.TraceInformation("Phantom Log - {0}", log.Log.Message.Substring(internalLogPrefix.Length).Trim());
                return;
            }

            log.Log.InputTestFile = testFileContext.ReferencedFile.Path;
            callback.FileLog(log.Log);
            testFileContext.TestFileSummary.Logs.Add(log.Log);
        }
Пример #25
0
        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);
            }
        }
Пример #26
0
        private IList <ReferencedFile> GetReferencedFiles(
            HashSet <string> discoveredPaths,
            IFrameworkDefinition definition,
            string textToParse,
            string currentFilePath,
            ChutzpahTestSettingsFile chutzpahTestSettings)
        {
            var referencedFiles = new List <ReferencedFile>();

            Regex regex = RegexPatterns.JsReferencePathRegex;

            foreach (Match match in regex.Matches(textToParse))
            {
                if (!ShouldIncludeReference(match))
                {
                    continue;
                }

                string referencePath = match.Groups["Path"].Value;

                ProcessFilePathAsReference(
                    discoveredPaths,
                    definition,
                    currentFilePath,
                    chutzpahTestSettings,
                    referencePath,
                    referencedFiles,
                    new ReferencePathSettings());
            }

            foreach (Match match in RegexPatterns.JsTemplatePathRegex.Matches(textToParse))
            {
                string referencePath = match.Groups["Path"].Value;

                referencePath = AdjustPathIfRooted(chutzpahTestSettings, referencePath);
                string relativeReferencePath = Path.Combine(Path.GetDirectoryName(currentFilePath), referencePath);
                string absoluteFilePath      = fileProbe.FindFilePath(relativeReferencePath);
                if (referencedFiles.All(r => r.Path != absoluteFilePath))
                {
                    ChutzpahTracer.TraceInformation("Added html template '{0}' to referenced files", absoluteFilePath);
                    referencedFiles.Add(new ReferencedFile {
                        Path = absoluteFilePath, IsLocal = false, IncludeInTestHarness = true
                    });
                }
            }

            return(referencedFiles);
        }
Пример #27
0
        public virtual void TestFinished(TestCase testCase)
        {
            if (testCase.Passed)
            {
                ChutzpahTracer.TraceInformation("File {0}, Test {1} passed", testCase.InputTestFile, testCase.TestName);
                TestPassed(testCase);
            }

            if (!testCase.Passed)
            {
                ChutzpahTracer.TraceInformation("File {0}, Test {1} failed", testCase.InputTestFile, testCase.TestName);
                TestFailed(testCase);
            }

            TestComplete(testCase);
        }
Пример #28
0
        /// <summary>
        /// Iterates over filegenerators letting the generators decide if they handle any files
        /// </summary>
        private void ProcessForFilesGeneration(List <ReferencedFile> referencedFiles, List <string> temporaryFiles, ChutzpahTestSettingsFile chutzpahTestSettings)
        {
            if (chutzpahTestSettings.Compile != null)
            {
                ChutzpahTracer.TraceInformation("Ignoring old style file compilation since we detected the new compile setting");
                return;
            }
            ChutzpahTracer.TraceInformation("Starting legacy file compilation/generation");

            foreach (var fileGenerator in fileGenerators)
            {
                fileGenerator.Generate(referencedFiles, temporaryFiles, chutzpahTestSettings);
            }

            ChutzpahTracer.TraceInformation("Finished legacy file compilation/generation");
        }
Пример #29
0
        private bool PerformBatchCompile(ITestMethodRunnerCallback callback, IEnumerable <TestContext> testContexts)
        {
            try
            {
                batchCompilerService.Compile(testContexts);
            }
            catch (ChutzpahCompilationFailedException e)
            {
                callback.ExceptionThrown(e, e.SettingsFile);

                ChutzpahTracer.TraceError(e, "Error during batch compile from {0}", e.SettingsFile);
                return(false);
            }

            return(true);
        }
Пример #30
0
        private void ConfigureTracing(TestRunConfiguration testRunConfiguration)
        {
            var path = testRunConfiguration.TraceFilePath;

            if (testRunConfiguration.EnableTracing)
            {
                ChutzpahTracer.AddFileListener(path);
            }
            else
            {
                // TODO (mmanela): There is a known issue with this if the user is running chutzpah in VS and changes their trace path
                // This will result in that path not getting removed until the VS is restarted. To fix this we need to keep trace of previous paths
                // and clear them all out.
                ChutzpahTracer.RemoveFileListener(path);
            }
        }