diff --git a/aspclassiccompiler/ASPClassicCompiler.sln b/aspclassiccompiler/ASPClassicCompiler.sln index 1ef74bc..2df9d61 100644 --- a/aspclassiccompiler/ASPClassicCompiler.sln +++ b/aspclassiccompiler/ASPClassicCompiler.sln @@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspWebApp", "AspWebApp\AspW EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NerdDinnerAsp", "NerdDinnerAsp\NerdDinnerAsp.csproj", "{328C148C-DBEE-41A4-B1C7-104CBB216556}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VBScriptTest", "VBScriptTest\VBScriptTest.csproj", "{3153B5A6-B372-46D0-A10B-0CC4C4FBAE9D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -41,6 +43,10 @@ Global {328C148C-DBEE-41A4-B1C7-104CBB216556}.Debug|Any CPU.Build.0 = Debug|Any CPU {328C148C-DBEE-41A4-B1C7-104CBB216556}.Release|Any CPU.ActiveCfg = Release|Any CPU {328C148C-DBEE-41A4-B1C7-104CBB216556}.Release|Any CPU.Build.0 = Release|Any CPU + {3153B5A6-B372-46D0-A10B-0CC4C4FBAE9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3153B5A6-B372-46D0-A10B-0CC4C4FBAE9D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3153B5A6-B372-46D0-A10B-0CC4C4FBAE9D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3153B5A6-B372-46D0-A10B-0CC4C4FBAE9D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/aspclassiccompiler/VBScript/Runtime/IAssert.cs b/aspclassiccompiler/VBScript/Runtime/IAssert.cs new file mode 100644 index 0000000..8976849 --- /dev/null +++ b/aspclassiccompiler/VBScript/Runtime/IAssert.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Dlrsoft.VBScript.Runtime +{ + public interface IAssert + { + void AreEqual(object expected, object actual); + void AreEqual(object expected, object actual, string message); + void AreNotEqual(object notExpected, object actual); + void AreNotEqual(object notExpected, object actual, string message); + void Fail(); + void Fail(string message); + void IsFalse(bool condition); + void IsFalse(bool condition, string message); + void IsTrue(bool condition); + void IsTrue(bool condition, string message); + } +} diff --git a/aspclassiccompiler/VBScript/VBScript.VS2010.csproj b/aspclassiccompiler/VBScript/VBScript.VS2010.csproj index 5af701a..237bc6a 100644 --- a/aspclassiccompiler/VBScript/VBScript.VS2010.csproj +++ b/aspclassiccompiler/VBScript/VBScript.VS2010.csproj @@ -89,6 +89,7 @@ + diff --git a/aspclassiccompiler/VBScript/VBScript.csproj b/aspclassiccompiler/VBScript/VBScript.csproj index 7e4c484..f388d58 100644 --- a/aspclassiccompiler/VBScript/VBScript.csproj +++ b/aspclassiccompiler/VBScript/VBScript.csproj @@ -82,6 +82,7 @@ + diff --git a/aspclassiccompiler/VBScriptTest/NunitAssert.cs b/aspclassiccompiler/VBScriptTest/NunitAssert.cs new file mode 100644 index 0000000..f0b5187 --- /dev/null +++ b/aspclassiccompiler/VBScriptTest/NunitAssert.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Dlrsoft.VBScript.Runtime; +using NUnit.Framework; + +namespace Dlrsoft.VBScriptTest +{ + public class NunitAssert : IAssert + { + #region IAssert Members + + public void AreEqual(object expected, object actual) + { + Assert.AreEqual(expected, actual); + } + + public void AreEqual(object expected, object actual, string message) + { + Assert.AreEqual(expected, actual, message); + } + + public void AreNotEqual(object notExpected, object actual) + { + Assert.AreNotEqual(notExpected, actual); + } + + public void AreNotEqual(object notExpected, object actual, string message) + { + Assert.AreNotEqual(notExpected, actual, message); + } + + public void Fail() + { + Assert.Fail(); + } + + public void Fail(string message) + { + Assert.Fail(message); + } + + public void IsFalse(bool condition) + { + Assert.IsFalse(condition); + } + + public void IsFalse(bool condition, string message) + { + Assert.IsFalse(condition, message); + } + + public void IsTrue(bool condition) + { + Assert.IsTrue(condition); + } + + public void IsTrue(bool condition, string message) + { + Assert.IsTrue(condition, message); + } + + #endregion + } +} diff --git a/aspclassiccompiler/VBScriptTest/Properties/AssemblyInfo.cs b/aspclassiccompiler/VBScriptTest/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..fdc02ce --- /dev/null +++ b/aspclassiccompiler/VBScriptTest/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("VBScriptTest")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("VBScriptTest")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2011")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM componenets. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("7dd772ea-4578-4083-a45a-e3877734b214")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/aspclassiccompiler/VBScriptTest/TestRunner.cs b/aspclassiccompiler/VBScriptTest/TestRunner.cs new file mode 100644 index 0000000..88abd6a --- /dev/null +++ b/aspclassiccompiler/VBScriptTest/TestRunner.cs @@ -0,0 +1,77 @@ +using System; +using System.Text; +using System.Collections.Generic; +using NUnit.Framework; +using System.IO; + +namespace Dlrsoft.VBScriptTest +{ + /// + /// Summary description for UnitTest1 + /// + [TestFixture] + public class TestRunner + { + public TestRunner() + { + // + // TODO: Add constructor logic here + // + } + + private TestContext testContextInstance; + + /// + ///Gets or sets the test context which provides + ///information about and functionality for the current test run. + /// + public TestContext TestContext + { + get + { + return testContextInstance; + } + set + { + testContextInstance = value; + } + } + + #region Additional test attributes + // + // You can use the following additional attributes as you write your tests: + // + // Use ClassInitialize to run code before running the first test in the class + // [ClassInitialize()] + // public static void MyClassInitialize(TestContext testContext) { } + // + // Use ClassCleanup to run code after all tests in a class have run + // [ClassCleanup()] + // public static void MyClassCleanup() { } + // + // Use TestInitialize to run code before running each test + // [TestInitialize()] + // public void MyTestInitialize() { } + // + // Use TestCleanup to run code after each test has run + // [TestCleanup()] + // public void MyTestCleanup() { } + // + #endregion + + [Test] + public void RunTest() + { + VBScriptTestHelper.Walk( + Path.Combine(VBScriptTestHelper.AssemblyDirectory, "../../VBScripts"), + f => + { + if (f.EndsWith(".vbs", StringComparison.InvariantCultureIgnoreCase)) + { + VBScriptTestHelper.Run(f); + } + } + ); + } + } +} diff --git a/aspclassiccompiler/VBScriptTest/VBScriptTest.csproj b/aspclassiccompiler/VBScriptTest/VBScriptTest.csproj new file mode 100644 index 0000000..c8b2a72 --- /dev/null +++ b/aspclassiccompiler/VBScriptTest/VBScriptTest.csproj @@ -0,0 +1,80 @@ + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {3153B5A6-B372-46D0-A10B-0CC4C4FBAE9D} + Library + Properties + Dlrsoft.VBScriptTest + Dlrsoft.VBScriptTest + v3.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE;USE35 + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\library\35\Microsoft.Dynamic.dll + + + False + ..\library\35\Microsoft.Scripting.dll + + + False + ..\library\35\Microsoft.Scripting.Core.dll + + + False + ..\library\35\Microsoft.Scripting.ExtensionAttribute.dll + + + False + ..\library\35\nunit.framework.dll + + + + + + + + + + + + + + {0846368D-EA96-4AC4-81AF-E4F9B78CE60B} + VBScript + + + + + + + + \ No newline at end of file diff --git a/aspclassiccompiler/VBScriptTest/VBScriptTestHelper.cs b/aspclassiccompiler/VBScriptTest/VBScriptTestHelper.cs new file mode 100644 index 0000000..a2cfe4a --- /dev/null +++ b/aspclassiccompiler/VBScriptTest/VBScriptTestHelper.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Dynamic; +using System.Reflection; +using System.IO; +#if USE35 +using Microsoft.Scripting.Hosting; +using Microsoft.Scripting.Ast; +#else +using System.Linq.Expressions; +#endif + +using Dlrsoft.VBScript.Hosting; +namespace Dlrsoft.VBScriptTest +{ + public class VBScriptTestHelper + { + static public void Run(string filePath) + { + // Setup DLR ScriptRuntime with our languages. We hardcode them here + // but a .NET app looking for general language scripting would use + // an app.config file and ScriptRuntime.CreateFromConfiguration. + var setup = new ScriptRuntimeSetup(); + string qualifiedname = typeof(VBScriptContext).AssemblyQualifiedName; + setup.LanguageSetups.Add(new LanguageSetup( + qualifiedname, "vbscript", new[] { "vbscript" }, new[] { ".vbs" })); + var dlrRuntime = new ScriptRuntime(setup); + + //Add the VBScript runtime assembly + dlrRuntime.LoadAssembly(typeof(global::Dlrsoft.VBScript.Runtime.BuiltInFunctions).Assembly); + + // Get a VBScript engine and run stuff ... + var engine = dlrRuntime.GetEngine("vbscript"); + var scriptSource = engine.CreateScriptSourceFromFile(filePath); + var compiledCode = scriptSource.Compile(); + var feo = engine.CreateScope(); + //feo = engine.ExecuteFile(filename, feo); + feo.SetVariable("Assert", new NunitAssert()); + compiledCode.Execute(feo); + } + + static public string AssemblyDirectory + { + get + { + string codeBase = Assembly.GetExecutingAssembly().CodeBase; + UriBuilder uri = new UriBuilder(codeBase); + string path = Uri.UnescapeDataString(uri.Path); + return Path.GetDirectoryName(path); + } + } + + static public void Walk(string path, Action fileHandler) + { + FileAttributes fa = File.GetAttributes(path); + if ((fa & FileAttributes.Directory) == FileAttributes.Directory) + { + Walk(new DirectoryInfo(path), fileHandler); + } + else + { + Walk(new FileInfo(path), fileHandler); + } + } + + static private void Walk(DirectoryInfo di, Action fileHandler) + { + foreach (FileInfo fi in di.GetFiles()) + { + Walk(fi, fileHandler); + } + + foreach (DirectoryInfo cdi in di.GetDirectories()) + { + Walk(cdi, fileHandler); + } + } + + static private void Walk(FileInfo fi, Action fileHandler) + { + fileHandler(fi.FullName); + } + + } +} diff --git a/aspclassiccompiler/VBScriptTest/VBScripts/DataTypes.vbs b/aspclassiccompiler/VBScriptTest/VBScripts/DataTypes.vbs new file mode 100644 index 0000000..10d757c --- /dev/null +++ b/aspclassiccompiler/VBScriptTest/VBScripts/DataTypes.vbs @@ -0,0 +1,2 @@ +dim a +Assert.IsTrue(IsEmpty(a), "Unassigned variable must be empty") diff --git a/aspclassiccompiler/library/35/nunit.framework.dll b/aspclassiccompiler/library/35/nunit.framework.dll new file mode 100644 index 0000000..875e098 Binary files /dev/null and b/aspclassiccompiler/library/35/nunit.framework.dll differ diff --git a/aspclassiccompiler/library/40/nunit.framework.dll b/aspclassiccompiler/library/40/nunit.framework.dll new file mode 100644 index 0000000..875e098 Binary files /dev/null and b/aspclassiccompiler/library/40/nunit.framework.dll differ