Browse Source

MachineSpecifications test framework initial import.

pull/23/head
Tomasz Tretkowski 14 years ago
parent
commit
72589de445
  1. 24
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/AddInWritingHelp.txt
  2. 31
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/Configuration/AssemblyInfo.cs
  3. BIN
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MSpecRunner/CommandLine.dll
  4. BIN
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MSpecRunner/Machine.Specifications.Reporting.dll
  5. BIN
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MSpecRunner/Machine.Specifications.dll
  6. BIN
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MSpecRunner/Newtonsoft.Json.dll
  7. BIN
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MSpecRunner/Spark.dll
  8. BIN
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MSpecRunner/mspec-clr4.exe
  9. BIN
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MSpecRunner/mspec-x86-clr4.exe
  10. BIN
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MSpecRunner/mspec-x86.exe
  11. BIN
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MSpecRunner/mspec.exe
  12. 15
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MachineSpecifications.addin
  13. 118
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MachineSpecifications.csproj
  14. 4
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/packages.config
  15. 107
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecApplication.cs
  16. 36
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestDebugger.cs
  17. 82
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestFramework.cs
  18. 122
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecUnitTestMonitor.cs
  19. 36
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MspecTestRunner.cs

24
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/AddInWritingHelp.txt

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
You have created a new SharpDevelop AddIn project.
We would like to point out that there are three locations where you can get information on how
to write SharpDevelop AddIns:
- http://wiki.sharpdevelop.net/ (section Developer Zone)
- The folder "doc/technotes" in the SharpDevelop source code download
- You can ask questions about AddIn development in the SharpDevelop forum:
http://community.sharpdevelop.net/forums/
The next steps:
- First, you have to add references to the SharpDevelop assemblies.
An AddIn will work with the SharpDevelop version it was compiled for, or later service releases.
You might want to compile against SharpDevelop 3.0.0.3800 (the first official release of SharpDevelop 3)
to ensure your AddIn runs with all later 3.x versions of SharpDevelop.
- Include a <Manifest> section to your .addin for use with the SharpDevelop AddIn Manager.
See SharpDevelop/doc/technotes/AddInManager.rtf for more information.
- Once you have published your AddIn on the Internet, please add it to the SharpDevelop wiki to let other users know!
http://wiki.sharpdevelop.net/3rdPartyAddins.ashx
This file serves as a reminder for you on how to find information on SharpDevelop AddIn development, you can
remove it from your project if you don't need it anymore.

