Exemplo n.º 1
0
        public void RunTests(IEnumerable <string> sources, IRunContext runContext,
                             IFrameworkHandle frameworkHandle)
        {
            this._log = frameworkHandle;
            this.Log(TestMessageLevel.Informational, "running tests (src) ...");
            var sourcesList = sources as IList <string> ?? sources.ToList();

            if (!this.SetupEnvironment(sourcesList.First()))
            {
                return;
            }
            this.Log(TestMessageLevel.Informational, "using configuration: "
                     + this._config.ActiveConfiguration);
            this._runningFromSources = true;
            var logFileDir = this._config.CacheDir + "\\Testing\\Temporary";

            this.Log(TestMessageLevel.Informational,
                     "logs are written to (" + TestContainerHelper.ToLinkPath(logFileDir) + ")");
            foreach (var source in sourcesList)
            {
                var cases = TestContainerHelper.ParseTestContainerFile(
                    source, frameworkHandle, null, this._config.ActiveConfiguration);
                this.RunTests(cases.Values, runContext, frameworkHandle);
            }
            this._runningFromSources = false;
            this.Log(TestMessageLevel.Informational, "running tests (src) done");
        }
Exemplo n.º 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");
        }