Ejemplo n.º 1
0
        public static CTestTestCollection FindAllTestsWithCtest(CTestAdapterConfig cfg)
        {
            if (null == cfg)
            {
                return(null);
            }
            if (!Directory.Exists(cfg.CacheDir))
            {
                return(null);
            }
            if (!File.Exists(cfg.CTestExecutable))
            {
                return(null);
            }
            var collection = new CTestTestCollection();
            var collector  = new CTestTestCollector
            {
                CTestExecutable     = cfg.CTestExecutable,
                CTestWorkingDir     = cfg.CacheDir,
                CurrentActiveConfig = cfg.ActiveConfiguration
            };

            collector.CollectTestCases(collection);
            return(collection);
        }
Ejemplo n.º 2
0
        public void CollectTestCases(CTestTestCollection testCollection)
        {
            testCollection.Tests.Clear();
            if (!File.Exists(this.CTestExecutable))
            {
                return;
            }
            if (!Directory.Exists(this.CTestWorkingDir))
            {
                return;
            }
            var args = this.CTestArguments;

            if (!string.IsNullOrWhiteSpace(this.CurrentActiveConfig))
            {
                args += " -C ";
                args += this.CurrentActiveConfig;
            }
            var proc = new Process
            {
                StartInfo = new ProcessStartInfo()
                {
                    FileName               = this.CTestExecutable,
                    WorkingDirectory       = this.CTestWorkingDir,
                    Arguments              = args,
                    CreateNoWindow         = true,
                    RedirectStandardError  = true,
                    RedirectStandardOutput = true,
                    WindowStyle            = ProcessWindowStyle.Hidden,
                    UseShellExecute        = false
                }
            };

            proc.Start();
            var output = proc.StandardOutput.ReadToEnd();

            proc.Dispose();
            var matches = TestRegex.Matches(output);

            foreach (var match in matches)
            {
                var m = match as Match;
                if (m == null)
                {
                    continue;
                }
                var name      = m.Groups[FieldNameTestname].Value;
                var numberStr = m.Groups[FieldNameNumber].Value;
                int number;
                int.TryParse(numberStr, out number);
                var newinfo = new CTestTestCollection.TestInfo
                {
                    Name   = name,
                    Number = number,
                };
                testCollection.Tests.Add(newinfo);
            }
        }
Ejemplo n.º 3
0
        public static Dictionary <string, TestCase> ParseTestContainerFile(string source, IMessageLogger log,
                                                                           CTestTestCollection collection, string activeConfiguration)
        {
            log.SendMessage(TestMessageLevel.Informational, "Parsing CTest file: " + TestContainerHelper.ToLinkPath(source));
            var cases          = new Dictionary <string, TestCase>();
            var content        = File.ReadLines(source);
            var skipFoundTests = false;
            var lineNumber     = 0;

            foreach (var line in content)
            {
                lineNumber++;
                var ifcheck = TestContainerHelper.IfLevelRegex.Match(line);
                if (ifcheck.Success)
                {
                    var cfgRegexString = ifcheck.Groups[FieldNameCfgRegex].Value;
                    var cfgRegex       = new Regex(cfgRegexString);
                    skipFoundTests = !cfgRegex.IsMatch(activeConfiguration);
                    continue;
                }
                else if (line == "else()")
                {
                    skipFoundTests = true;
                    continue;
                }
                else if (line == "endif()")
                {
                    skipFoundTests = false;
                    continue;
                }
                var test = TestContainerHelper.AddTestRegex.Match(line);
                if (test.Success)
                {
                    var testname = test.Groups[FieldNameTestname].Value;
                    if (skipFoundTests)
                    {
                        //log.SendMessage(TestMessageLevel.Warning,
                        //"skipping test because of Configuration mismatch: line " + lineNumber + ", test " + testname);
                        continue;
                    }
                    if (null != collection)
                    {
                        if (!collection.TestExists(testname))
                        {
                            log.SendMessage(TestMessageLevel.Warning,
                                            "test not listed by ctest -N : " + testname);
                        }
                    }
                    if (cases.ContainsKey(testname))
                    {
                        continue;
                    }
                    var testcase = new TestCase(testname, CTestExecutor.ExecutorUri, source)
                    {
                        CodeFilePath = source,
                        DisplayName  = testname,
                        LineNumber   = lineNumber,
                    };
                    if (null != collection)
                    {
                        if (collection.TestExists(testname))
                        {
                            testcase.DisplayName = collection[testname].Number.ToString().PadLeft(3, '0') + ": " + testname;
                        }
                    }
                    cases.Add(testname, testcase);
                }
            }
            return(cases);
        }