Skip to content

Update fantomas #217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
]
},
"fsdocs-tool": {
"version": "15.0.1",
"version": "16.1.1",
"commands": [
"fsdocs"
]
},
"fantomas-tool": {
"version": "4.7.9",
"fantomas": {
"version": "5.0.0",
"commands": [
"fantomas"
]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
os: [windows-latest, macOS-latest, ubuntu-latest]
dotnet: [6.0.400]
dotnet: [6.0.401]
runs-on: ${{ matrix.os }}

steps:
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.400",
"version": "6.0.401",
"rollForward": "minor"
}
}
9 changes: 5 additions & 4 deletions src/FsUnit.MsTestUnit/FsUnit.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ let inline private assertThat(actual, matcher: IMatcher<'a>) =
(try
actualfunc()
String.Empty
with
| ex -> ex.ToString())
with ex ->
ex.ToString())
|> raiseAssertFailedException
| _ -> actual |> raiseAssertFailedException

type Assert with

static member That<'a>(actual, matcher: IMatcher<'a>) =
assertThat(actual, matcher)

Expand All @@ -45,8 +46,8 @@ let inline shouldFail(f: unit -> unit) =
try
f()
false
with
| _ -> true
with _ ->
true

if not failed then
raise(AssertFailedException("Method should fail"))
Expand Down
12 changes: 2 additions & 10 deletions src/FsUnit.NUnit/Equality.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,8 @@ type Equality<'T when 'T: equality> =

