Skip to content

Commit

Permalink
Removing Nunit from utils (#17770)
Browse files Browse the repository at this point in the history
* Migrate last Nunit tests to Xunit

* up

* up

* up

* Update TestLib.LanguageService.fs

* up

* up

* up

* Remove unused tests

* one more

* Salsa

* up

* up

* up

* Update FsUnit.fs

* Up

* Update AsyncTests.fs

---------

Co-authored-by: Kevin Ransom (msft) <codecutter@hotmail.com>
  • Loading branch information
psfinaki and KevinRansom authored Sep 24, 2024
1 parent 2907d59 commit cd736c4
Show file tree
Hide file tree
Showing 27 changed files with 195 additions and 463 deletions.
4 changes: 2 additions & 2 deletions src/FSharp.Build/Fsc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -786,10 +786,10 @@ type public Fsc() as this =
let builder = generateCommandLineBuilder ()
builder.GetCapturedArguments() |> String.concat Environment.NewLine

// expose this to internal components (for nunit testing)
// expose this to internal components (for unit testing)
member internal fsc.InternalGenerateCommandLineCommands() = fsc.GenerateCommandLineCommands()

// expose this to internal components (for nunit testing)
// expose this to internal components (for unit testing)
member internal fsc.InternalGenerateResponseFileCommands() = fsc.GenerateResponseFileCommands()

member internal fsc.InternalExecuteTool(pathToTool, responseFileCommands, commandLineCommands) =
Expand Down
4 changes: 2 additions & 2 deletions src/FSharp.Build/Fsi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,10 @@ type public Fsi() as this =
let builder = generateCommandLineBuilder ()
builder.GetCapturedArguments() |> String.concat Environment.NewLine

// expose this to internal components (for nunit testing)
// expose this to internal components (for unit testing)
member internal fsi.InternalGenerateCommandLineCommands() = fsi.GenerateCommandLineCommands()

// expose this to internal components (for nunit testing)
// expose this to internal components (for unit testing)
member internal fsi.InternalGenerateResponseFileCommands() = fsi.GenerateResponseFileCommands()

member internal fsi.InternalExecuteTool(pathToTool, responseFileCommands, commandLineCommands) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ module CompilationFromCmdlineArgsTests =
open System
open System.IO
open FSharp.Compiler.CodeAnalysis
open NUnit.Framework
open Xunit
open CompilationTests

// Point to a generated args.txt file.
// Use scrape.fsx to generate an args.txt from a binary log file.
// The path needs to be absolute.
let localProjects: string list =
let localProjects =
[
@"C:\Projects\fantomas\src\Fantomas.Core\Fantomas.Core.args.txt"
@"C:\Projects\FsAutoComplete\src\FsAutoComplete\FsAutoComplete.args.txt"
@"C:\Projects\fsharp\src\Compiler\FSharp.Compiler.Service.args.txt"
@"C:\Projects\fsharp\tests\FSharp.Compiler.ComponentTests\FSharp.Compiler.ComponentTests.args.txt"
]
] |> Seq.map (fun p -> [| box p |])

let checker = FSharpChecker.Create()

Expand All @@ -43,16 +43,16 @@ module CompilationFromCmdlineArgsTests =
for diag in diagnostics do
printfn "%A" diag

Assert.That(exitCode, Is.Zero)
Assert.Equal(exitCode, 0)
finally
Environment.CurrentDirectory <- oldWorkDir

[<TestCaseSource(nameof localProjects)>]
[<Explicit("Slow, only useful as a sanity check that the test codebase is sound and type-checks using the old method")>]
[<MemberData(nameof localProjects)>]
[<Theory(Skip = "Slow, only useful as a sanity check that the test codebase is sound and type-checks using the old method")>]
let ``Test sequential type-checking`` (projectArgumentsFilePath: string) =
testCompilerFromArgs Method.Sequential projectArgumentsFilePath

[<TestCaseSource(nameof localProjects)>]
[<Explicit("This only runs with the explicitly mentioned projects above")>]
[<MemberData(nameof localProjects)>]
[<Theory(Skip = "This should only run with the explicitly mentioned projects above")>]
let ``Test graph-based type-checking`` (projectArgumentsFilePath: string) =
testCompilerFromArgs Method.Graph projectArgumentsFilePath
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
module TypeChecks.DependencyResolutionTests

