Exemplo n.º 1
0
        private IEnumerable <TestCaseLocation> FindTestCaseLocationsInBinary(
            string binary, List <string> testMethodSignatures, string symbolFilterString, string pathExtension)
        {
            using (IDiaResolver diaResolver = _diaResolverFactory.Create(binary, pathExtension, _testEnvironment, _testEnvironment.Options.DebugMode))
            {
                try
                {
                    IList <SourceFileLocation> allTestMethodSymbols = diaResolver.GetFunctions(symbolFilterString);
                    IList <SourceFileLocation> allTraitSymbols      = diaResolver.GetFunctions("*" + TraitAppendix);
                    _testEnvironment.DebugInfo($"Found {allTestMethodSymbols.Count} test method symbols and {allTraitSymbols.Count} trait symbols in binary {binary}");

                    return(allTestMethodSymbols
                           .Where(nsfl => testMethodSignatures.Any(tms => Regex.IsMatch(nsfl.Symbol, tms))) // Contains() instead of == because nsfl might contain namespace
                           .Select(nsfl => ToTestCaseLocation(nsfl, allTraitSymbols))
                           .ToList());                                                                      // we need to force immediate query execution, otherwise our session object will already be released
                }
                catch (Exception e)
                {
                    if (_testEnvironment.Options.DebugMode)
                    {
                        _testEnvironment.LogError($"Exception while resolving test locations and traits in {binary}\n{e}");
                    }
                    return(new TestCaseLocation[0]);
                }
            }
        }
        public void GetFunctions_ExeWithoutPdb_ErrorIsLogged()
        {
            string executable = TestResources.LoadTests_ReleaseX86;

            executable.AsFileInfo().Should().Exist();
            string pdb = Path.ChangeExtension(executable, ".pdb");

            pdb.AsFileInfo().Should().Exist();
            string renamedPdb = $"{pdb}.bak";

            renamedPdb.AsFileInfo().Should().NotExist();

            var locations  = new List <SourceFileLocation>();
            var fakeLogger = new FakeLogger(() => OutputMode.Verbose);

            try
            {
                File.Move(pdb, renamedPdb);
                pdb.AsFileInfo().Should().NotExist();

                using (IDiaResolver resolver = DefaultDiaResolverFactory.Instance.Create(executable, pdb, fakeLogger))
                {
                    locations.AddRange(resolver.GetFunctions("*"));
                }
            }
            finally
            {
                File.Move(renamedPdb, pdb);
                pdb.AsFileInfo().Should().Exist();
            }

            locations.Should().BeEmpty();
            fakeLogger.Errors.Should().Contain(msg => msg.Contains("PDB file") && msg.Contains("does not exist"));
        }
Exemplo n.º 3
0
        private void AddSymbolsFromBinary(string binary)
        {
            using (IDiaResolver diaResolver = _diaResolverFactory.Create(binary, _pathExtension, _logger))
            {
                try
                {
                    _allTestMethodSymbols.AddRange(diaResolver.GetFunctions("*" + GoogleTestConstants.TestBodySignature));
                    _allTraitSymbols.AddRange(diaResolver.GetFunctions("*" + TraitAppendix));

                    _logger.DebugInfo($"Found {_allTestMethodSymbols.Count} test method symbols and {_allTraitSymbols.Count} trait symbols in binary {binary}");
                }
                catch (Exception e)
                {
                    _logger.DebugError($"Exception while resolving test locations and traits in {binary}\n{e}");
                }
            }
        }
        private void AddSymbolsFromBinary(string binary)
        {
            using (IDiaResolver diaResolver = _diaResolverFactory.Create(binary, _pathExtension, _logger))
            {
                try
                {
                    _allTestMethodSymbols.AddRange(diaResolver.GetFunctions("*" + GoogleTestConstants.TestBodySignature));
                    _allTraitSymbols.AddRange(diaResolver.GetFunctions("*" + TraitAppendix));

                    _logger.DebugInfo(String.Format(Resources.FoundTestMethod, _allTestMethodSymbols.Count, _allTraitSymbols.Count, binary));
                }
                catch (Exception e)
                {
                    _logger.DebugError(String.Format(Resources.ExceptionResolving, binary, e));
                }
            }
        }
        private void AddSymbolsFromBinary(string binary, string pdb, bool resolveMainMethod = false)
        {
            using (IDiaResolver diaResolver = _diaResolverFactory.Create(binary, pdb, _logger))
            {
                try
                {
                    _allTestMethodSymbols.AddRange(diaResolver.GetFunctions("*" + GoogleTestConstants.TestBodySignature));
                    _allTraitSymbols.AddRange(diaResolver.GetFunctions("*" + TraitAppendix));
                    _logger.DebugInfo($"Found {_allTestMethodSymbols.Count} test method symbols and {_allTraitSymbols.Count} trait symbols in binary {binary}, pdb {pdb}");

                    if (resolveMainMethod)
                    {
                        MainMethodLocation = ResolveMainMethod(diaResolver);
                    }
                }
                catch (Exception e)
                {
                    _logger.DebugError($"Exception while resolving test locations and traits in '{binary}':{Environment.NewLine}{e}");
                }
            }
        }
