示例#1
0
        private bool SetupEnvironment(string source)
        {
            var cacheDir = TestContainerHelper.FindCMakeCacheDirectory(source);

            this._config = CTestAdapterConfig.ReadFromDisk(Path.Combine(cacheDir, Constants.CTestAdapterConfigFileName)) ??
                           CTestAdapterConfig.ReadFromCache(cacheDir);
            if (this._config == null)
            {
                this.Log(TestMessageLevel.Error, "could not initialize environment");
                return(false);
            }
            return(true);
        }
示例#2
0
        public void DiscoverTests(IEnumerable <string> sources,
                                  IDiscoveryContext discoveryContext,
                                  IMessageLogger logger,
                                  ITestCaseDiscoverySink discoverySink)
        {
            this._log = logger;
            this.Log(TestMessageLevel.Informational, "discovering ...");
            var v = sources as IList <string> ?? sources.ToList();
            // verify we have a CMakeCache.txt directory
            var cacheDir = TestContainerHelper.FindCMakeCacheDirectory(v.First());

            if (!cacheDir.Any())
            {
                this.Log(TestMessageLevel.Informational, "cmake cache not found");
                return;
            }
            // read parameters
            var cfg = CTestAdapterConfig.ReadFromDisk(Path.Combine(cacheDir, Constants.CTestAdapterConfigFileName)) ??
                      CTestAdapterConfig.ReadFromCache(cacheDir);

            if (null == cfg)
            {
                this.Log(TestMessageLevel.Error, "could not create CTestAdapterConfig");
                return;
            }
            // make sure a configuration is set
            if (!cfg.ActiveConfiguration.Any())
            {
                if (cfg.TrySetActiveConfigFromConfigTypes())
                {
                    this.Log(TestMessageLevel.Warning,
                             "Configuration fallback to: " + cfg.ActiveConfiguration);
                }
                else
                {
                    this.Log(TestMessageLevel.Error, "could not set Configuration");
                    return;
                }
            }
            this.Log(TestMessageLevel.Informational, "using configuration: " + cfg.ActiveConfiguration);
            // make sure we have a ctest executable
            if (!File.Exists(cfg.CTestExecutable))
            {
                cfg.CTestExecutable = TestContainerHelper.FindCTestExe(cfg.CacheDir);
            }
            if (!File.Exists(cfg.CTestExecutable))
            {
                this.Log(TestMessageLevel.Error,
                         "ctest not found, tried: \"" + cfg.CTestExecutable + "\"");
                return;
            }
            this.Log(TestMessageLevel.Informational, "using ctest binary: " + cfg.CTestExecutable);
            // collect all existing tests by executing ctest
            var collection = TestContainerHelper.FindAllTestsWithCtest(cfg);

            foreach (var source in v)
            {
                var cases = TestContainerHelper.ParseTestContainerFile(source, this._log, collection, cfg.ActiveConfiguration);
                foreach (var c in cases)
                {
                    discoverySink.SendTestCase(c.Value);
                }
            }
            this.Log(TestMessageLevel.Informational, "discovering done");
        }