Skip to content

Commit b1a1960

Browse files
committed
A couple more tests.
1 parent 9645216 commit b1a1960

4 files changed

Lines changed: 36 additions & 2 deletions

File tree

RoslynCodeProviderTest/CSharpProviderTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ public static void ClassInitialize(TestContext testContext) {
1717
string frameworkFolder = Path.GetDirectoryName(typeof(object).Assembly.Location);
1818
string compilerPath = Path.Combine(frameworkFolder, "csc.exe");
1919
var codeDomProviderType = typeof(Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider);
20+
#pragma warning disable CS0618
2021
csharpCodeProvider = new CSharpCodeProvider(compilerSettings: CompilerSettingsHelper.CSC);
22+
#pragma warning restore CS0618
2123
AppContext.SetSwitch("Switch.System.DisableTempFileCollectionDirectoryFeature", true);
2224
}
2325

RoslynCodeProviderTest/ProviderOptionsTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,32 @@ public void DefaultSettings()
4444
Assert.AreEqual<string>("bar2", opts.AllOptions["AnotherCoolSetting"]);
4545
}
4646

47+
[TestMethod]
48+
public void FromShortConstructor()
49+
{
50+
IProviderOptions opts = new ProviderOptions(@"D:\My\Fun\Compiler\Path\compiles.exe", 123);
51+
Assert.IsNotNull(opts);
52+
Assert.AreEqual<string>(@"D:\My\Fun\Compiler\Path\compiles.exe", opts.CompilerFullPath); // Would include csc.exe or vbc.exe if the extension we searched for wasn't fake.
53+
Assert.AreEqual<int>(123, opts.CompilerServerTimeToLive); // 10 in Production. 900 in a "dev" environment.
54+
Assert.IsFalse(opts.UseAspNetSettings); // Default via constructor is false.
55+
Assert.IsFalse(opts.WarnAsError);
56+
Assert.IsNull(opts.CompilerVersion);
57+
Assert.AreEqual<int>(0, opts.AllOptions.Count);
58+
}
59+
60+
[TestMethod]
61+
public void FromICompilerSettings()
62+
{
63+
IProviderOptions opts = new ProviderOptions(CompilerSettingsHelper.CSC);
64+
Assert.IsNotNull(opts);
65+
Assert.AreEqual<string>(CompilerSettingsHelper.CSC.CompilerFullPath, opts.CompilerFullPath); // Would include csc.exe or vbc.exe if the extension we searched for wasn't fake.
66+
Assert.AreEqual<int>(CompilerSettingsHelper.CSC.CompilerServerTimeToLive, opts.CompilerServerTimeToLive); // 10 in Production. 900 in a "dev" environment.
67+
Assert.IsFalse(opts.UseAspNetSettings); // Default via constructor is false.
68+
Assert.IsFalse(opts.WarnAsError);
69+
Assert.IsNull(opts.CompilerVersion);
70+
Assert.AreEqual<int>(0, opts.AllOptions.Count);
71+
}
72+
4773
// <providerOptions> override defaults
4874
[TestMethod]
4975
public void FromProviderOptions()

RoslynCodeProviderTest/VBCodeProviderTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ public class VBCodeProviderTests {
1818
private const int Failed = 1;
1919
private const int Success = 0;
2020

21+
#pragma warning disable CS0618
2122
private CommonCodeDomProviderTests commonTests = new CommonCodeDomProviderTests();
2223
private CodeDomProvider _codeProvider = new VBCodeProvider(CompilerSettingsHelper.VB);
24+
#pragma warning restore CS0618
2325

2426
[ClassInitialize]
2527
public static void ClassInitialize(TestContext context) {

src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/Util/ProviderOptions.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ public ProviderOptions()
2222
this.CompilerFullPath = null;
2323
this.CompilerVersion = null;
2424
this.WarnAsError = false;
25-
this.AllOptions = null;
25+
26+
// To be consistent, make sure there is always a dictionary here. It is less than ideal
27+
// for some parts of code to be checking AllOptions.count and some part checking
28+
// for AllOptions == null.
29+
this.AllOptions = new ReadOnlyDictionary<string, string>(new Dictionary<string, string>());
2630

2731
// This results in no keep-alive for the compiler. This will likely result in
2832
// slower performance for any program that calls out the the compiler any
@@ -48,7 +52,7 @@ public ProviderOptions(IProviderOptions opts)
4852
this.CompilerVersion = opts.CompilerVersion;
4953
this.WarnAsError = opts.WarnAsError;
5054
this.UseAspNetSettings = opts.UseAspNetSettings;
51-
this.AllOptions = opts.AllOptions;
55+
this.AllOptions = new ReadOnlyDictionary<string, string>(opts.AllOptions);
5256
}
5357

5458
/// <summary>

0 commit comments

Comments
 (0)