Exemplo n.º 6
0
        private void AddSymbolsFromBinary(string binary, string pdb, bool resolveMainMethod = false)
        {
            using (IDiaResolver diaResolver = _diaResolverFactory.Create(binary, pdb, _logger))
            {
                try
                {
                    _allTestMethodSymbols.AddRange(diaResolver.GetFunctions("*" + GoogleTestConstants.TestBodySignature));
                    _allTraitSymbols.AddRange(diaResolver.GetFunctions("*" + TraitAppendix));
                    _logger.DebugInfo(String.Format(Resources.FoundTestMethod, _allTestMethodSymbols.Count, _allTraitSymbols.Count, binary, pdb));

                    if (resolveMainMethod)
                    {
                        MainMethodLocation = ResolveMainMethod(diaResolver);
                    }
                }
                catch (Exception e)
                {
                    _logger.DebugError(String.Format(Resources.ExceptionResolving, binary, e));
                }
            }
        }
        private Dictionary <string, TestCaseLocation> FindTestCaseLocationsInBinary(
            string binary, HashSet <string> testMethodSignatures, string symbolFilterString, string pathExtension)
        {
            using (IDiaResolver diaResolver = _diaResolverFactory.Create(binary, pathExtension, _logger))
            {
                try
                {
                    IList <SourceFileLocation> allTestMethodSymbols = diaResolver.GetFunctions(symbolFilterString);
                    IList <SourceFileLocation> allTraitSymbols      = diaResolver.GetFunctions("*" + TraitAppendix);
                    _logger.DebugInfo($"Found {allTestMethodSymbols.Count} test method symbols and {allTraitSymbols.Count} trait symbols in binary {binary}");

                    return(allTestMethodSymbols
                           .Where(nsfl => testMethodSignatures.Contains(TestCaseFactory.StripTestSymbolNamespace(nsfl.Symbol)))
                           .Select(nsfl => ToTestCaseLocation(nsfl, allTraitSymbols))
                           .ToDictionary(nsfl => TestCaseFactory.StripTestSymbolNamespace(nsfl.Symbol)));
                }
                catch (Exception e)
                {
                    _logger.DebugError($"Exception while resolving test locations and traits in {binary}\n{e}");
                    return(new Dictionary <string, TestCaseLocation>());
                }
            }
        }
        private void DoResolveTest(string executable, string filter, int expectedLocations, int expectedErrorMessages, bool disposeResolver = true)
        {
            var locations  = new List <SourceFileLocation>();
            var fakeLogger = new FakeLogger();

            IDiaResolver resolver = DefaultDiaResolverFactory.Instance.Create(executable, "", fakeLogger);

            locations.AddRange(resolver.GetFunctions(filter));

            if (disposeResolver)
            {
                resolver.Dispose();
            }

            locations.Count.Should().Be(expectedLocations);
            fakeLogger.MessagesOfType(Severity.Warning, Severity.Error).Count.Should().Be(expectedErrorMessages);
        }
        private void DoResolveTest(string executable, string filter, int expectedLocations, int expectedErrorMessages, bool disposeResolver = true)
        {
            var locations  = new List <SourceFileLocation>();
            var fakeLogger = new FakeLogger(() => OutputMode.Info);

            string       pdb      = PdbLocator.FindPdbFile(executable, "", fakeLogger);
            IDiaResolver resolver = DefaultDiaResolverFactory.Instance.Create(executable, pdb, fakeLogger);

            locations.AddRange(resolver.GetFunctions(filter));

            if (disposeResolver)
            {
                resolver.Dispose();
            }

            locations.Should().HaveCountGreaterOrEqualTo(expectedLocations);
            fakeLogger.GetMessages(Severity.Warning, Severity.Error).Should().HaveCountGreaterOrEqualTo(expectedErrorMessages);
        }
        public void GetFunctions_ExeWithoutPdb_AttemptsToFindPdbAreLogged()
        {
            TestResources.LoadTests_ReleaseX86.AsFileInfo().Should().Exist();
            string pdb = Path.ChangeExtension(TestResources.LoadTests_ReleaseX86, ".pdb");

            pdb.AsFileInfo().Should().Exist();
            string renamedPdb = $"{pdb}.bak";

            renamedPdb.AsFileInfo().Should().NotExist();

            var locations  = new List <SourceFileLocation>();
            var fakeLogger = new FakeLogger(() => true);

            try
            {
                File.Move(pdb, renamedPdb);
                pdb.AsFileInfo().Should().NotExist();

                using (
                    IDiaResolver resolver = DefaultDiaResolverFactory.Instance.Create(TestResources.LoadTests_ReleaseX86, "",
                                                                                      fakeLogger))
                {
                    locations.AddRange(resolver.GetFunctions("*"));
                }
            }
            finally
            {
                File.Move(renamedPdb, pdb);
                pdb.AsFileInfo().Should().Exist();
            }

            locations.Count.Should().Be(0);
            fakeLogger.Warnings
            .Should()
            .Contain(msg => msg.Contains("Couldn't find the .pdb file"));
            fakeLogger.Infos
            .Should()
            .Contain(msg => msg.Contains("Attempts to find PDB"));
        }
