Example #1
0
        private void RunTests(String source, IEnumerable <TestCase> tests, IFrameworkHandle frameworkHandle, IRunContext runContext)
        {
            Logger logger = new Logger(frameworkHandle);

            if (m_cancelled)
            {
                return;
            }

            FileInfo file = new FileInfo(source);

            if (!file.Exists)
            {
                logger.WriteWarning(strings.UnknownFileX, source);
            }

            Container settings = PlowConfiguration.FindConfiguration(file);

            if (settings == null)
            {
                logger.WriteInformation(strings.SkipXNotListed, source);
                return;
            }

            if (!settings.Enable)
            {
                logger.WriteInformation(strings.SkipXDisabled, source);
                return;
            }

            logger.WriteInformation(strings.PlowingInX, source);

            // Start the process, Call WaitForExit and then the using statement will close.
            Process process = new Process(file, settings);

            if (runContext.IsBeingDebugged)
            {
                process.DebugTests(frameworkHandle).WaitForExit();
            }
            else
            {
                using (System.Diagnostics.Process unittestProcess = process.ExecuteTests())
                {
                    string rawContent = unittestProcess.StandardOutput.ReadToEnd();

                    int timeout = 10000;
                    unittestProcess.WaitForExit(timeout);

                    if (!unittestProcess.HasExited)
                    {
                        unittestProcess.Kill();
                        logger.WriteError(strings.TimoutInX, source);
                        return;
                    }

                    if (unittestProcess.ExitCode < 0)
                    {
                        logger.WriteError(strings.XReturnedErrorCodeY, source, unittestProcess.ExitCode);
                        return;
                    }

                    XmlTestResultReader testReader = new XmlTestResultReader(frameworkHandle);
                    testReader.read(tests, XmlWasher.Clean(rawContent));
                }
            }
        }
Example #2
0
        internal static IEnumerable <TestCase> GetTests(IEnumerable <string> sources, Logger logger, ITestCaseDiscoverySink discoverySink)
        {
            Ensure.That(() => logger).IsNotNull();

            logger.WriteInformation(strings.LookingForSnowN, sources.Count());

            XmlTestCaseReader testReader = new XmlTestCaseReader(discoverySink);

            foreach (string source in sources)
            {
                try
                {
                    FileInfo file = new FileInfo(source);
                    if (!file.Exists)
                    {
                        logger.WriteWarning(strings.UnknownFileX, source);
                    }

                    Container settings = PlowConfiguration.FindConfiguration(file);

                    if (settings == null)
                    {
                        logger.WriteWarning(strings.SkipXNotListed, source);
                        continue;
                    }

                    if (!settings.Enable)
                    {
                        logger.WriteWarning(strings.SkipXDisabled, source);
                        continue;
                    }

                    logger.WriteInformation(strings.LookingInX, source);

                    Process process = new Process(file, settings);
                    // Start the process, Call WaitForExit and then the using statement will close.
                    using (System.Diagnostics.Process unittestProcess = process.ListTests())
                    {
                        string rawContent = unittestProcess.StandardOutput.ReadToEnd();

                        int timeout = 10000;
                        unittestProcess.WaitForExit(timeout);

                        if (!unittestProcess.HasExited)
                        {
                            unittestProcess.Kill();
                            logger.WriteError(strings.TimoutInX, source);
                            continue;
                        }

                        if (unittestProcess.ExitCode < 0)
                        {
                            logger.WriteError(strings.XReturnedErrorCodeY, source, unittestProcess.ExitCode);
                            continue;
                        }

                        testReader.Read(source, XmlWasher.Clean(rawContent));
                    }
                }
                catch (Exception exception)
                {
                    // Log exception as error.
                    logger.WriteException(exception);
                }
            }

            logger.WriteInformation(strings.FinishedLooking);

            return(testReader.TestCases);
        }