static member inline IsEqualTo(x: 'T) =
match (box x) with
| :? IStructuralEquatable ->
Is
.EqualTo(x)
.Or.EqualTo(x)
.Using<'T>(Equality.Structural)
| :? IStructuralComparable ->
Is
.EqualTo(x)
.Or.EqualTo(x)
.Using<'T>(Equality.StructuralC)
| :? IStructuralEquatable -> Is.EqualTo(x).Or.EqualTo(x).Using<'T>(Equality.Structural)
| :? IStructuralComparable -> Is.EqualTo(x).Or.EqualTo(x).Using<'T>(Equality.StructuralC)
| _ -> Is.EqualTo(x)

static member IsNotEqualTo(x: 'T) =
Expand Down
22 changes: 11 additions & 11 deletions src/FsUnit.NUnit/GenericAssert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type Assert =
/// <param name="actual">The actual value.</param>
/// <param name="message">The message to display in case of failure.</param>
/// <param name="args">Array of objects to be used in formatting the message.</param>
static member AreEqual<'T when 'T: equality>(expected: 'T, actual: 'T, message: string, [<ParamArray>] args: obj []) : unit =
static member AreEqual<'T when 'T: equality>(expected: 'T, actual: 'T, message: string, [<ParamArray>] args: obj[]) : unit =
let eqConstraint = Equality.IsEqualTo(expected)
Assert.That(actual, eqConstraint, message, args)

Expand Down Expand Up @@ -71,7 +71,7 @@ type Assert =
/// <param name="actual">The actual value.</param>
/// <param name="message">The message to display in case of failure.</param>
/// <param name="args">Array of objects to be used in formatting the message.</param>
static member AreNotEqual<'T when 'T: equality>(expected: 'T, actual: 'T, message: string, [<ParamArray>] args: obj []) : unit =
static member AreNotEqual<'T when 'T: equality>(expected: 'T, actual: 'T, message: string, [<ParamArray>] args: obj[]) : unit =
let neqConstraint = Equality.IsNotEqualTo(expected)
Assert.That(actual, neqConstraint, message, args)

Expand Down Expand Up @@ -104,7 +104,7 @@ type Assert =
/// <param name="actual">The actual object.</param>
/// <param name="message">The message to display in case of failure.</param>
/// <param name="args">Array of objects to be used in formatting the message.</param>
static member AreNotSame<'T when 'T: not struct>(expected: 'T, actual: 'T, message: string, [<ParamArray>] args: obj []) : unit =
static member AreNotSame<'T when 'T: not struct>(expected: 'T, actual: 'T, message: string, [<ParamArray>] args: obj[]) : unit =
let sameConstraint = Is.Not.SameAs expected
Assert.That(actual, sameConstraint, message, args)

Expand Down Expand Up @@ -137,7 +137,7 @@ type Assert =
/// <param name="actual">The actual object.</param>
/// <param name="message">The message to display in case of failure.</param>
/// <param name="args">Array of objects to be used in formatting the message.</param>
static member AreSame<'T when 'T: not struct>(expected: 'T, actual: 'T, message: string, [<ParamArray>] args: obj []) : unit =
static member AreSame<'T when 'T: not struct>(expected: 'T, actual: 'T, message: string, [<ParamArray>] args: obj[]) : unit =
let sameConstraint = Is.SameAs expected
Assert.That(actual, sameConstraint, message, args)

Expand Down Expand Up @@ -169,7 +169,7 @@ type Assert =
/// <param name="actual">The list to be examined.</param>
/// <param name="message">The message to display in case of failure.</param>
/// <param name="args">Array of objects to be used in formatting the message.</param>
static member Contains<'T when 'T: equality>(expected: 'T, actual: IEnumerable<'T>, message: string, [<ParamArray>] args: obj []) : unit =
static member Contains<'T when 'T: equality>(expected: 'T, actual: IEnumerable<'T>, message: string, [<ParamArray>] args: obj[]) : unit =
let eqConstraint = Equality.IsEqualTo(expected)
let containsConstraint = SomeItemsConstraint(eqConstraint)
Assert.That(actual, containsConstraint, message, args)
Expand Down Expand Up @@ -201,7 +201,7 @@ type Assert =
/// <param name="arg2">The second value, expected to be less.</param>
/// <param name="message">The message to display in case of failure.</param>
/// <param name="args">Array of objects to be used in formatting the message.</param>
static member Greater<'T when 'T: comparison>(arg1: 'T, arg2: 'T, message: string, [<ParamArray>] args: obj []) : unit =
static member Greater<'T when 'T: comparison>(arg1: 'T, arg2: 'T, message: string, [<ParamArray>] args: obj[]) : unit =
Assert.That(arg1, Is.GreaterThan arg2, message, args)

/// <summary>
Expand Down Expand Up @@ -231,7 +231,7 @@ type Assert =
/// <param name="arg2">The second value, expected to be less.</param>
/// <param name="message">The message to display in case of failure.</param>
/// <param name="args">Array of objects to be used in formatting the message.</param>
static member GreaterOrEqual<'T when 'T: comparison>(arg1: 'T, arg2: 'T, message: string, [<ParamArray>] args: obj []) : unit =
static member GreaterOrEqual<'T when 'T: comparison>(arg1: 'T, arg2: 'T, message: string, [<ParamArray>] args: obj[]) : unit =
Assert.That(arg1, Is.GreaterThanOrEqualTo arg2, message, args)

/// <summary>
Expand Down Expand Up @@ -261,7 +261,7 @@ type Assert =
/// <param name="arg2">The second value, expected to be greater.</param>
/// <param name="message">The message to display in case of failure.</param>
/// <param name="args">Array of objects to be used in formatting the message.</param>
static member Less<'T when 'T: comparison>(arg1: 'T, arg2: 'T, message: string, [<ParamArray>] args: obj []) : unit =
static member Less<'T when 'T: comparison>(arg1: 'T, arg2: 'T, message: string, [<ParamArray>] args: obj[]) : unit =
Assert.That(arg1, Is.LessThan arg2, message, args)

/// <summary>
Expand Down Expand Up @@ -291,7 +291,7 @@ type Assert =
/// <param name="arg2">The second value, expected to be greater.</param>
/// <param name="message">The message to display in case of failure.</param>
/// <param name="args">Array of objects to be used in formatting the message.</param>
static member LessOrEqual<'T when 'T: comparison>(arg1: 'T, arg2: 'T, message: string, [<ParamArray>] args: obj []) : unit =
static member LessOrEqual<'T when 'T: comparison>(arg1: 'T, arg2: 'T, message: string, [<ParamArray>] args: obj[]) : unit =
Assert.That(arg1, Is.LessThanOrEqualTo arg2, message, args)

/// <summary>
Expand All @@ -318,7 +318,7 @@ type Assert =
/// <param name="arg">The object that is to be tested.</param>
/// <param name="message">The message to display in case of failure.</param>
/// <param name="args">Array of objects to be used in formatting the message.</param>
static member NotNull<'T when 'T: not struct>(arg: 'T, message: string, [<ParamArray>] args: obj []) : unit =
static member NotNull<'T when 'T: not struct>(arg: 'T, message: string, [<ParamArray>] args: obj[]) : unit =
Assert.That(arg, Is.Not.Null, message, args)

/// <summary>
Expand All @@ -345,5 +345,5 @@ type Assert =
/// <param name="arg">The object that is to be tested.</param>
/// <param name="message">The message to display in case of failure.</param>
/// <param name="args">Array of objects to be used in formatting the message.</param>
static member Null<'T when 'T: not struct>(arg: 'T, message: string, [<ParamArray>] args: obj []) : unit =
static member Null<'T when 'T: not struct>(arg: 'T, message: string, [<ParamArray>] args: obj[]) : unit =
Assert.That(arg, Is.Null, message, args)
16 changes: 8 additions & 8 deletions src/FsUnit.Xunit/CustomMatchers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ let equivalent f expected =
f (toCollection expected) (toCollection e)
true
| _ -> false
with
| _ -> false
with _ ->
false

CustomMatcher<obj>($"Equivalent to %A{expected}", Func<_, _> matches)

Expand Down Expand Up @@ -57,8 +57,8 @@ let throw(t: Type) =
try
testFunc()
false
with
| ex -> t.IsAssignableFrom(ex.GetType())
with ex ->
t.IsAssignableFrom(ex.GetType())
| _ -> false

CustomMatcher<obj>(string t, Func<_, _> matches)
Expand All @@ -70,8 +70,8 @@ let throwWithMessage (m: string) (t: Type) =
try
testFunc()
false
with
| ex -> ex.GetType() = t && ex.Message = m
with ex ->
ex.GetType() = t && ex.Message = m
| _ -> false

CustomMatcher<obj>($"{string t} \"{m}\"", Func<_, _> matches)
Expand Down Expand Up @@ -298,8 +298,8 @@ type ChoiceDiscriminator(n: int) =
this.GetType().GetMethods()
|> Seq.filter(fun m -> m.Name = "check" && Seq.length(m.GetGenericArguments()) = cArgCount)
|> Seq.exists(fun m -> m.MakeGenericMethod(cArgs).Invoke(this, [| c |]) :?> bool)
with
| _ -> false
with _ ->
false

let choice n =
CustomMatcher<obj>($"The choice %d{n}", (fun x -> (ChoiceDiscriminator(n)).check(x)))
Expand Down
9 changes: 5 additions & 4 deletions src/FsUnit.Xunit/FsUnit.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type MatchException(expected, actual, userMessage) =
inherit AssertActualExpectedException(expected, actual, userMessage)

type Xunit.Assert with

static member That<'a>(actual, matcher: IMatcher<'a>) =
if not(matcher.Matches(actual)) then
let description = StringDescription()
Expand All @@ -23,8 +24,8 @@ type Xunit.Assert with
(try
actualfunc()
String.Empty
with
| ex -> ex.ToString())
with ex ->
ex.ToString())
|> raiseMatchException
| _ -> $"%A{actual}" |> raiseMatchException

Expand All @@ -46,8 +47,8 @@ let inline shouldFail(f: unit -> unit) =
try
f()
false
with
| _ -> true
with _ ->
true

if not failed then
raise(MatchException("Method should fail", "No exception raised", null))
Expand Down
6 changes: 3 additions & 3 deletions tests/FsUnit.MsTest.Test/raiseTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ type ``raise tests``() =

[<TestMethod>]
member _.``should fail when exception of expected type with unexpected message is thrown``() =
shouldFail (fun () ->
shouldFail(fun () ->
(fun () -> raise(ApplicationException "BOOM!") |> ignore)
|> should (throwWithMessage "CRASH!") typeof<ApplicationException>)

[<TestMethod>]
member _.``should fail when exception of unexpected type with expected message is thrown``() =
shouldFail (fun () ->
shouldFail(fun () ->
let msg = "BOOM!"

(fun () -> raise(ApplicationException msg) |> ignore)
|> should (throwWithMessage msg) typeof<ArgumentException>)

[<TestMethod>]
member _.``should fail when negated and exception of expected type with expected message is thrown``() =
shouldFail (fun () ->
shouldFail(fun () ->
let msg = "BOOM!"

(fun () -> raise(ApplicationException msg) |> ignore)
Expand Down
10 changes: 5 additions & 5 deletions tests/FsUnit.NUnit.Test/raiseTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ type ``raise tests``() =

[<Test>]
member _.``should fail when negated and exception is thrown``() =
shouldFail (fun () ->
shouldFail(fun () ->
(fun () -> raise TestException |> ignore)
|> should not' (throw typeof<TestException>))

[<Test>]
member _.``should fail when exception thrown is not the type expected``() =
shouldFail (fun () ->
shouldFail(fun () ->
(fun () -> raise TestException |> ignore)
|> should throw typeof<ApplicationException>)

Expand All @@ -45,21 +45,21 @@ type ``raise tests``() =

[<Test>]
member _.``should fail when exception of expected type with unexpected message is thrown``() =
shouldFail (fun () ->
shouldFail(fun () ->
(fun () -> raise(ApplicationException "BOOM!") |> ignore)
|> should (throwWithMessage "CRASH!") typeof<ApplicationException>)

[<Test>]
member _.``should fail when exception of unexpected type with expected message is thrown``() =
shouldFail (fun () ->
shouldFail(fun () ->
let msg = "BOOM!"

(fun () -> raise(ApplicationException msg) |> ignore)
|> should (throwWithMessage msg) typeof<ArgumentException>)

[<Test>]
member _.``should fail when negated and exception of expected type with expected message is thrown``() =
shouldFail (fun () ->
shouldFail(fun () ->
let msg = "BOOM!"

(fun () -> raise(ApplicationException msg) |> ignore)
Expand Down
6 changes: 3 additions & 3 deletions tests/FsUnit.Xunit.Test/raiseTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ type ``raise tests``() =

[<Fact>]
member _.``should fail when exception of expected type with unexpected message is thrown``() =
shouldFail (fun () ->
shouldFail(fun () ->
(fun () -> raise(ApplicationException "BOOM!") |> ignore)
|> should (throwWithMessage "CRASH!") typeof<ApplicationException>)

[<Fact>]
member _.``should fail when exception of unexpected type with expected message is thrown``() =
shouldFail (fun () ->
shouldFail(fun () ->
let msg = "BOOM!"

(fun () -> raise(ApplicationException msg) |> ignore)
|> should (throwWithMessage msg) typeof<ArgumentException>)

[<Fact>]
member _.``should fail when negated and exception of expected type with expected message is thrown``() =
shouldFail (fun () ->
shouldFail(fun () ->
let msg = "BOOM!"

(fun () -> raise(ApplicationException msg) |> ignore)
Expand Down