|
1 | 1 | // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. |
2 | 2 |
|
| 3 | +using System.Linq; |
3 | 4 | using Microsoft.CodeAnalysis.CSharp.Test.Utilities; |
4 | 5 | using Roslyn.Test.Utilities; |
5 | 6 | using Roslyn.Utilities; |
@@ -60,6 +61,60 @@ public void FileWithErrors() |
60 | 61 | Diagnostic(ErrorCode.ERR_NameNotInContext, "asdf").WithArguments("asdf").WithLocation(3, 21)); |
61 | 62 | } |
62 | 63 |
|
| 64 | + [Fact] |
| 65 | + public void FileThatCannotBeDecoded() |
| 66 | + { |
| 67 | + var code = "#load \"b.csx\""; |
| 68 | + var resolver = TestSourceReferenceResolver.Create( |
| 69 | + KeyValuePair.Create<string, object>("a.csx", new byte[] { 0xd8, 0x00, 0x00 }), |
| 70 | + KeyValuePair.Create<string, object>("b.csx", "#load \"a.csx\"")); |
| 71 | + var options = TestOptions.DebugDll.WithSourceReferenceResolver(resolver); |
| 72 | + var compilation = CreateCompilationWithMscorlib45(code, sourceFileName: "external1.csx", options: options, parseOptions: TestOptions.Script); |
| 73 | + var external1 = compilation.SyntaxTrees.Last(); |
| 74 | + var external2 = Parse(code, filename: "external2.csx", options: TestOptions.Script); |
| 75 | + compilation = compilation.AddSyntaxTrees(external2); |
| 76 | + |
| 77 | + Assert.Equal(3, compilation.SyntaxTrees.Length); |
| 78 | + compilation.GetParseDiagnostics().Verify( |
| 79 | + // (1,7): error CS2015: 'a.csx' is a binary file instead of a text file |
| 80 | + // #load "a.csx" |
| 81 | + Diagnostic(ErrorCode.ERR_BinaryFile, @"""a.csx""").WithArguments("a.csx").WithLocation(1, 7)); |
| 82 | + |
| 83 | + var external3 = Parse(@" |
| 84 | + #load ""b.csx"" |
| 85 | + #load ""a.csx""", filename: "external3.csx", options: TestOptions.Script); |
| 86 | + compilation = compilation.ReplaceSyntaxTree(external1, external3); |
| 87 | + |
| 88 | + Assert.Equal(3, compilation.SyntaxTrees.Length); |
| 89 | + compilation.GetParseDiagnostics().Verify( |
| 90 | + // external3.csx(3,23): error CS2015: 'a.csx' is a binary file instead of a text file |
| 91 | + // #load "a.csx" |
| 92 | + Diagnostic(ErrorCode.ERR_BinaryFile, @"""a.csx""").WithArguments("a.csx").WithLocation(3, 23), |
| 93 | + // b.csx(1,7): error CS2015: 'a.csx' is a binary file instead of a text file |
| 94 | + // #load "a.csx" |
| 95 | + Diagnostic(ErrorCode.ERR_BinaryFile, @"""a.csx""").WithArguments("a.csx").WithLocation(1, 7)); |
| 96 | + |
| 97 | + var external4 = Parse("#load \"a.csx\"", filename: "external4.csx", options: TestOptions.Script); |
| 98 | + compilation = compilation.ReplaceSyntaxTree(external3, external4); |
| 99 | + |
| 100 | + Assert.Equal(3, compilation.SyntaxTrees.Length); |
| 101 | + compilation.GetParseDiagnostics().Verify( |
| 102 | + // external4.csx(1,7): error CS2015: 'a.csx' is a binary file instead of a text file |
| 103 | + // #load "a.csx" |
| 104 | + Diagnostic(ErrorCode.ERR_BinaryFile, @"""a.csx""").WithArguments("a.csx").WithLocation(1, 7), |
| 105 | + // b.csx(1,7): error CS2015: 'a.csx' is a binary file instead of a text file |
| 106 | + // #load "a.csx" |
| 107 | + Diagnostic(ErrorCode.ERR_BinaryFile, @"""a.csx""").WithArguments("a.csx").WithLocation(1, 7)); |
| 108 | + |
| 109 | + compilation = compilation.RemoveSyntaxTrees(external2); |
| 110 | + |
| 111 | + Assert.Equal(external4, compilation.SyntaxTrees.Single()); |
| 112 | + compilation.GetParseDiagnostics().Verify( |
| 113 | + // external4.csx(1,7): error CS2015: 'a.csx' is a binary file instead of a text file |
| 114 | + // #load "a.csx" |
| 115 | + Diagnostic(ErrorCode.ERR_BinaryFile, @"""a.csx""").WithArguments("a.csx").WithLocation(1, 7)); |
| 116 | + } |
| 117 | + |
63 | 118 | [Fact] |
64 | 119 | public void NoSourceReferenceResolver() |
65 | 120 | { |
|
0 commit comments