open TypeChecks.TestUtils
open NUnit.Framework
open Xunit
open FSharp.Compiler.GraphChecking
open Scenarios

[<TestCaseSource(nameof scenarios)>]
let scenarios = scenarios |> Seq.map (fun p -> [| box p |])

[<Theory>]
[<MemberData(nameof scenarios)>]
let ``Supported scenario`` (scenario: Scenario) =
let files =
scenario.Files
Expand All @@ -18,4 +21,4 @@ let ``Supported scenario`` (scenario: Scenario) =
for file in scenario.Files do
let expectedDeps = file.ExpectedDependencies
let actualDeps = set graph.[file.Index]
Assert.AreEqual(expectedDeps, actualDeps, $"Dependencies don't match for {System.IO.Path.GetFileName file.FileName}")
Assert.True((expectedDeps = actualDeps), $"Dependencies don't match for {System.IO.Path.GetFileName file.FileName}")
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module TypeChecks.FileContentMappingTests

open NUnit.Framework
open Xunit
open FSharp.Compiler.GraphChecking
open TestUtils

Expand Down Expand Up @@ -35,7 +35,7 @@ let private (|NestedModule|_|) value e =
| FileContentEntry.NestedModule(name, nestedContent) -> if name = value then Some(nestedContent) else None
| _ -> None

[<Test>]
[<Fact>]
let ``Top level module only exposes namespace`` () =
let content =
getContent
Expand All @@ -45,10 +45,10 @@ module X.Y.Z
"""

match content with
| [ TopLevelNamespace "X.Y" [] ] -> Assert.Pass()
| [ TopLevelNamespace "X.Y" [] ] -> ()
| content -> Assert.Fail($"Unexpected content: {content}")

[<Test>]
[<Fact>]
let ``Top level namespace`` () =
let content =
getContent
Expand All @@ -58,10 +58,10 @@ namespace X.Y
"""

match content with
| [ TopLevelNamespace "X.Y" [] ] -> Assert.Pass()
| [ TopLevelNamespace "X.Y" [] ] -> ()
| content -> Assert.Fail($"Unexpected content: {content}")

[<Test>]
[<Fact>]
let ``Open statement in top level module`` () =
let content =
getContent
Expand All @@ -73,10 +73,10 @@ open A.B.C
"""

match content with
| [ TopLevelNamespace "X.Y" [ OpenStatement "A.B.C" ] ] -> Assert.Pass()
| [ TopLevelNamespace "X.Y" [ OpenStatement "A.B.C" ] ] -> ()
| content -> Assert.Fail($"Unexpected content: {content}")

[<Test>]
[<Fact>]
let ``PrefixedIdentifier in type annotation`` () =
let content =
getContent
Expand All @@ -88,10 +88,10 @@ let fn (a: A.B.CType) = ()
"""

match content with
| [ TopLevelNamespace "X.Y" [ PrefixedIdentifier "A.B" ] ] -> Assert.Pass()
| [ TopLevelNamespace "X.Y" [ PrefixedIdentifier "A.B" ] ] -> ()
| content -> Assert.Fail($"Unexpected content: {content}")

[<Test>]
[<Fact>]
let ``Nested module`` () =
let content =
getContent
Expand All @@ -104,10 +104,10 @@ module Z =
"""

match content with
| [ TopLevelNamespace "X" [ NestedModule "Z" [] ] ] -> Assert.Pass()
| [ TopLevelNamespace "X" [ NestedModule "Z" [] ] ] -> ()
| content -> Assert.Fail($"Unexpected content: {content}")

[<Test>]
[<Fact>]
let ``Single ident module abbreviation`` () =
let content =
getContent
Expand All @@ -119,13 +119,13 @@ module B = C
"""

match content with
| [ TopLevelNamespace "" [ PrefixedIdentifier "C" ] ] -> Assert.Pass()
| [ TopLevelNamespace "" [ PrefixedIdentifier "C" ] ] -> ()
| content -> Assert.Fail($"Unexpected content: {content}")