Exemplo n.º 11
0
        public void GetFunctions_ExeWithoutPdb_AttemptsToFindPdbAreLogged()
        {
            TestResources.X86TestsWithoutPdb.AsFileInfo().Should().Exist();

            var locations  = new List <SourceFileLocation>();
            var fakeLogger = new FakeLogger(() => true);

            using (
                IDiaResolver resolver = DefaultDiaResolverFactory.Instance.Create(TestResources.X86TestsWithoutPdb, "",
                                                                                  fakeLogger))
            {
                locations.AddRange(resolver.GetFunctions("*"));
            }

            locations.Count.Should().Be(0);
            fakeLogger.Warnings
            .Should()
            .Contain(msg => msg.Contains("Couldn't find the .pdb file"));
            fakeLogger.Infos
            .Should()
            .Contain(msg => msg.Contains("Attempts to find pdb:"));
        }
Exemplo n.º 12
0
        public void GetFunctions_ExeWithoutPdb_AttemptsToFindPdbAreLogged()
        {
            File.Exists(TestResources.X86TestsWithoutPdb).Should().BeTrue();

            var locations  = new List <SourceFileLocation>();
            var fakeLogger = new FakeLogger();

            using (
                IDiaResolver resolver = DefaultDiaResolverFactory.Instance.Create(TestResources.X86TestsWithoutPdb, "",
                                                                                  fakeLogger, true))
            {
                locations.AddRange(resolver.GetFunctions("*"));
            }

            locations.Count.Should().Be(0);
            fakeLogger.MessagesOfType(Severity.Warning)
            .Should()
            .Contain(msg => msg.Contains("Couldn't find the .pdb file"));
            fakeLogger.MessagesOfType(Severity.Info)
            .Should()
            .Contain(msg => msg.Contains("Attempts to find pdb:"));
        }
        private TestCaseLocation ResolveMainMethod(IDiaResolver diaResolver)
        {
            var mainSymbols = new List <SourceFileLocation>();

            mainSymbols.AddRange(diaResolver.GetFunctions("main"));

            if (!string.IsNullOrWhiteSpace(_settings.ExitCodeTestCase))
            {
                if (mainSymbols.Count == 0)
                {
                    _logger.DebugWarning(
                        $"Could not find any main method for executable {_executable} - exit code test will not have source location");
                }
                else if (mainSymbols.Count > 1)
                {
                    _logger.DebugWarning(
                        $"Found more than one potential main method in executable {_executable} - exit code test might have wrong source location");
                }
            }

            var location = mainSymbols.FirstOrDefault();

            return(location != null?ToTestCaseLocation(location) : null);
        }