Skip to content

Commit 9f4a910

Browse files
authored
Merge pull request #261 from CaptnCodr/feature/cleanups
Solution cleanup
2 parents c6883d0 + 3651a5d commit 9f4a910

File tree

93 files changed

+241
-185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+241
-185
lines changed

build.fsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ let (|Fsproj|Csproj|Vbproj|) (projFileName: string) =
7272
| f when f.EndsWith("fsproj") -> Fsproj
7373
| f when f.EndsWith("csproj") -> Csproj
7474
| f when f.EndsWith("vbproj") -> Vbproj
75-
| _ -> failwith (sprintf "Project file %s not supported. Unknown project type." projFileName)
75+
| _ -> failwith $"Project file %s{projFileName} not supported. Unknown project type."
7676

7777
// Generate assembly info files with the right version & up-to-date information
7878
Target.create "AssemblyInfo" (fun _ ->
@@ -141,7 +141,7 @@ Target.create "CheckFormat" (fun _ ->
141141
elif result.ExitCode = 99 then
142142
failwith "Some files need formatting, check output for more info"
143143
else
144-
Trace.logf "Errors while formatting: %A" result.Errors)
144+
Trace.logf $"Errors while formatting: %A{result.Errors}")
145145

146146
Target.create "Format" (fun _ ->
147147
let result =
@@ -151,7 +151,7 @@ Target.create "Format" (fun _ ->
151151
|> DotNet.exec id "fantomas"
152152

153153
if not result.OK then
154-
printfn "Errors while formatting all files: %A" result.Messages)
154+
printfn $"Errors while formatting all files: %A{result.Messages}")
155155

156156
// --------------------------------------------------------------------------------------
157157
// Build library & test project
@@ -169,19 +169,19 @@ Target.create "NUnit" (fun _ ->
169169
let result = DotNet.exec id "test" "tests/FsUnit.NUnit.Test/"
170170

171171
if not result.OK then
172-
failwithf "NUnit test failed: %A" result.Errors)
172+
failwithf $"NUnit test failed: %A{result.Errors}")
173173

174174
Target.create "xUnit" (fun _ ->
175175
let result = DotNet.exec id "test" "tests/FsUnit.Xunit.Test/"
176176

177177
if not result.OK then
178-
failwithf "xUnit test failed: %A" result.Errors)
178+
failwithf $"xUnit test failed: %A{result.Errors}")
179179

180180
Target.create "MsTest" (fun _ ->
181181
let result = DotNet.exec id "test" "tests/FsUnit.MsTest.Test/"
182182

183183
if not result.OK then
184-
failwithf "MsTest test failed: %A" result.Errors)
184+
failwithf $"MsTest test failed: %A{result.Errors}")
185185

186186
Target.create "RunTests" ignore
187187

src/Common.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module Common =
2626
| _ -> None
2727

2828
/// <summary>
29-
/// Checks wether the given value is of the same case of a union type as the
29+
/// Checks whether the given value is of the same case of a union type as the
3030
/// case defined by the given expression.
3131
/// </summary>
3232
/// <exception cref="System.Exception">If the expression is not an union case or does not result in an union case.</exception>
@@ -37,7 +37,7 @@ module Common =
3737
| Lambda(_, expr)
3838
| Let(_, _, expr) -> isOfCase expr
3939
| NewUnionCase(case, _) ->
40-
// Returns a function that check wether the tag of the argument matches
40+
// Returns a function that check whether the tag of the argument matches
4141
// the tag of the union given in the expression.
4242
let readTag = FSharpValue.PreComputeUnionTagReader case.DeclaringType
4343

