Added unit test framework.
This commit is contained in:
parent
9fcff1b8fb
commit
48c9b91e26
12 changed files with 373 additions and 0 deletions
|
@ -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
|
||||
|
|
20
aspclassiccompiler/VBScript/Runtime/IAssert.cs
Normal file
20
aspclassiccompiler/VBScript/Runtime/IAssert.cs
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -89,6 +89,7 @@
|
|||
<Compile Include="Runtime\DynamicObjectHelpers.cs" />
|
||||
<Compile Include="Runtime\ErrObject.cs" />
|
||||
<Compile Include="Runtime\HelperFunctions.cs" />
|
||||
<Compile Include="Runtime\IAssert.cs" />
|
||||
<Compile Include="Runtime\InvokeMemberBinderKey.cs" />
|
||||
<Compile Include="Runtime\ITrace.cs" />
|
||||
<Compile Include="Runtime\RuntimeHelpers.cs" />
|
||||
|
|
|
@ -82,6 +82,7 @@
|
|||
<Compile Include="Runtime\DynamicObjectHelpers.cs" />
|
||||
<Compile Include="Runtime\ErrObject.cs" />
|
||||
<Compile Include="Runtime\HelperFunctions.cs" />
|
||||
<Compile Include="Runtime\IAssert.cs" />
|
||||
<Compile Include="Runtime\InvokeMemberBinderKey.cs" />
|
||||
<Compile Include="Runtime\ITrace.cs" />
|
||||
<Compile Include="Runtime\RuntimeHelpers.cs" />
|
||||
|
|
65
aspclassiccompiler/VBScriptTest/NunitAssert.cs
Normal file
65
aspclassiccompiler/VBScriptTest/NunitAssert.cs
Normal file
|
@ -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
|
||||
}
|
||||
}
|
35
aspclassiccompiler/VBScriptTest/Properties/AssemblyInfo.cs
Normal file
35
aspclassiccompiler/VBScriptTest/Properties/AssemblyInfo.cs
Normal file
|
@ -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")]
|
77
aspclassiccompiler/VBScriptTest/TestRunner.cs
Normal file
77
aspclassiccompiler/VBScriptTest/TestRunner.cs
Normal file
|
@ -0,0 +1,77 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using System.IO;
|
||||
|
||||
namespace Dlrsoft.VBScriptTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for UnitTest1
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public class TestRunner
|
||||
{
|
||||
public TestRunner()
|
||||
{
|
||||
//
|
||||
// TODO: Add constructor logic here
|
||||
//
|
||||
}
|
||||
|
||||
private TestContext testContextInstance;
|
||||
|
||||
/// <summary>
|
||||
///Gets or sets the test context which provides
|
||||
///information about and functionality for the current test run.
|
||||
///</summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
80
aspclassiccompiler/VBScriptTest/VBScriptTest.csproj
Normal file
80
aspclassiccompiler/VBScriptTest/VBScriptTest.csproj
Normal file
|
@ -0,0 +1,80 @@
|
|||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{3153B5A6-B372-46D0-A10B-0CC4C4FBAE9D}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Dlrsoft.VBScriptTest</RootNamespace>
|
||||
<AssemblyName>Dlrsoft.VBScriptTest</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;USE35</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Dynamic, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\library\35\Microsoft.Dynamic.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Scripting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\library\35\Microsoft.Scripting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Scripting.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\library\35\Microsoft.Scripting.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Scripting.ExtensionAttribute, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\library\35\Microsoft.Scripting.ExtensionAttribute.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=2.5.9.10348, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\library\35\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="NunitAssert.cs" />
|
||||
<Compile Include="VBScriptTestHelper.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="TestRunner.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VBScript\VBScript.csproj">
|
||||
<Project>{0846368D-EA96-4AC4-81AF-E4F9B78CE60B}</Project>
|
||||
<Name>VBScript</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="VBScripts\DataTypes.vbs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
86
aspclassiccompiler/VBScriptTest/VBScriptTestHelper.cs
Normal file
86
aspclassiccompiler/VBScriptTest/VBScriptTestHelper.cs
Normal file
|
@ -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<string> 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<string> 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<string> fileHandler)
|
||||
{
|
||||
fileHandler(fi.FullName);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
2
aspclassiccompiler/VBScriptTest/VBScripts/DataTypes.vbs
Normal file
2
aspclassiccompiler/VBScriptTest/VBScripts/DataTypes.vbs
Normal file
|
@ -0,0 +1,2 @@
|
|||
dim a
|
||||
Assert.IsTrue(IsEmpty(a), "Unassigned variable must be empty")
|
BIN
aspclassiccompiler/library/35/nunit.framework.dll
Normal file
BIN
aspclassiccompiler/library/35/nunit.framework.dll
Normal file
Binary file not shown.
BIN
aspclassiccompiler/library/40/nunit.framework.dll
Normal file
BIN
aspclassiccompiler/library/40/nunit.framework.dll
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue