Permalink
Browse files

Add support for running tests written in VB.net instead of C#

Add a simple VB.Net test
  • Loading branch information...
1 parent 2f5e31e commit 89b451240abd283bac86e180db9a08c45186e966 @kg kg committed Feb 20, 2012
Showing with 75 additions and 32 deletions.
  1. +2 −4 Tests/ComparisonTests.cs
  2. +1 −1 Tests/DependencyTests.cs
  3. +3 −4 Tests/FailingTests.cs
  4. +24 −0 Tests/SimpleTestCases/Constructors.vb
  5. +1 −0 Tests/Tests.csproj
  6. +44 −23 Tests/Util.cs
View
@@ -172,10 +172,8 @@ public class ComparisonTests : GenericTestFixture {
[Test]
public void AllSimpleTests () {
var defaultProvider = MakeDefaultProvider();
- var simpleTests = Directory.GetFiles(
- Path.GetFullPath(Path.Combine(ComparisonTest.TestSourceFolder, "SimpleTestCases")),
- "*.cs"
- );
+ var testPath = Path.GetFullPath(Path.Combine(ComparisonTest.TestSourceFolder, "SimpleTestCases"));
+ var simpleTests = Directory.GetFiles(testPath, "*.cs").Concat(Directory.GetFiles(testPath, "*.vb")).ToArray();
RunComparisonTests(
simpleTests, null, defaultProvider
View
@@ -12,7 +12,7 @@ public class DependencyTests {
public void EnumeratesAssemblyDependencies () {
TempFileCollection temporaryFiles;
- var assembly = CSharpUtil.Compile(@"
+ var assembly = CompilerUtil.CompileCS(@"
using System;
using System.Text.RegularExpressions;
View
@@ -14,10 +14,9 @@ namespace JSIL.Tests {
public class FailingTests {
[Test]
public void AllFailingTests () {
- var simpleTests = Directory.GetFiles(
- Path.GetFullPath(Path.Combine(ComparisonTest.TestSourceFolder, "FailingTestCases")),
- "*.cs"
- );
+ var testPath = Path.GetFullPath(Path.Combine(ComparisonTest.TestSourceFolder, "FailingTestCases"));
+ var simpleTests = Directory.GetFiles(testPath, "*.cs").Concat(Directory.GetFiles(testPath, "*.vb")).ToArray();
+
int passCount = 0;
foreach (var filename in simpleTests) {
@@ -0,0 +1,24 @@
+Imports System
+
+Public Module Program
+ Public Sub Main(Args As String())
+ Console.WriteLine(New CustomType())
+ End Sub
+End Module
+
+Public Class CustomType
+ Public Shared A As Integer
+ Public B As Integer
+
+ Shared Sub New()
+ A = 1
+ End Sub
+
+ Public Sub New()
+ B = 1
+ End Sub
+
+ Public Overrides Function ToString() As String
+ Return String.Format("A = {0}, B = {1}", A, B)
+ End Function
+End Class
View
@@ -277,6 +277,7 @@
<None Include="SimpleTestCases\IsAssignableFrom.cs" />
<None Include="SimpleTestCases\DelegateResultWithConstraints.cs" />
<None Include="TestCases\GenericNestedTypeConstructedInParentStaticConstructor.cs" />
+ <Content Include="SimpleTestCases\Constructors.vb" />
<Compile Include="TestCases\StaticInitializersInGenericTypesSettingStaticFields.cs" />
<Compile Include="Util.cs" />
<Compile Include="VerbatimTests.cs" />
View
@@ -12,6 +12,7 @@
using System.Diagnostics;
using System.Runtime.Serialization.Json;
using System.Threading;
+using Microsoft.VisualBasic;
using NUnit.Framework;
using System.Globalization;
using Microsoft.Win32;
@@ -28,13 +29,13 @@ public JavaScriptException (int exitCode, string stdout, string stderr)
}
}
- public static class CSharpUtil {
+ public static class CompilerUtil {
public static string TempPath;
// Attempt to clean up stray assembly files from previous test runs
// since the assemblies would have remained locked and undeletable
// due to being loaded
- static CSharpUtil () {
+ static CompilerUtil () {
TempPath = Path.Combine(Path.GetTempPath(), "JSIL Tests");
if (!Directory.Exists(TempPath))
Directory.CreateDirectory(TempPath);
@@ -46,33 +47,44 @@ public static class CSharpUtil {
}
}
- public static Assembly Compile (string sourceCode, out TempFileCollection temporaryFiles) {
+ public static Assembly CompileCS (string sourceCode, out TempFileCollection temporaryFiles) {
using (var csc = new CSharpCodeProvider(new Dictionary<string, string>() {
{ "CompilerVersion", "v4.0" }
})) {
+ return Compile(csc, sourceCode, out temporaryFiles);
+ }
+ }
- var parameters = new CompilerParameters(new[] {
- "mscorlib.dll", "System.dll", "System.Core.dll", "Microsoft.CSharp.dll",
- typeof(JSIL.Meta.JSIgnore).Assembly.Location
- }) {
- CompilerOptions = "/unsafe",
- GenerateExecutable = true,
- GenerateInMemory = false,
- IncludeDebugInformation = true,
- TempFiles = new TempFileCollection(TempPath, true)
- };
+ public static Assembly CompileVB (string sourceCode, out TempFileCollection temporaryFiles) {
+ using (var vbc = new VBCodeProvider(new Dictionary<string, string>() {
+ { "CompilerVersion", "v4.0" }
+ })) {
+ return Compile(vbc, sourceCode, out temporaryFiles);
+ }
+ }
- var results = csc.CompileAssemblyFromSource(parameters, sourceCode);
+ private static Assembly Compile (CodeDomProvider provider, string sourceCode, out TempFileCollection temporaryFiles) {
+ var parameters = new CompilerParameters(new[] {
+ "mscorlib.dll", "System.dll", "System.Core.dll", "Microsoft.CSharp.dll",
+ typeof(JSIL.Meta.JSIgnore).Assembly.Location
+ }) {
+ CompilerOptions = "/unsafe",
+ GenerateExecutable = true,
+ GenerateInMemory = false,
+ IncludeDebugInformation = true,
+ TempFiles = new TempFileCollection(TempPath, true)
+ };
- if (results.Errors.Count > 0) {
- throw new Exception(
- String.Join(Environment.NewLine, results.Errors.Cast<CompilerError>().Select((ce) => ce.ToString()).ToArray())
- );
- }
+ var results = provider.CompileAssemblyFromSource(parameters, sourceCode);
- temporaryFiles = results.TempFiles;
- return results.CompiledAssembly;
+ if (results.Errors.Count > 0) {
+ throw new Exception(
+ String.Join(Environment.NewLine, results.Errors.Cast<CompilerError>().Select((ce) => ce.ToString()).ToArray())
+ );
}
+
+ temporaryFiles = results.TempFiles;
+ return results.CompiledAssembly;
}
}
@@ -109,7 +121,16 @@ public class ComparisonTest : IDisposable {
Filename = Path.Combine(TestSourceFolder, filename);
var sourceCode = File.ReadAllText(Filename);
- Assembly = CSharpUtil.Compile(sourceCode, out TemporaryFiles);
+ switch (Path.GetExtension(filename).ToLower()) {
+ case ".cs":
+ Assembly = CompilerUtil.CompileCS(sourceCode, out TemporaryFiles);
+ break;
+ case ".vb":
+ Assembly = CompilerUtil.CompileVB(sourceCode, out TemporaryFiles);
+ break;
+ default:
+ throw new ArgumentException("Unsupported source file type for test");
+ }
var program = Assembly.GetType("Program");
if (program == null)
@@ -251,7 +272,7 @@ public class ComparisonTest : IDisposable {
return output[0] ?? "";
} finally {
- var jsFile = Filename.Replace(".cs", ".js");
+ var jsFile = Filename.Replace(".cs", ".js").Replace(".vb", ".js");
if (File.Exists(jsFile))
File.Delete(jsFile);
File.Copy(tempFilename, jsFile);

0 comments on commit 89b4512

Please sign in to comment.