module InvalidSyntax =

[<Test>]
[<Fact>]
let ``Nested module`` () =
let content =
getContent
Expand All @@ -137,11 +137,11 @@ module InvalidSyntax =
"""

match content with
| [ TopLevelNamespace "" [] ] -> Assert.Pass()
| [ TopLevelNamespace "" [] ] -> ()
| content -> Assert.Fail($"Unexpected content: {content}")


[<Test>]
[<Fact>]
let ``Module above namespace`` () =
let content =
getContent
Expand All @@ -153,5 +153,5 @@ module InvalidSyntax =
"""

match content with
| [ TopLevelNamespace "" [] ] -> Assert.Pass()
| [ TopLevelNamespace "" [] ] -> ()
| content -> Assert.Fail($"Unexpected content: {content}")
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

open System.Threading
open FSharp.Compiler.GraphChecking.GraphProcessing
open NUnit.Framework
open Xunit

[<Test>]
[<Fact>]
let ``When processing a node throws an exception, an exception is raised with the original exception included`` () =
let graph = [1, [|2|]; 2, [||]] |> readOnlyDict
let work (_processor : int -> ProcessedNode<int, string>) (_node : NodeInfo<int>) : string = failwith "Work exception"
Expand All @@ -18,6 +18,6 @@ let ``When processing a node throws an exception, an exception is raised with th
CancellationToken.None
|> ignore
)
Assert.That(exn.Message, Is.EqualTo("Encountered exception when processing item '2'"))
Assert.That(exn.InnerException, Is.Not.Null)
Assert.That(exn.InnerException.Message, Is.EqualTo("Work exception"))
Assert.Equal(exn.Message, "Encountered exception when processing item '2'")
Assert.NotNull(exn.InnerException)
Assert.Equal(exn.InnerException.Message, "Work exception")
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

open System.Collections.Generic
open System.Collections.Immutable
open NUnit.Framework
open Xunit
open FSharp.Compiler.GraphChecking
open FSharp.Compiler.GraphChecking.DependencyResolution

Expand Down Expand Up @@ -757,35 +757,35 @@ let private fantomasCoreTrie: TrieNode =
|]
}

[<Test>]
[<Fact>]
let ``Query nonexistent node in trie`` () =
let result =
queryTrie fantomasCoreTrie [ "System"; "System"; "Runtime"; "CompilerServices" ]

match result with
| QueryTrieNodeResult.NodeDoesNotExist -> Assert.Pass()
| QueryTrieNodeResult.NodeDoesNotExist -> ()
| result -> Assert.Fail $"Unexpected result: %A{result}"

[<Test>]
[<Fact>]
let ``Query node that does not expose data in trie`` () =
let result = queryTrie fantomasCoreTrie [ "Fantomas"; "Core" ]

match result with
| QueryTrieNodeResult.NodeDoesNotExposeData -> Assert.Pass()
| QueryTrieNodeResult.NodeDoesNotExposeData -> ()
| result -> Assert.Fail $"Unexpected result: %A{result}"

[<Test>]
[<Fact>]
let ``Query module node that exposes one file`` () =
let result =
queryTrie fantomasCoreTrie [ "Fantomas"; "Core"; "ISourceTextExtensions" ]

match result with
| QueryTrieNodeResult.NodeExposesData file ->
let file = Seq.exactlyOne file
Assert.AreEqual(indexOf "ISourceTextExtensions.fs", file)
Assert.Equal(indexOf "ISourceTextExtensions.fs", file)
| result -> Assert.Fail $"Unexpected result: %A{result}"

[<Test>]
[<Fact>]
let ``ProcessOpenStatement full path match`` () =
let state =
FileContentQueryState.Create Set.empty
Expand All @@ -794,4 +794,4 @@ let ``ProcessOpenStatement full path match`` () =
processOpenPath fantomasCoreTrie [ "Fantomas"; "Core"; "AstExtensions" ] state

let dep = Seq.exactlyOne result.FoundDependencies
Assert.AreEqual(indexOf "AstExtensions.fsi", dep)
Assert.Equal(indexOf "AstExtensions.fsi", dep)
Loading

0 comments on commit cd736c4

Please sign in to comment.