Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #333 from krwq/spanunittests
Browse files Browse the repository at this point in the history
Convert Slices tests to Xunit
  • Loading branch information
krwq committed Oct 16, 2015
2 parents 236c34a + 7a36f31 commit c0e4024
Show file tree
Hide file tree
Showing 7 changed files with 696 additions and 169 deletions.
2 changes: 1 addition & 1 deletion src/System.Slices/System.Slices.sln
Expand Up @@ -5,7 +5,7 @@ VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Slices", "src\System.Slices.csproj", "{C5FD8740-19EA-4BCC-B518-7F16B55D23CA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Slices.tests", "tests\System.Slices.tests.csproj", "{20F5308A-1910-40E9-B3F0-6569DB08E649}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Slices.Tests", "tests\System.Slices.Tests.csproj", "{20F5308A-1910-40E9-B3F0-6569DB08E649}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
5 changes: 4 additions & 1 deletion src/System.Slices/src/System.Slices.csproj
Expand Up @@ -30,6 +30,9 @@
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
<PropertyGroup>
<PostBuildEvent>ildasm /out:"$(TargetDir)$(TargetName).beforerewrite.il" /nobar "$(TargetPath)" &amp;&amp; "$([System.IO.Path]::GetFullPath('$(SourceDir)System.Slices\tools\ILSub\ILSub.exe'))" "$(TargetDir)$(TargetName).beforerewrite.il" "$(TargetDir)$(TargetName).rewritten.il" &amp;&amp; ilasm /dll /out:$(TargetPath) /nologo $(TargetDir)$(TargetName).rewritten.il &amp;&amp; ilasm /dll /out:$(TargetPath) /nologo $(TargetDir)$(TargetName).rewritten.il</PostBuildEvent>
<DecompileToILCommand>ildasm /out:"$(TargetDir)$(TargetName).beforerewrite.il" /nobar "$(TargetPath)"</DecompileToILCommand>
<RewriteILCommand>"$([System.IO.Path]::GetFullPath('$(SourceDir)System.Slices\tools\ILSub\ILSub.exe'))" "$(TargetDir)$(TargetName).beforerewrite.il" "$(TargetDir)$(TargetName).rewritten.il"</RewriteILCommand>
<RecompileILCommand>ilasm /quiet /dll /out:$(TargetPath) /nologo $(TargetDir)$(TargetName).rewritten.il</RecompileILCommand>
<PostBuildEvent>$(DecompileToILCommand) &amp;&amp; $(RewriteILCommand) &amp;&amp; $(RecompileILCommand)</PostBuildEvent>
</PropertyGroup>
</Project>
103 changes: 2 additions & 101 deletions src/System.Slices/tests/Harness.cs
Expand Up @@ -2,112 +2,13 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;

class Program
static class Tester
{
public static void Main()
{
Console.WriteLine("TESTING...");
Console.WriteLine("==========");
var sw = Stopwatch.StartNew();
var t = new Tester();
if (t.RunTests(new Tests())) {
Console.WriteLine("Success! ({0})", sw.Elapsed);
}
else {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("{0} Failures ({1})", t.Failures, sw.Elapsed);
Console.ResetColor();
}
}
}

class Tester
{
int m_failures;

public int Failures
{
get { return m_failures; }
}

public bool Success
{
get { return (m_failures == 0); }
}

public void Assert(bool condition, string msg = "")
{
if (!condition) {
m_failures++;
Console.WriteLine(" # assertion failed [{0}]", msg);
}
}

public void AssertEqual<T>(T x, T y)
where T : IEquatable<T>
{
Assert(x.Equals(y), String.Format("{0} != {1}", x, y));
}

public bool RunTests(object tests)
{
// Run all methods that match the pattern 'bool Test*(Tester t)'
var sw = new Stopwatch();
var testMethods =
tests.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance);
foreach (var testMethod in testMethods) {
if (testMethod.Name.StartsWith("Test") &&
testMethod.ReturnType == typeof(bool) &&
testMethod.GetParameters().Length == 1 &&
testMethod.GetParameters()[0].ParameterType == typeof(Tester)) {

Console.WriteLine("Run {0}...", testMethod.Name);

JitWarmUp(testMethod, tests);
CleanUpMemory();

sw.Start();
int failures = m_failures;
bool success = (bool)testMethod.Invoke(tests, new object[] { this });
sw.Stop();
if (success && m_failures == failures) {
Console.WriteLine(" - success ({0})", sw.Elapsed);
}
else {
m_failures++;
Console.WriteLine(" - failure ({0})", sw.Elapsed);
}
sw.Reset();
}
}
return Success;
}

public void CleanUpMemory()
public static void CleanUpMemory()
{
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}

void JitWarmUp(MethodInfo testMethod, object tests)
{
SilentExecution(() => testMethod.Invoke(tests, new object[] { this }));
}

void SilentExecution(Action command)
{
var output = Console.Out;
try {
Console.SetOut(TextWriter.Null);
command.Invoke();
}
finally {
Console.SetOut(output);
}
}
}
39 changes: 13 additions & 26 deletions src/System.Slices/tests/System.Slices.tests.csproj
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{20F5308A-1910-40E9-B3F0-6569DB08E649}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>System.Slices.tests</RootNamespace>
<AssemblyName>System.Slices.tests</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<OutputType>Library</OutputType>
<RootNamespace>System.Slices.Tests</RootNamespace>
<AssemblyName>System.Slices.Tests</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -34,11 +34,6 @@
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<Compile Include="Harness.cs" />
<Compile Include="Tests.cs" />
Expand All @@ -50,18 +45,10 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<None Include="project.json" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="BuildAndTest">
<CallTarget Targets="Build" />
<Exec Command="$(OutputPath)\$(AssemblyName).exe" />
</Target>
<!-- 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>
-->
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>

0 comments on commit c0e4024

Please sign in to comment.