コード例 #1
0
 internal CompilationVerifier CompileAndVerify(
     string source,
     IEnumerable<MetadataReference> additionalRefs = null,
     IEnumerable<ModuleData> dependencies = null,
     Action<IModuleSymbol> sourceSymbolValidator = null,
     Action<PEAssembly> assemblyValidator = null,
     Action<IModuleSymbol> symbolValidator = null,
     SignatureDescription[] expectedSignatures = null,
     string expectedOutput = null,
     CompilationOptions options = null,
     ParseOptions parseOptions = null,
     bool verify = true)
 {
     return CompileAndVerify(
         sources: new string[] { source },
         additionalRefs: additionalRefs,
         dependencies: dependencies,
         sourceSymbolValidator: sourceSymbolValidator,
         assemblyValidator: assemblyValidator,
         symbolValidator: symbolValidator,
         expectedSignatures: expectedSignatures,
         expectedOutput: expectedOutput,
         options: options,
         parseOptions: parseOptions,
         verify: verify);
 }
コード例 #2
0
        internal CompilationVerifier CompileAndVerify(
            string[] sources,
            IEnumerable<MetadataReference> additionalRefs = null,
            IEnumerable<ModuleData> dependencies = null,
            Action<IModuleSymbol> sourceSymbolValidator = null,
            Action<PEAssembly> assemblyValidator = null,
            Action<IModuleSymbol> symbolValidator = null,
            SignatureDescription[] expectedSignatures = null,
            string expectedOutput = null,
            CompilationOptions options = null,
            ParseOptions parseOptions = null,
            bool verify = true)
        {
            if (options == null)
            {
                options = CompilationOptionsReleaseDll.WithOutputKind((expectedOutput != null) ? OutputKind.ConsoleApplication : OutputKind.DynamicallyLinkedLibrary);
            }

            var compilation = GetCompilationForEmit(sources, additionalRefs, options, parseOptions);

            return this.CompileAndVerify(
                compilation,
                null,
                dependencies,
                sourceSymbolValidator,
                assemblyValidator,
                symbolValidator,
                expectedSignatures,
                expectedOutput,
                verify);
        }
コード例 #3
0
 private CompilationVerifier CompileAndVerifyRef(
     string source,
     string expectedOutput = null,
     MetadataReference[] additionalRefs = null,
     IEnumerable<ModuleData> dependencies = null,
     Action<ModuleSymbol> sourceSymbolValidator = null,
     Action<PEAssembly> assemblyValidator = null,
     Action<ModuleSymbol> symbolValidator = null,
     SignatureDescription[] expectedSignatures = null,
     CSharpCompilationOptions options = null,
     bool verify = true)
 {
     return CompileAndVerifyExperimental(
         source,
         MessageID.IDS_FeatureRefLocalsReturns,
         expectedOutput,
         additionalRefs,
         dependencies,
         sourceSymbolValidator,
         assemblyValidator,
         symbolValidator,
         expectedSignatures,
         options,
         verify);
 }
コード例 #4
0
            public void Emit(string expectedOutput, IEnumerable<ResourceDescription> manifestResources, bool emitPdb, bool peVerify, SignatureDescription[] expectedSignatures)
            {
                bool doExecute = expectedOutput != null;

                using (var testEnvironment = new HostedRuntimeEnvironment(dependencies))
                {
                    string mainModuleName = Emit(testEnvironment, manifestResources, emitPdb);

                    allModuleData = testEnvironment.GetAllModuleData();

                    if (peVerify)
                    {
                        testEnvironment.PeVerify();
                    }

                    if (expectedSignatures != null)
                    {
                        MetadataSignatureUnitTestHelper.VerifyMemberSignatures(testEnvironment, expectedSignatures);
                    }

                    if (doExecute)
                    {
                        testEnvironment.Execute(mainModuleName, expectedOutput);
                    }
                }
            }
