Exemplo n.º 1
0
        public static Container FindConfiguration(FileInfo testContainer)
        {
            Ensure.That(() => testContainer).IsNotNull();

            DirectoryInfo directory = testContainer.Directory;

            do
            {
                string[] extensions = { "*.plow.user", "*.plow" };
                foreach (string extension in extensions)
                {
                    foreach (FileInfo plowFile in directory.EnumerateFiles(extension))
                    {
                        PlowConfiguration config = Load(plowFile);
                        if (config.HasConfigurationFor(testContainer.Name))
                        {
                            return(config.ConfigurationFor(testContainer.Name));
                        }
                    }
                }
                directory = directory.Parent;
            }while (directory != null);
            return(null);
        }
Exemplo n.º 2
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));
                }
            }
        }
Exemplo n.º 3
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);
        }