Skip to content

Commit

Permalink
Simplify Dependencies a tad (#18236)
Browse files Browse the repository at this point in the history
* simplify tests dependencies

* OverallHintExperienceTests
  • Loading branch information
KevinRansom authored Jan 16, 2025
1 parent 8473ce6 commit 7c598f4
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 43 deletions.
1 change: 0 additions & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@
<XUnitVersion>2.9.0</XUnitVersion>
<XUnitRunnerVersion>2.8.2</XUnitRunnerVersion>
<XunitXmlTestLoggerVersion>3.1.17</XunitXmlTestLoggerVersion>
<FluentAssertionsVersion>5.10.3</FluentAssertionsVersion>
<HumanizerCoreVersion>2.2.0</HumanizerCoreVersion>
<!-- -->
<!-- MIBC profile packages -->
Expand Down
17 changes: 8 additions & 9 deletions tests/FSharp.Compiler.Service.Tests/FsiTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

open System
open System.IO
open FluentAssertions
open FSharp.Compiler.Interactive.Shell
open FSharp.Test
open Xunit
Expand Down Expand Up @@ -575,7 +574,7 @@ module FsiTests =
fsiSession.AddBoundValue("boundMdArray", arr)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe typeof<int[]> boundValue.Value.ReflectionType
boundValue.Value.ReflectionValue.Should().Be(arr, "") |> ignore
Assert.shouldBe arr boundValue.Value.ReflectionValue

[<Fact>]
let ``Creation of a bound value succeeds if the value is an array of a built-in reference type``() =
Expand All @@ -584,7 +583,7 @@ module FsiTests =
fsiSession.AddBoundValue("boundMdArray", arr)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe typeof<string[]> boundValue.Value.ReflectionType
boundValue.Value.ReflectionValue.Should().Be(arr, "") |> ignore
Assert.shouldBe arr boundValue.Value.ReflectionValue

[<Fact>]
let ``Creation of a bound value succeeds if the value is an array of a custom value type``() =
Expand All @@ -593,7 +592,7 @@ module FsiTests =
fsiSession.AddBoundValue("boundMdArray", arr)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe typeof<CustomStruct[]> boundValue.Value.ReflectionType
boundValue.Value.ReflectionValue.Should().Be(arr, "") |> ignore
Assert.shouldBe arr boundValue.Value.ReflectionValue

[<Fact>]
let ``Creation of a bound value succeeds if the value is an array of a custom reference type``() =
Expand All @@ -602,7 +601,7 @@ module FsiTests =
fsiSession.AddBoundValue("boundMdArray", arr)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe typeof<CustomType2[]> boundValue.Value.ReflectionType
boundValue.Value.ReflectionValue.Should().Be(arr, "") |> ignore
Assert.shouldBe arr boundValue.Value.ReflectionValue

[<Fact>]
let ``Creation of a bound value succeeds if the value is a multidimensional array of a built-in value type``() =
Expand All @@ -611,7 +610,7 @@ module FsiTests =
fsiSession.AddBoundValue("boundMdArray", mdArr)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe typeof<int[,]> boundValue.Value.ReflectionType
boundValue.Value.ReflectionValue.Should().Be(mdArr, "") |> ignore
Assert.shouldBe mdArr boundValue.Value.ReflectionValue

[<Fact>]
let ``Creation of a bound value succeeds if the value is a multidimensional array of a built-in reference type``() =
Expand All @@ -620,7 +619,7 @@ module FsiTests =
fsiSession.AddBoundValue("boundMdArray", mdArr)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe typeof<string[,]> boundValue.Value.ReflectionType
boundValue.Value.ReflectionValue.Should().Be(mdArr, "") |> ignore
Assert.shouldBe mdArr boundValue.Value.ReflectionValue

[<Fact>]
let ``Creation of a bound value succeeds if the value is a multidimensional array of a custom value type``() =
Expand All @@ -629,7 +628,7 @@ module FsiTests =
fsiSession.AddBoundValue("boundMdArray", mdArr)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe typeof<CustomStruct[,]> boundValue.Value.ReflectionType
boundValue.Value.ReflectionValue.Should().Be(mdArr, "") |> ignore
Assert.shouldBe mdArr boundValue.Value.ReflectionValue

[<Fact>]
let ``Creation of a bound value succeeds if the value is a multidimensional array of a custom reference type``() =
Expand All @@ -638,7 +637,7 @@ module FsiTests =
fsiSession.AddBoundValue("boundMdArray", mdArr)
let boundValue = fsiSession.GetBoundValues() |> List.exactlyOne
Assert.shouldBe typeof<CustomType2[,]> boundValue.Value.ReflectionType
boundValue.Value.ReflectionValue.Should().Be(mdArr, "") |> ignore
Assert.shouldBe mdArr boundValue.Value.ReflectionValue

[<TheoryForNETCOREAPP>]
[<InlineData(true)>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ type ManglingNamesOfProvidedTypesWithSingleParameter() =
member this.DemangleDefaultValue() =
let name, parameters = PrettyNaming.DemangleProvidedTypeName "MyNamespace.Test,"
Assert.shouldBe "MyNamespace.Test" name
Assert.shouldBeEquivalentTo [||] parameters
Assert.shouldBeEmpty parameters

[<Fact>]
member this.DemangleNewDefaultValue() =
let name, parameters = PrettyNaming.DemangleProvidedTypeName "MyNamespace.Test"
Assert.shouldBe "MyNamespace.Test" name
Assert.shouldBeEquivalentTo [||] parameters
Assert.shouldBeEmpty parameters


type ManglingNamesOfProvidedTypesWithMultipleParameter() =
Expand Down
2 changes: 1 addition & 1 deletion tests/FSharp.Compiler.Service.Tests/SuggestionBuffer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module SuggestionBuffer =
let results = Array.ofSeq buffer

Assert.shouldBeTrue buffer.Disabled
Assert.shouldBeEquivalentTo [||] results
Assert.shouldBeEmpty results

[<Fact>]
let BufferShouldOnlyTakeTop5Elements() =
Expand Down
37 changes: 18 additions & 19 deletions tests/FSharp.Test.Utilities/Assert.fs
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
namespace FSharp.Test

module Assert =
open FluentAssertions
open System.Collections
open Xunit
open System.IO

// Equivalent, with message
let inline shouldBeEqualWith (expected : ^T) (message: string) (actual: ^U) =
actual.Should().BeEquivalentTo(expected, message) |> ignore
try
Assert.Equivalent(expected, actual)
with e ->
Assert.True(false, message);

let inline shouldBeEquivalentTo (expected : ^T) (actual : ^U) =
actual.Should().BeEquivalentTo(expected, "") |> ignore

let inline shouldStartWith (expected : string) (actual : string) =
actual.Should().StartWith(expected) |> ignore

let inline shouldContain (needle : string) (haystack : string) =
haystack.Should().Contain(needle) |> ignore
Assert.Equivalent(expected, actual)

// One fine day, all of the 3 things below should be purged and replaced with pure Assert.Equal.
// Xunit checks types by default. These are just artifacts of the testing chaos in the repo back in a day.
let inline shouldBe (expected : ^T) (actual : ^U) =
actual.Should().Be(expected, "") |> ignore
Assert.Equal(expected :> obj, actual :> obj)

let inline shouldStartWith (expected : string) (actual : string) =
Assert.StartsWith(expected, actual)

let inline shouldContain (needle : string) (haystack : string) =
Assert.Contains(needle, haystack)

let inline areEqual (expected: ^T) (actual: ^T) =
Assert.Equal<^T>(expected, actual)

let inline shouldEqual (x: 'a) (y: 'a) =
Assert.Equal<'a>(x, y)
//

let inline shouldBeEmpty (actual : ^T when ^T :> IEnumerable) =
actual.Should().BeEmpty("") |> ignore
Assert.Empty(actual)

let inline shouldNotBeEmpty (actual : ^T when ^T :> IEnumerable) =
actual.Should().NotBeEmpty("") |> ignore
Assert.NotEmpty(actual)

let shouldBeFalse (actual: bool) =
actual.Should().BeFalse("") |> ignore
Assert.False(actual)

let shouldBeTrue (actual: bool) =
actual.Should().BeTrue("") |> ignore
Assert.True(actual)

let shouldBeSameMultilineStringSets expectedText actualText =

let shouldBeSameMultilineStringSets expectedText actualText =
let getLines text =
use reader = new StringReader(text)
Seq.initInfinite (fun _ -> reader.ReadLine())
Expand Down
15 changes: 6 additions & 9 deletions tests/FSharp.Test.Utilities/FSharp.Test.Utilities.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@

<ItemGroup>
<PackageReference Include="xunit" Version="$(XUnitVersion)" />
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
</ItemGroup>

<!-- Runtime dependencies. Beware. -->
Expand All @@ -83,14 +82,12 @@
</ItemGroup>

<ItemGroup>

<InternalsVisibleTo Include="VisualFSharp.UnitTests" />
<InternalsVisibleTo Include="FSharp.Compiler.ComponentTests" />
<InternalsVisibleTo Include="FSharp.Compiler.Service.Tests" />
<InternalsVisibleTo Include="FSharp.Tests.FSharpSuite" />
<InternalsVisibleTo Include="LanguageServiceProfiling" />
<InternalsVisibleTo Include="FSharp.Compiler.Benchmarks" />

<InternalsVisibleTo Include="VisualFSharp.UnitTests" />
<InternalsVisibleTo Include="FSharp.Compiler.ComponentTests" />
<InternalsVisibleTo Include="FSharp.Compiler.Service.Tests" />
<InternalsVisibleTo Include="FSharp.Tests.FSharpSuite" />
<InternalsVisibleTo Include="LanguageServiceProfiling" />
<InternalsVisibleTo Include="FSharp.Compiler.Benchmarks" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@

## Framework for testing

The following test frameworks and libraries will be used for new test projects **[xUnit Test Framework](https://xunit.net/), [FluentAssertions](https://fluentassertions.com/) (+ [FsUnit](https://fsprojects.github.io/FsUnit/) and [FsCheck](https://github.com/fscheck/FsCheck) when needed)**.
The following test frameworks and libraries will be used for new test projects **[xUnit Test Framework](https://xunit.net/) and [FsCheck](https://github.com/fscheck/FsCheck) when needed)**.

**Justification:**

* **xUnit** is an extensible, TDD adherent, testing framework, which was successfully adopted by many .NET engineering teams, including Roslyn, AspNetCore, EFcore, etc, has a "cleaner" approach for writing test suites (i.e. class constructor for setup, implementing IDisposable for teardown, as oppose to custom attributes). More info [here](https://xunit.net/docs/comparisons).
* **FluentAssertions** makes it easier to write scoped assertions, provides better error messages.

**Alternatives:** NUnit, MSBuild, Expecto

Expand Down

0 comments on commit 7c598f4

Please sign in to comment.