31
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/Configuration/AssemblyInfo.cs

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
#region Using directives
using System;
using System.Reflection;
using System.Runtime.InteropServices;
#endregion
// 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("MachineSpecifications")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MachineSpecifications")]
[assembly: AssemblyCopyright("Copyright 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// This sets the default COM visibility of types in the assembly to invisible.
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
[assembly: ComVisible(false)]
// The assembly version has following format :
//
// Major.Minor.Build.Revision
//
// You can specify all the values or you can use the default the Revision and
// Build Numbers by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]

BIN
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MSpecRunner/CommandLine.dll

Binary file not shown.

BIN
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MSpecRunner/Machine.Specifications.Reporting.dll

Binary file not shown.

BIN
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MSpecRunner/Machine.Specifications.dll

Binary file not shown.

BIN
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MSpecRunner/Newtonsoft.Json.dll

Binary file not shown.

BIN
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MSpecRunner/Spark.dll

Binary file not shown.

BIN
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MSpecRunner/mspec-clr4.exe

Binary file not shown.

BIN
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MSpecRunner/mspec-x86-clr4.exe

Binary file not shown.

BIN
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MSpecRunner/mspec-x86.exe

Binary file not shown.

BIN
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MSpecRunner/mspec.exe

Binary file not shown.

15
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MachineSpecifications.addin

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
<AddIn name = "Machine.Specifications Addin"
author = "Tomasz Tretkowski"
url = ""
description = "Runner for Machine.Specifications unit tests for SharpDevelop">
<Runtime>
<Import assembly = "MachineSpecifications.dll"/>
</Runtime>
<Path name="/SharpDevelop/UnitTesting/TestFrameworks">
<TestFramework id="mspec"
class="ICSharpCode.MachineSpecifications.MSpecTestFramework"
supportedProjects=".csproj" />
</Path>
</AddIn>

118
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MachineSpecifications.csproj

@ -0,0 +1,118 @@ @@ -0,0 +1,118 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectGuid>{D1DA3B8F-7313-4BDA-8880-461C5F007751}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>Library</OutputType>
<RootNamespace>ICSharpCode.MachineSpecifications</RootNamespace>
<AssemblyName>MachineSpecifications</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'x86' ">
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
<DebugSymbols>True</DebugSymbols>
<DebugType>Full</DebugType>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<OutputPath>..\..\..\..\..\AddIns\Analysis\MachineSpecifications\</OutputPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="AddInWritingHelp.txt" />
<None Include="MachineSpecifications.addin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<SubType>Designer</SubType>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="src\MSpecApplication.cs" />
<Compile Include="src\MSpecTestDebugger.cs" />
<Compile Include="src\MSpecTestFramework.cs" />
<Compile Include="src\MspecTestRunner.cs" />
<Compile Include="src\MSpecUnitTestMonitor.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="MSpecRunner\CommandLine.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="MSpecRunner\Machine.Specifications.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="MSpecRunner\Machine.Specifications.Reporting.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="MSpecRunner\mspec-clr4.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="MSpecRunner\mspec-x86-clr4.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="MSpecRunner\mspec-x86.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="MSpecRunner\mspec.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="MSpecRunner\Newtonsoft.Json.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="MSpecRunner\Spark.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="D:\git\sharpdevelop\src\AddIns\Analysis\UnitTesting\UnitTesting.csproj">
<Project>{1F261725-6318-4434-A1B1-6C70CE4CD324}</Project>
<Name>UnitTesting</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="D:\git\sharpdevelop\src\Main\Base\Project\ICSharpCode.SharpDevelop.csproj">
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project>
<Name>ICSharpCode.SharpDevelop</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="D:\git\sharpdevelop\src\Main\Core\Project\ICSharpCode.Core.csproj">
<Project>{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}</Project>
<Name>ICSharpCode.Core</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="D:\git\sharpdevelop\src\Main\ICSharpCode.SharpDevelop.Dom\Project\ICSharpCode.SharpDevelop.Dom.csproj">
<Project>{924EE450-603D-49C1-A8E5-4AFAA31CE6F3}</Project>
<Name>ICSharpCode.SharpDevelop.Dom</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>

4
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/packages.config

@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Machine.Specifications" version="0.4.9.0" />
</packages>

107
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecApplication.cs

@ -0,0 +1,107 @@ @@ -0,0 +1,107 @@
/*
* Created by SharpDevelop.
* User: trecio
* Date: 2011-06-18
* Time: 14:56
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Diagnostics;
using ICSharpCode.UnitTesting;
using System.IO;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Project;
using System.Text;
namespace ICSharpCode.MachineSpecifications
{
/// <summary>
/// Description of MSpecApplication.
/// </summary>
public class MSpecApplication
{
public MSpecApplication(SelectedTests tests) {
InitializeFrom(tests);
}
public ProcessStartInfo GetProcessStartInfo() {
var result = new ProcessStartInfo();
result.FileName = ExecutableFileName;
result.Arguments = GetArguments();
result.WorkingDirectory = WorkingDirectory;
return result;
}
public string Results {get;set;}
void InitializeFrom(SelectedTests tests) {
this.tests = tests;
project = tests.Project;
}
SelectedTests tests;
IProject project;
string GetArguments()
{
var builder = new StringBuilder();
builder.Append("--xml \"");
builder.Append(FileUtility.GetAbsolutePath(Environment.CurrentDirectory, Results));
builder.Append("\" ");
builder.Append(project.OutputAssemblyFullPath);
return builder.ToString();
}
string ExecutableFileName {
get {
var assemblyDirectory = Path.GetDirectoryName(new Uri(typeof(MSpecApplication).Assembly.CodeBase).LocalPath);
var runnerDirectory = Path.Combine(assemblyDirectory, "MSpecRunner");
string executableName = "mspec";
if (TargetPlatformIs32Bit(project))
executableName += "-x86";
if (UsesClr4(project))
executableName += "-clr4";
executableName += ".exe";
return Path.Combine(runnerDirectory, executableName);
}
}
private bool UsesClr4(IProject project)
{
MSBuildBasedProject msbuildProject = project as MSBuildBasedProject;
if (msbuildProject != null)
{
string targetFrameworkVersion = msbuildProject.GetEvaluatedProperty("TargetFrameworkVersion");
return String.Equals(targetFrameworkVersion, "v4.0", StringComparison.OrdinalIgnoreCase);
}
return false;
}
private bool TargetPlatformIs32Bit(IProject project)
{
MSBuildBasedProject msbuildProject = project as MSBuildBasedProject;
if (msbuildProject != null)
{
string platformTarget = msbuildProject.GetEvaluatedProperty("PlatformTarget");
return String.Compare(platformTarget, "x86", true) == 0;
}
return false;
}
string WorkingDirectory
{
get
{
return Path.GetDirectoryName(project.OutputAssemblyFullPath);
}
}
}
}

36
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestDebugger.cs

@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
/*
* Created by SharpDevelop.
* User: trecio
* Date: 2011-06-18
* Time: 14:02
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Diagnostics;
using ICSharpCode.UnitTesting;
namespace ICSharpCode.MachineSpecifications
{
/// <summary>
/// Description of MSpecTestDebugger.
/// </summary>
public class MSpecTestDebugger : TestDebuggerBase
{
public MSpecTestDebugger()
: base(new UnitTestDebuggerService(), new UnitTestMessageService(), new MSpecUnitTestMonitor())
{ }
protected override ProcessStartInfo GetProcessStartInfo(SelectedTests selectedTests)
{
var app = new MSpecApplication(selectedTests);
app.Results = TestResultsMonitor.FileName;
return app.GetProcessStartInfo();
}
protected override TestResult CreateTestResultForTestFramework(TestResult testResult)
{
return testResult;
}
}
}

82
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestFramework.cs

@ -0,0 +1,82 @@ @@ -0,0 +1,82 @@
/*
* Created by SharpDevelop.
* User: trecio
* Date: 2011-06-18
* Time: 13:31
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Linq;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
namespace ICSharpCode.MachineSpecifications
{
/// <summary>
/// Description of MSpecTestFramework.
/// </summary>
public class MSpecTestFramework : ITestFramework
{
public bool IsTestMethod(IMember member) {
return member is IField
&& IsSpecificationMember(member as IField);
}
public bool IsTestClass(IClass c) {
return HasSpecificationMembers(c) && !IsBehavior(c);
}
public bool IsTestProject(IProject project) {
if (project != null) {
foreach (ProjectItem item in project.Items)
if (IsMSpecAssemblyReference(item))
return true;
}
return false;
}
public ITestRunner CreateTestRunner() {
return new MSpecTestRunner();
}
public ITestRunner CreateTestDebugger() {
return new MSpecTestDebugger();
}
public bool IsBuildNeededBeforeTestRun {
get {return true;}
}
private bool HasSpecificationMembers(IClass c) {
return !c.IsAbstract
&& c.Fields.Any(IsSpecificationMember);
}
private bool IsSpecificationMember(IField field) {
return MSpecItFQName.Equals(field.ReturnType.FullyQualifiedName)
|| MSpecBehavesLikeFQName.Equals(field.ReturnType.FullyQualifiedName);
}
private bool IsBehavior(IClass c) {
return c.Attributes.Any(
attribute => MSpecBehaviorsAttributeFQName.Equals(attribute.AttributeType.FullyQualifiedName));
}
private bool IsMSpecAssemblyReference(ProjectItem projectItem) {
if (projectItem is ReferenceProjectItem) {
ReferenceProjectItem refProjectItem = projectItem as ReferenceProjectItem;
string name = refProjectItem.ShortName;
return MSpecAssemblyName.Equals(name, StringComparison.OrdinalIgnoreCase);
}
return false;
}
const string MSpecAssemblyName = "Machine.Specifications";
const string MSpecItFQName = MSpecAssemblyName + ".It";
const string MSpecBehavesLikeFQName = MSpecAssemblyName + ".Behaves_like";
const string MSpecBehaviorsAttributeFQName = MSpecAssemblyName + ".BehaviorsAttribute";
}
}

122
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecUnitTestMonitor.cs

@ -0,0 +1,122 @@ @@ -0,0 +1,122 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.UnitTesting;
using System.IO;
using ICSharpCode.Core;
using System.Xml;
namespace ICSharpCode.MachineSpecifications
{
public class MSpecUnitTestMonitor : ITestResultsMonitor
{
public event TestFinishedEventHandler TestFinished;
private FileSystemWatcher fileSystemWatcher;
public MSpecUnitTestMonitor()
{
FileName = Path.GetTempFileName();
}
public string FileName { get; set; }
public void Stop()
{
if (fileSystemWatcher != null)
{
fileSystemWatcher.Dispose();
fileSystemWatcher = null;
}
}
public void Start()
{
var filter = FileName;
fileSystemWatcher = new FileSystemWatcher(Path.GetDirectoryName(FileName), Path.GetFileName(FileName));
if (File.Exists(FileName))
{
fileSystemWatcher.NotifyFilter = NotifyFilters.LastWrite;
fileSystemWatcher.Changed += ObservedFileChanged;
} else
fileSystemWatcher.Created += ObservedFileCreated;
fileSystemWatcher.Error += FileObservationError;
fileSystemWatcher.EnableRaisingEvents = true;
}
void FileObservationError(object sender, ErrorEventArgs e)
{
LoggingService.Error("Error while waiting for unit test session report modification.", e.GetException());
}
void ObservedFileCreated(object sender, FileSystemEventArgs e)
{
fileSystemWatcher.Created -= ObservedFileCreated;
fileSystemWatcher.NotifyFilter = NotifyFilters.LastWrite;
fileSystemWatcher.Changed += ObservedFileChanged;
}
void ObservedFileChanged(object sender, FileSystemEventArgs e)
{
Read();
}
public void Read()
{
var document = new XmlDocument();
document.Load(FileName);
var contextNodes = document.SelectNodes("MSpec/assembly/concern/context/specification");
var results = contextNodes.Cast<XmlNode>().Select(BuildTestResultFrom).ToArray();
PublishTestResults(results);
}
TestResult BuildTestResultFrom(XmlNode node)
{
var className = node.SelectSingleNode("../@type-name").InnerText;
var result = new TestResult(className + "." + node.Attributes["field-name"].InnerText);
switch (node.Attributes["status"].InnerText)
{
case "failed":
result.ResultType = TestResultType.Failure;
break;
case "passed":
result.ResultType = TestResultType.Success;
break;
}
var errorNode = node.SelectSingleNode("error");
if (errorNode != null)
{
var messageNode = errorNode.SelectSingleNode("message");
result.Message = messageNode.InnerText;
var stackTraceNode = errorNode.SelectSingleNode("stack-trace");
result.StackTrace = stackTraceNode.InnerText;
}
return result;
}
void PublishTestResults(TestResult[] testResults)
{
if (TestFinished != null)
foreach (var result in testResults)
TestFinished(this, new TestFinishedEventArgs(result));
}
public long InitialFilePosition { get; set; }
public void Dispose()
{
Stop();
try
{
File.Delete(FileName);
}
catch (Exception e)
{
LoggingService.Warn("Could delete temporary file.", e);
}
}
}
}

36
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MspecTestRunner.cs

@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
/*
* Created by SharpDevelop.
* User: trecio
* Date: 2011-06-18
* Time: 14:01
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using ICSharpCode.UnitTesting;
using System.Diagnostics;
namespace ICSharpCode.MachineSpecifications
{
/// <summary>
/// Description of MspecTestRunner.
/// </summary>
public class MSpecTestRunner : TestProcessRunnerBase
{
public MSpecTestRunner()
: base(new UnitTestProcessRunner(), new MSpecUnitTestMonitor(), new UnitTestFileService(), new UnitTestMessageService())
{ }
protected override ProcessStartInfo GetProcessStartInfo(SelectedTests selectedTests)
{
var app = new MSpecApplication(selectedTests);
app.Results = TestResultsMonitor.FileName;
return app.GetProcessStartInfo();
}
protected override TestResult CreateTestResultForTestFramework(TestResult testResult)
{
return testResult;
}
}
}
Loading…
Cancel
Save