コード例 #5
0
        internal CompilationVerifier CompileAndVerify(
            Compilation compilation,
            IEnumerable<ResourceDescription> manifestResources = null,
            IEnumerable<ModuleData> dependencies = null,
            Action<IModuleSymbol> sourceSymbolValidator = null,
            Action<PEAssembly> assemblyValidator = null,
            Action<IModuleSymbol> symbolValidator = null,
            SignatureDescription[] expectedSignatures = null,
            string expectedOutput = null,
            bool verify = true)
        {
            Assert.NotNull(compilation);

            Assert.True(expectedOutput == null ||
                (compilation.Options.OutputKind == OutputKind.ConsoleApplication || compilation.Options.OutputKind == OutputKind.WindowsApplication),
                "Compilation must be executable if output is expected.");

            if (verify)
            {
                // Unsafe code might not verify, so don't try.
                var csharpOptions = compilation.Options as CSharp.CSharpCompilationOptions;
                verify = (csharpOptions == null || !csharpOptions.AllowUnsafe);
            }

            if (sourceSymbolValidator != null)
            {
                var module = compilation.Assembly.Modules.First();
                sourceSymbolValidator(module);
            }

            CompilationVerifier result = null;

            var verifier = Emit(compilation,
                                dependencies,
                                manifestResources,
                                expectedSignatures,
                                expectedOutput,
                                assemblyValidator,
                                symbolValidator,
                                verify);

            if (result == null)
            {
                result = verifier;
            }
            else
            {
                // only one emitter should return a verifier
                Assert.Null(verifier);
            }

            // If this fails, it means that more that all emitters failed to return a validator
            // (i.e. none thought that they were applicable for the given input parameters).
            Assert.NotNull(result);

            return result;
        }
コード例 #6
0
        internal CompilationVerifier Emit(
            Compilation compilation,
            IEnumerable<ModuleData> dependencies,
            IEnumerable<ResourceDescription> manifestResources,
            SignatureDescription[] expectedSignatures,
            string expectedOutput,
            Action<PEAssembly> assemblyValidator,
            Action<IModuleSymbol> symbolValidator,
            bool verify)
        {
            CompilationVerifier verifier = null;

            verifier = new CompilationVerifier(this, compilation, dependencies);

            verifier.Emit(expectedOutput, manifestResources, verify, expectedSignatures);

            // We're dual-purposing emitters here.  In this context, it
            // tells the validator the version of Emit that is calling it. 
            RunValidators(verifier, assemblyValidator, symbolValidator);

            return verifier;
        }
コード例 #7
0
            public void Emit(string expectedOutput, IEnumerable<ResourceDescription> manifestResources, EmitOptions emitOptions, bool peVerify, SignatureDescription[] expectedSignatures)
            {
                using (var testEnvironment = RuntimeEnvironmentFactory.Create(_dependencies))
                {
                    string mainModuleName = Emit(testEnvironment, manifestResources, emitOptions);
                    _allModuleData = testEnvironment.GetAllModuleData();

                    if (peVerify)
                    {
                        testEnvironment.PeVerify();
                    }

                    if (expectedSignatures != null)
                    {
                        MetadataSignatureUnitTestHelper.VerifyMemberSignatures(testEnvironment, expectedSignatures);
                    }

                    if (expectedOutput != null)
                    {
                        testEnvironment.Execute(mainModuleName, expectedOutput);
                    }
                }
            }
コード例 #8
0
ファイル: CommonTestBase.cs プロジェクト: rgani/roslyn
 internal ICompilationVerifier Emit(
     Compilation compilation,
     IEnumerable<ModuleData> dependencies,
     IEnumerable<ResourceDescription> manifestResources,
     SignatureDescription[] expectedSignatures,
     string expectedOutput,
     Action<PEAssembly> assemblyValidator,
     Action<IModuleSymbol> symbolValidator,
     bool verify)
 {
     return null;
 }