コード例 #1
0
        void VerifyLoggedMessages(AssemblyDefinition original, LinkerTestLogger logger)
        {
            string allMessages = string.Join(Environment.NewLine, logger.Messages.Select(mc => mc.Message));

            foreach (var typeWithRemoveInAssembly in original.AllDefinedTypes())
            {
                foreach (var attr in typeWithRemoveInAssembly.CustomAttributes)
                {
                    if (attr.AttributeType.Resolve().Name == nameof(LogContainsAttribute))
                    {
                        var expectedMessagePattern = (string)attr.ConstructorArguments [0].Value;
                        Assert.That(
                            logger.Messages.Any(mc => Regex.IsMatch(mc.Message, expectedMessagePattern)),
                            $"Expected to find logged message matching `{expectedMessagePattern}`, but no such message was found.{Environment.NewLine}Logged messages:{Environment.NewLine}{allMessages}");
                    }

                    if (attr.AttributeType.Resolve().Name == nameof(LogDoesNotContainAttribute))
                    {
                        var unexpectedMessagePattern = (string)attr.ConstructorArguments [0].Value;
                        foreach (var loggedMessage in logger.Messages)
                        {
                            Assert.That(
                                !Regex.IsMatch(loggedMessage.Message, unexpectedMessagePattern),
                                $"Expected to not find logged message matching `{unexpectedMessagePattern}`, but found:{Environment.NewLine}{loggedMessage.Message}{Environment.NewLine}Logged messages:{Environment.NewLine}{allMessages}");
                        }
                    }
                }
            }
        }
コード例 #2
0
 public LinkedTestCaseResult(TestCase testCase, NPath inputAssemblyPath, NPath outputAssemblyPath, NPath expectationsAssemblyPath, TestCaseSandbox sandbox, TestCaseMetadaProvider metadaProvider, ManagedCompilationResult compilationResult, LinkerTestLogger logger)
 {
     TestCase                 = testCase;
     InputAssemblyPath        = inputAssemblyPath;
     OutputAssemblyPath       = outputAssemblyPath;
     ExpectationsAssemblyPath = expectationsAssemblyPath;
     Sandbox           = sandbox;
     MetadataProvider  = metadaProvider;
     CompilationResult = compilationResult;
     Logger            = logger;
 }
コード例 #3
0
        private LinkedTestCaseResult Link(TestCase testCase, TestCaseSandbox sandbox, ManagedCompilationResult compilationResult, TestCaseMetadaProvider metadataProvider)
        {
            var linker  = _factory.CreateLinker();
            var builder = _factory.CreateLinkerArgumentBuilder(metadataProvider);

            AddLinkOptions(sandbox, compilationResult, builder, metadataProvider);

            LinkerTestLogger logger = new LinkerTestLogger();

            linker.Link(builder.ToArgs(), logger);

            return(new LinkedTestCaseResult(testCase, compilationResult.InputAssemblyPath, sandbox.OutputDirectory.Combine(compilationResult.InputAssemblyPath.FileName), compilationResult.ExpectationsAssemblyPath, sandbox, metadataProvider, compilationResult, logger));
        }