src/FsUnit.MsTestUnit/FsUnit.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ let inline private assertThat(actual, matcher: IMatcher<'a>) =
1414
raise(AssertFailedException($"%A{description} was %A{value}", null))
1515

1616
match box actual with
17-
| :? (unit -> unit) as actualfunc ->
17+
| :? (unit -> unit) as actualFunc ->
1818
(try
19-
actualfunc()
19+
actualFunc()
2020
String.Empty
2121
with ex ->
2222
ex.ToString())

src/FsUnit.NUnit/CustomConstraints.fs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,4 @@ module CustomConstraints =
1717
let result = Common.isOfCase this.Expected actual
1818
ConstraintResult(this, actual, result)
1919
else
20-
let actualType = actual.GetType()
21-
do printf $"Got a {actualType.Name}"
22-
failwith "Value (not expression) is not a union case."
20+
failwith $"Value (not expression) is not a union case. Got a {actual.GetType().Name}."

src/FsUnit.NUnit/FsUnitTyped.fs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ namespace FsUnitTyped
22

33
open System.Diagnostics
44
open NUnit.Framework
5-
open NUnit.Framework.Legacy
65

76
[<AutoOpen>]
87
module TopLevelOperators =
@@ -17,35 +16,35 @@ module TopLevelOperators =
1716

1817
[<DebuggerStepThrough>]
1918
let shouldContain (expected: 'a) (actual: 'a seq) =
20-
CollectionAssert.Contains(actual, expected)
19+
Assert.That(actual, Does.Contain(expected))
2120

2221
[<DebuggerStepThrough>]
2322
let shouldBeEmpty(actual: 'a seq) =
24-
ClassicAssert.IsEmpty(actual)
23+
Assert.That(actual, Is.Empty)
2524

2625
[<DebuggerStepThrough>]
2726
let shouldNotContain (expected: 'a) (actual: 'a seq) =
28-
CollectionAssert.DoesNotContain(actual, expected, $"Seq %A{actual} should not contain %A{expected}")
27+
Assert.That(actual, Does.Not.Contain(expected), $"Seq %A{actual} should not contain %A{expected}")
2928

3029
[<DebuggerStepThrough>]
3130
let shouldBeSmallerThan (expected: 'a) (actual: 'a) =
32-
ClassicAssert.Less(actual, expected)
31+
Assert.That(actual, Is.LessThan(expected))
3332

3433
[<DebuggerStepThrough>]
3534
let shouldBeGreaterThan (expected: 'a) (actual: 'a) =
36-
ClassicAssert.Greater(actual, expected)
35+
Assert.That(actual, Is.GreaterThan(expected))
3736

3837
[<DebuggerStepThrough>]
3938
let shouldFail<'exn when 'exn :> exn>(f: unit -> unit) =
4039
Assert.Throws(Is.InstanceOf<'exn>(), TestDelegate(f)) |> ignore
4140

4241
[<DebuggerStepThrough>]
4342
let shouldContainText (expected: string) (actual: string) =
44-
StringAssert.Contains(expected, actual)
43+
Assert.That(actual, Does.Contain(expected))
4544

4645
[<DebuggerStepThrough>]
4746
let shouldNotContainText (expected: string) (actual: string) =
48-
StringAssert.DoesNotContain(expected, actual)
47+
Assert.That(actual, Does.Not.Contain(expected))
4948

5049
[<DebuggerStepThrough>]
5150
let shouldHaveLength (expected: int) actual =

src/FsUnit.Xunit/CustomMatchers.fs

Lines changed: 40 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ let equalWithin (tolerance: obj) (expected: obj) =
4040
let matches(actual: obj) =
4141
let parseValue(v: string) =
4242
match Double.TryParse(v, NumberStyles.Any, CultureInfo("en-US")) with
43-
| (true, x) -> Some(x)
44-
| (false, _) -> None
43+
| true, x -> Some(x)
44+
| false, _ -> None
4545

4646
let actual = string actual |> parseValue
4747
let expect = string expected |> parseValue
@@ -185,10 +185,10 @@ let instanceOfType<'a> =
185185
let contain expected =
186186
let matches(actual: obj) =
187187
match actual with
188-
| :? (list<_>) as l -> l |> List.exists(fun i -> i = expected)
189-
| :? (array<_>) as a -> a |> Array.exists(fun i -> i = expected)
190-
| :? (seq<_>) as s -> s |> Seq.exists(fun i -> i = expected)
191-
| :? IEnumerable as e -> e |> Seq.cast |> Seq.exists(fun i -> i = expected)
188+
| :? list<_> as l -> l |> List.exists((=) expected)
189+
| :? array<_> as a -> a |> Array.exists((=) expected)
190+
| :? seq<_> as s -> s |> Seq.exists((=) expected)
191+
| :? IEnumerable as e -> e |> Seq.cast |> Seq.exists((=) expected)
192192
| _ -> false
193193

194194
CustomMatcher<obj>($"Contains %A{expected}", Func<_, _> matches)
@@ -213,17 +213,6 @@ let haveLength expected =
213213
let haveCount expected =
214214
CustomMatcher<obj>($"Have Count %d{expected}", (fun x -> x?Count = expected))
215215

216-
let containf f =
217-
let matches(actual: obj) =
218-
match actual with
219-
| :? (list<_>) as l -> l |> List.exists f
220-
| :? (array<_>) as a -> a |> Array.exists f
221-
| :? (seq<_>) as s -> s |> Seq.exists f
222-
| :? IEnumerable as e -> e |> Seq.cast |> Seq.exists f
223-
| _ -> false
224-
225-
CustomMatcher<obj>($"Contains %A{f}", Func<_, _> matches)
226-
227216
let supersetOf expected =
228217
CustomMatcher<obj>($"Is superset of %A{expected}", (fun c -> Set.isSuperset (Set(unbox c)) (Set expected)))
229218

@@ -233,7 +222,7 @@ let subsetOf expected =
233222
let matchList xs =
234223
let matches(ys: obj) =
235224
match ys with
236-
| :? (list<_>) as ys' -> List.sort xs = List.sort ys'
225+
| :? list<_> as ys' -> List.sort xs = List.sort ys'
237226
| :? IEnumerable as e -> e |> Seq.cast |> Seq.isEmpty && xs |> Seq.isEmpty
238227
| _ -> false
239228

@@ -242,9 +231,9 @@ let matchList xs =
242231
let private makeOrderedMatcher description comparer =
243232
let matches(actual: obj) =
244233
match actual with
245-
| :? (list<IComparable>) as l -> l = List.sortWith comparer l
246-
| :? (array<IComparable>) as a -> a = Array.sortWith comparer a
247-
| :? (seq<IComparable>) as s ->
234+
| :? list<IComparable> as l -> l = List.sortWith comparer l
235+
| :? array<IComparable> as a -> a = Array.sortWith comparer a
236+
| :? seq<IComparable> as s ->
248237
let a = s |> Seq.toArray
249238
a = (a |> Array.sortWith comparer)
250239
| :? IEnumerable as e ->
@@ -262,52 +251,51 @@ type ChoiceDiscriminator(n: int) =
262251

263252
member this.check(c: Choice<'a, 'b>) : bool =
264253
match c with
265-
| Choice1Of2(_) -> n = 1
266-
| Choice2Of2(_) -> n = 2
254+
| Choice1Of2 _ -> n = 1
255+
| Choice2Of2 _ -> n = 2
267256

268257
member this.check(c: Choice<'a, 'b, 'c>) : bool =
269258
match c with
270-
| Choice1Of3(_) -> n = 1
271-
| Choice2Of3(_) -> n = 2
272-
| Choice3Of3(_) -> n = 3
259+
| Choice1Of3 _ -> n = 1
260+
| Choice2Of3 _ -> n = 2
261+
| Choice3Of3 _ -> n = 3
273262

274263
member this.check(c: Choice<'a, 'b, 'c, 'd>) : bool =
275264
match c with
276-
| Choice1Of4(_) -> n = 1
277-
| Choice2Of4(_) -> n = 2
278-
| Choice3Of4(_) -> n = 3
279-
| Choice4Of4(_) -> n = 4
265+
| Choice1Of4 _ -> n = 1
266+
| Choice2Of4 _ -> n = 2
267+
| Choice3Of4 _ -> n = 3
268+
| Choice4Of4 _ -> n = 4
280269

281270
member this.check(c: Choice<'a, 'b, 'c, 'd, 'e>) : bool =
282271
match c with
283-
| Choice1Of5(_) -> n = 1
284-
| Choice2Of5(_) -> n = 2
285-
| Choice3Of5(_) -> n = 3
286-
| Choice4Of5(_) -> n = 4
287-
| Choice5Of5(_) -> n = 5
272+
| Choice1Of5 _ -> n = 1
273+
| Choice2Of5 _ -> n = 2
274+
| Choice3Of5 _ -> n = 3
275+
| Choice4Of5 _ -> n = 4
276+
| Choice5Of5 _ -> n = 5
288277

289278
member this.check(c: Choice<'a, 'b, 'c, 'd, 'e, 'f>) : bool =
290279
match c with
291-
| Choice1Of6(_) -> n = 1
292-
| Choice2Of6(_) -> n = 2
293-
| Choice3Of6(_) -> n = 3
294-
| Choice4Of6(_) -> n = 4
295-
| Choice5Of6(_) -> n = 5
296-
| Choice6Of6(_) -> n = 6
280+
| Choice1Of6 _ -> n = 1
281+
| Choice2Of6 _ -> n = 2
282+
| Choice3Of6 _ -> n = 3
283+
| Choice4Of6 _ -> n = 4
284+
| Choice5Of6 _ -> n = 5
285+
| Choice6Of6 _ -> n = 6
297286

298287
member this.check(c: Choice<'a, 'b, 'c, 'd, 'e, 'f, 'g>) : bool =
299288
match c with
300-
| Choice1Of7(_) -> n = 1
301-
| Choice2Of7(_) -> n = 2
302-
| Choice3Of7(_) -> n = 3
303-
| Choice4Of7(_) -> n = 4
304-
| Choice5Of7(_) -> n = 5
305-
| Choice6Of7(_) -> n = 6
306-
| Choice7Of7(_) -> n = 7
289+
| Choice1Of7 _ -> n = 1
290+
| Choice2Of7 _ -> n = 2
291+
| Choice3Of7 _ -> n = 3
292+
| Choice4Of7 _ -> n = 4
293+
| Choice5Of7 _ -> n = 5
294+
| Choice6Of7 _ -> n = 6
295+
| Choice7Of7 _ -> n = 7
307296

308297
member this.check(c: obj) : bool =
309-
let cType = c.GetType()
310-
let cArgs = cType.GetGenericArguments()
298+
let cArgs = c.GetType().GetGenericArguments()
311299
let cArgCount = Seq.length cArgs
312300

313301
try
@@ -318,7 +306,7 @@ type ChoiceDiscriminator(n: int) =
318306
false
319307

320308
let choice n =
321-
CustomMatcher<obj>($"The choice %d{n}", (fun x -> (ChoiceDiscriminator(n)).check(x)))
309+
CustomMatcher<obj>($"The choice %d{n}", (fun x -> ChoiceDiscriminator(n).check(x)))
322310

323311
let inRange min max =
324312
let matches(actual: obj) =
@@ -329,8 +317,7 @@ let inRange min max =
329317

330318
let ofCase(case: Quotations.Expr) =
331319
let expected =
332-
case |> Common.caseName |> defaultArg
333-
<| "<The given type is not a union case and the matcher won't work.>"
320+
defaultArg (Common.caseName case) "<The given type is not a union case and the matcher won't work.>"
334321

335322
let matcher = CustomMatcher(expected, (fun x -> x |> Common.isOfCase case))
336323

src/FsUnit.Xunit/FsUnit.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ open Xunit.Sdk
66
open NHamcrest
77
open NHamcrest.Core
88

9-
type Xunit.Assert with
9+
type Assert with
1010

1111
static member That<'a>(actual, matcher: IMatcher<'a>) =
1212
if not(matcher.Matches(actual)) then
@@ -17,9 +17,9 @@ type Xunit.Assert with
1717
raise(EqualException.ForMismatchedValues(description.ToString(), value))
1818

1919
match box actual with
20-
| :? (unit -> unit) as actualfunc ->
20+
| :? (unit -> unit) as actualFunc ->
2121
(try
22-
actualfunc()
22+
actualFunc()
2323
String.Empty
2424
with ex ->
2525
ex.ToString())

src/FsUnit.Xunit/FsUnitTyped.fs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@ open FsUnit.Xunit
77
[<AutoOpen>]
88
module TopLevelOperators =
99

10-
/// Asserts that `expected` is equal to `actual`.
11-
/// The equality instance on `actual` is used, if available.
1210
[<DebuggerStepThrough>]
1311
let shouldEqual<'a> (expected: 'a) (actual: 'a) =
1412
actual |> should equal expected
1513

16-
/// Asserts that `expected` is not equal to `actual`.
17-
/// The equality instance on `actual` is used, if available.
1814
[<DebuggerStepThrough>]
1915
let shouldNotEqual<'a> (expected: 'a) (actual: 'a) =
2016
actual |> should not' (equal expected)

tests/FsUnit.MsTest.Test/FsUnit.MsTest.Test.fsproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
66
</PropertyGroup>
77
<ItemGroup>
8-
<Compile Include="ofCaseTests.fs" />
8+
<Compile Include="beOfCaseTests.fs" />
99
<Compile Include="beAscendingTests.fs" />
1010
<Compile Include="beChoiceTests.fs" />
1111
<Compile Include="beDescendingTests.fs" />
@@ -37,7 +37,7 @@
3737
<Compile Include="startWithTests.fs" />
3838
<Compile Include="haveSubstringTests.fs" />
3939
<Compile Include="instanceOfTests.fs" />
40-
<Compile Include="NaNTests.fs" />
40+
<Compile Include="beNaNTests.fs" />
4141
<Compile Include="beUniqueTests.fs" />
4242
<None Include="paket.references" />
4343
<None Include="MSTest.runsettings" />

tests/FsUnit.MsTest.Test/NaNTests.fs renamed to tests/FsUnit.MsTest.Test/beNaNTests.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ open FsUnit.MsTest
55
open System
66

77
[<TestClass>]
8-
type ``NotANumberTests``() =
8+
type ``beNaNTests``() =
99

1010
[<TestMethod>]
1111
member _.``Number 1 should be a number``() =

tests/FsUnit.MsTest.Test/ofCaseTests.fs renamed to tests/FsUnit.MsTest.Test/beOfCaseTests.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type TestUnion =
99
| Third of string
1010

1111
[<TestClass>]
12-
type ``ofCaseTests``() =
12+
type ``beOfCaseTests``() =
1313

1414
[<TestMethod>]
1515
member _.``Given a (parameterless) union case of matching case returns true``() =

tests/FsUnit.MsTest.Test/beUniqueTests.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ open Microsoft.VisualStudio.TestTools.UnitTesting
44
open FsUnit.MsTest
55

66
[<TestClass>]
7-
type ``haveUniqueTests``() =
7+
type ``beUniqueTests``() =
88

99
[<TestMethod>]
1010
member _.``empty list should be considered as unique``() =

0 commit comments

Comments
 (0)