Esempio n. 1
0
        public void BrokenPDBStream()
        {
            string source = @"class Foo {}";
            var compilation = CreateCompilationWithMscorlib(source, null, OptionsDll.WithDebugInformationKind(DebugInformationKind.Full));

            var output = new MemoryStream();
            var pdb = new BrokenStream();
            pdb.BreakHow = 2;
            var result = compilation.Emit(output, GetUniqueName(), GetUniqueName(), pdb);
            result.Diagnostics.Verify(
                    Diagnostic(ErrorCode.FTL_DebugEmitFailure).WithArguments("Exception from HRESULT: 0x806D0004")
                );

            Func<EmitResult> f = () => compilation.Emit(output, GetUniqueName(), GetUniqueName(), pdb);
            pdb.Dispose();
            result = f();

            result.Diagnostics.Verify(
                    Diagnostic(ErrorCode.FTL_DebugEmitFailure).WithArguments("Exception from HRESULT: 0x806D0004")
                );
        }
Esempio n. 2
0
        public void BrokenOutStream()
        {
            //These tests ensure that users supplying a broken stream implementation via the emit API 
            //get exceptions enabling them to attribute the failure to their code and to debug.
            string source = @"class Foo {}";
            var compilation = CreateCompilationWithMscorlib(source);

            var output = new BrokenStream();
            Assert.Throws<IOException>(() => compilation.Emit(output));

            output.BreakHow = 1;
            Assert.Throws<NotSupportedException>(() => compilation.Emit(output));

            var outReal = new MemoryStream();
            Func<EmitResult> f = () => compilation.Emit(outReal);
            outReal.Dispose();
            Assert.Throws<ObjectDisposedException>(() => f());
        }
        public void BrokenPDBStream()
        {
            string source = @"class Foo {}";
            var compilation = CreateCompilationWithMscorlib(source, null, TestOptions.DebugDll);

            var output = new MemoryStream();
            var pdb = new BrokenStream();
            pdb.BreakHow = 2;
            var result = compilation.Emit(output, pdb);

            // error CS0041: Unexpected error writing debug information -- 'Exception from HRESULT: 0x806D0004'
            var err = result.Diagnostics.Single();

            Assert.Equal((int)ErrorCode.FTL_DebugEmitFailure, err.Code);
            Assert.Equal(1, err.Arguments.Count);
            var ioExceptionMessage = new IOException().Message;
            Assert.Equal(ioExceptionMessage, (string)err.Arguments[0]);

            pdb.Dispose();
            result = compilation.Emit(output, pdb);

            // error CS0041: Unexpected error writing debug information -- 'Exception from HRESULT: 0x806D0004'
            err = result.Diagnostics.Single();

            Assert.Equal((int)ErrorCode.FTL_DebugEmitFailure, err.Code);
            Assert.Equal(1, err.Arguments.Count);
            Assert.Equal(ioExceptionMessage, (string)err.Arguments[0]);
        }
Esempio n. 4
0
        public void FailingEmitterAllowsCancelationExceptionsThrough()
        {
            string source = @"
public class X
{
    public static void Main()
    {
  
    }
}";
            var compilation = CreateCompilationWithMscorlib(source);
            var broken = new BrokenStream();
            broken.BreakHow = BrokenStream.BreakHowType.CancelOnWrite;

            Assert.Throws<OperationCanceledException>(() => compilation.Emit(broken));
        }
Esempio n. 5
0
        public void FailingEmitter()
        {
            string source = @"
public class X
{
    public static void Main()
    {
  
    }
}";
            var compilation = CreateCompilationWithMscorlib(source);
            var broken = new BrokenStream();
            broken.BreakHow = BrokenStream.BreakHowType.ThrowOnWrite;
            var result = compilation.Emit(broken);
            Assert.False(result.Success);
            result.Diagnostics.Verify(
                // error CS8104: An error occurred while writing the Portable Executable file.
                Diagnostic(ErrorCode.ERR_PeWritingFailure).WithArguments(broken.ThrownException.ToString()).WithLocation(1, 1));
        }
Esempio n. 6
0
        public void BrokenOutStream()
        {
            //These tests ensure that users supplying a broken stream implementation via the emit API 
            //get exceptions enabling them to attribute the failure to their code and to debug.
            string source = @"class Foo {}";
            var compilation = CreateCompilationWithMscorlib(source);

            var output = new BrokenStream();
            var result = compilation.Emit(output);
            result.Diagnostics.Verify(
                // error CS8104: An error occurred while writing the Portable Executable file.
                Diagnostic(ErrorCode.ERR_PeWritingFailure).WithArguments(output.ThrownException.ToString()).WithLocation(1, 1));

            output.BreakHow = BrokenStream.BreakHowType.ThrowOnSetPosition;
            result = compilation.Emit(output);
            result.Diagnostics.Verify(    
                // error CS8104: An error occurred while writing the Portable Executable file.
                Diagnostic(ErrorCode.ERR_PeWritingFailure).WithArguments(output.ThrownException.ToString()).WithLocation(1, 1));

            // disposed stream is not writable
            var outReal = new MemoryStream();
            outReal.Dispose();
            Assert.Throws<ArgumentException>(() => compilation.Emit(outReal));
        }