Skip to content

Commit

Permalink
CheckThat now contains Check.That!
Browse files Browse the repository at this point in the history
  • Loading branch information
drunkcod committed Jul 11, 2020
1 parent 171b8d9 commit 7e8d8a2
Show file tree
Hide file tree
Showing 61 changed files with 138 additions and 111 deletions.
59 changes: 13 additions & 46 deletions Source/Check.That/Check.cs
Expand Up @@ -4,10 +4,11 @@
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Cone;
using Cone.Core;
using Cone.Expectations;

namespace Cone
namespace CheckThat
{
/*
* This file contains more repitition than any sane man would normally agree with.
Expand Down Expand Up @@ -38,42 +39,19 @@ public static bool IncludeGuide
static bool ReferencesExtensionPoints(Assembly assembly) =>
assembly.GetReferencedAssemblies().Any(a => a.FullName == ExtensionsAssembly.FullName);

public static void Initialize() {
DoMakeFail = DefaultFail;
That(() => Expect != null);
}
internal static void Initialize() => That(() => Expect != null);

internal static Exception MakeFail(FailedExpectation fail, Exception innerException) =>
DoMakeFail(string.Empty, new [] { fail }, innerException);

internal delegate Exception NewFailedExpectationException(string context, FailedExpectation[] fails, Exception inner);

static NewFailedExpectationException DoMakeFail = (context, fail, inner) =>
(DoMakeFail = LateBindFailureException())(context, fail, inner);

static NewFailedExpectationException LateBindFailureException() {
var nunit = Type.GetType("NUnit.Framework.AssertionException, NUnit.Framework");
if (nunit == null)
return DefaultFail;

var fails = Expression.Parameter(typeof (IEnumerable<FailedExpectation>), "fails");
var innerException = Expression.Parameter(typeof (Exception), "innerException");

return Expression.Lambda<NewFailedExpectationException>(
Expression.New(nunit.GetConstructor(new [] {typeof (string), typeof (Exception)}),
Expression.Call(typeof (Check).GetMethod("FormatFailMessage", BindingFlags.Static | BindingFlags.NonPublic), fails),
innerException),
fails, innerException).Compile();
}
internal static Exception MakeFail(FailedExpectation fail, Exception innerException) =>
new CheckFailed(string.Empty, fail, innerException);

static Exception DefaultFail(string context, FailedExpectation[] fail, Exception innerException) =>
new CheckFailed(context, fail, innerException);
internal static Exception MakeFail(FailedExpectation[] fails, Exception innerException) =>
new CheckFailed(string.Empty, fails, innerException);

public static object That(Expression<Func<bool>> expr) {
var result = CheckExpect(expr.Body, ExpressionEvaluatorParameters.Empty);
if (result.IsSuccess)
return result.Value;
throw DoMakeFail(string.Empty, new [] { result.Error }, null);
throw MakeFail(result.Error, null);
}

public static void That(Expression<Func<bool>> expr, params Expression<Func<bool>>[] extras) {
Expand All @@ -91,7 +69,7 @@ public static bool IncludeGuide
internal static Exception Eval(IEnumerable<Expression<Func<bool>>> exprs) {
var failed = GetFailed(exprs, x => CheckExpect(x.Body, ExpressionEvaluatorParameters.Empty));
return failed.Length > 0
? DoMakeFail(string.Empty, failed, null)
? MakeFail(failed, null)
: null;
}

Expand Down Expand Up @@ -213,7 +191,7 @@ internal class CheckWith
CheckExpect(x.Body, ExpressionEvaluatorParameters.Create(x.Parameters, args));

Exception MakeFail(FailedExpectation[] failed) =>
DoMakeFail(formatContext(), failed, null);
new CheckFailed(formatContext(), failed, null);
}

public class CheckWith<T>
Expand Down Expand Up @@ -248,20 +226,9 @@ public static class Check<TException> where TException : Exception
}
}

class NotExpectedExpect : IExpect
//For those wanting to pre-warm their expectations.
public static class Batteries
{
readonly Expression expression;
readonly ConeMessage message;

public NotExpectedExpect(Expression expression, ConeMessage message) {
this.expression = expression;
this.message = message;
}

public CheckResult Check() => new CheckResult(false, Maybe<object>.None, Maybe<object>.None);

public string FormatExpression(IFormatter<Expression> formatter) => formatter.Format(expression);
public ConeMessage FormatMessage(IFormatter<object> formatter) => message;
public static void Included() => Check.Initialize();
}

}
File renamed without changes.
1 change: 1 addition & 0 deletions Source/Check.That/Expectations/ExpectFactory.cs
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using CheckThat;
using Cone.Core;

namespace Cone.Expectations
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions Source/Check.That/Helpers/MethodSpy.cs
@@ -1,10 +1,10 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Threading;
using static Cone.Check;
using static CheckThat.Check;

namespace Cone.Helpers
{
Expand Down
22 changes: 22 additions & 0 deletions Source/Check.That/NotExpectedExpect.cs
@@ -0,0 +1,22 @@
using System.Linq.Expressions;
using Cone.Core;
using Cone.Expectations;

namespace CheckThat
{
class NotExpectedExpect : IExpect
{
readonly Expression expression;
readonly ConeMessage message;

public NotExpectedExpect(Expression expression, ConeMessage message) {
this.expression = expression;
this.message = message;
}

public CheckResult Check() => new CheckResult(false, Maybe<object>.None, Maybe<object>.None);

public string FormatExpression(IFormatter<Expression> formatter) => formatter.Format(expression);
public ConeMessage FormatMessage(IFormatter<object> formatter) => message;
}
}
2 changes: 2 additions & 0 deletions Source/Cone.TestAdapter/ConeTestAdapterProxy.cs
Expand Up @@ -7,6 +7,8 @@
using Cone.Core;
using Cone.Runners;
using Newtonsoft.Json;
using CheckThat;


namespace Cone.TestAdapter
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Cone/Assume.cs
@@ -1,6 +1,6 @@
using System;
using System.Linq;
using System.Linq.Expressions;
using CheckThat;
using Cone.Expectations;

namespace Cone
Expand Down
3 changes: 2 additions & 1 deletion Source/Cone/ConePad.cs
@@ -1,10 +1,11 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Cone.Core;
using Cone.Runners;
using CheckThat;

namespace Cone
{
Expand Down
1 change: 1 addition & 0 deletions Source/Cone/Core/ConeTestFailure.cs
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Reflection;
using Cone.Runners;
using CheckThat;

namespace Cone.Core
{
Expand Down
4 changes: 2 additions & 2 deletions Source/Cone/Runners/SimpleConeRunner.cs
Expand Up @@ -41,7 +41,7 @@ public SimpleConeRunner(ITestNamer testNamer): this(testNamer, new DefaultFixtur
public int Workers = 1;

public void RunTests(ICollection<string> runList, TestSession results, IEnumerable<Assembly> assemblies) {
Check.Initialize();
CheckThat.Batteries.Included();
results.RunTests(CreateTestRun(
runList,
BuildFlatSuites(assemblies.SelectMany(AssemblyMethods.GetExportedTypes))
Expand Down Expand Up @@ -75,7 +75,7 @@ public SimpleConeRunner(ITestNamer testNamer): this(testNamer, new DefaultFixtur
RunTests(results, assemblies.SelectMany(AssemblyMethods.GetExportedTypes));

public void RunTests(TestSession results, IEnumerable<Type> suiteTypes) {
Check.Initialize();
CheckThat.Batteries.Included();
var toRun = BuildFlatSuites(suiteTypes)
.Where(x => results.IncludeSuite(x))
.ToList();
Expand Down
5 changes: 3 additions & 2 deletions Specs/Cone.Specs/BinaryExpectSpec.cs
@@ -1,12 +1,13 @@
using System;
using System;
using System.Linq.Expressions;
using CheckThat;
using Cone.Core;
using Cone.Expectations;
using Moq;

namespace Cone
{
[Describe(typeof(EqualExpect))]
[Describe(typeof(EqualExpect))]
public class BinaryExpectSpec
{
class WithOverloadedOperators<T>
Expand Down
3 changes: 2 additions & 1 deletion Specs/Cone.Specs/BooleanExpectSpec.cs
@@ -1,5 +1,6 @@
using System.Linq.Expressions;
using System.Linq.Expressions;
using Cone.Expectations;
using CheckThat;

namespace Cone
{
Expand Down
1 change: 1 addition & 0 deletions Specs/Cone.Specs/CheckSpec.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using CheckThat;

namespace Cone
{
Expand Down
3 changes: 2 additions & 1 deletion Specs/Cone.Specs/CheckWithSpec.cs
@@ -1,4 +1,5 @@
using System;
using System;
using CheckThat;

namespace Cone
{
Expand Down
3 changes: 2 additions & 1 deletion Specs/Cone.Specs/ConeFixtureSetupSpec.cs
@@ -1,10 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
using CheckThat;
using Cone.Core;
using Moq;


namespace Cone
{
class ConeFixtureMethods : IConeFixtureMethodSink
Expand Down
1 change: 1 addition & 0 deletions Specs/Cone.Specs/ConeTestNamerSpec.cs
@@ -1,6 +1,7 @@
using System;
using System.Linq.Expressions;
using System.Reflection;
using CheckThat;

namespace Cone.Core
{
Expand Down
4 changes: 2 additions & 2 deletions Specs/Cone.Specs/Conesole/ConesoleConfigurationSpec.cs
@@ -1,7 +1,7 @@
using System;
using CheckThat;
using Cone.Stubs;
using Cone.Worker;
using System;
using System.Configuration;

namespace Cone.Conesole
{
Expand Down
5 changes: 1 addition & 4 deletions Specs/Cone.Specs/Core/CircularQueueSpec.cs
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CheckThat;

namespace Cone.Core
{
Expand Down
3 changes: 2 additions & 1 deletion Specs/Cone.Specs/Core/ConeAttributeProviderSpec.cs
@@ -1,4 +1,5 @@
using System.Linq;
using System.Linq;
using CheckThat;

namespace Cone.Core
{
Expand Down
2 changes: 1 addition & 1 deletion Specs/Cone.Specs/Core/ConeFixtureMethodCollectionSpec.cs
@@ -1,6 +1,6 @@
using System;
using System.Linq.Expressions;
using System.Reflection;
using CheckThat;

namespace Cone.Core
{
Expand Down
2 changes: 1 addition & 1 deletion Specs/Cone.Specs/Core/ConeFixtureSpec.cs
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using Cone.Runners;
using CheckThat;
using Moq;

namespace Cone.Core
Expand Down
3 changes: 2 additions & 1 deletion Specs/Cone.Specs/Core/ConeTestFailureSpec.cs
@@ -1,5 +1,6 @@
using System;
using System;
using System.Reflection;
using CheckThat;

namespace Cone.Core
{
Expand Down
3 changes: 2 additions & 1 deletion Specs/Cone.Specs/Core/ConeTestNameSpec.cs
@@ -1,4 +1,5 @@

using CheckThat;

namespace Cone.Core
{
[Describe(typeof(ConeTestName))]
Expand Down
1 change: 1 addition & 0 deletions Specs/Cone.Specs/Core/InvokableSpec.cs
@@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using CheckThat;

namespace Cone.Core
{
Expand Down
3 changes: 2 additions & 1 deletion Specs/Cone.Specs/Core/MaybeSpec.cs
@@ -1,7 +1,8 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CheckThat;

namespace Cone.Core
{
Expand Down
3 changes: 2 additions & 1 deletion Specs/Cone.Specs/Core/MethodExpectProviderLookupSpec.cs
@@ -1,10 +1,11 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cone.Expectations;
using System.Linq.Expressions;
using System.Reflection;
using CheckThat;

namespace Cone.Core
{
Expand Down
4 changes: 1 addition & 3 deletions Specs/Cone.Specs/Core/MissingLinqSpec.cs
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CheckThat;

namespace Cone.Core
{
Expand Down
5 changes: 3 additions & 2 deletions Specs/Cone.Specs/Core/TestContextContextSpec.cs
@@ -1,10 +1,11 @@
using System;
using System;
using System.Linq;
using CheckThat;
using Moq;

namespace Cone.Core
{
[Describe(typeof(TestExecutionContext))]
[Describe(typeof(TestExecutionContext))]
public class TestContextContextSpec
{
class Fixture {
Expand Down
7 changes: 3 additions & 4 deletions Specs/Cone.Specs/Core/TypeFormatterSpec.cs
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using CheckThat;


namespace Cone.Core
{
Expand Down
3 changes: 2 additions & 1 deletion Specs/Cone.Specs/CustomMethodExpectFeature.cs
@@ -1,10 +1,11 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Cone.Core;
using Cone.Expectations;
using CheckThat;

namespace Cone
{
Expand Down

0 comments on commit 7e8d8a2

Please sign in to comment.