Skip to content

Commit

Permalink
Add tests for top-level modules and fix top-level item resolution in …
Browse files Browse the repository at this point in the history
…signature files - FCS now failing for a different reason.
  • Loading branch information
safesparrow committed Nov 12, 2022
1 parent 9048a96 commit 6a482d6
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 5 deletions.
11 changes: 9 additions & 2 deletions tests/ParallelTypeCheckingTests/Code/ASTVisit.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1327,10 +1327,17 @@ module TopModulesExtraction =
range,
synModuleOrNamespaceTrivia) ->
if mightHaveAutoOpen synAttributeLists then
// Contents of a module that's potentially AutoOpen are available everywhere, so treat it as if it had no name ('root' module).
// Contents of a module that's potentially AutoOpen are available from its parent without a prefix.
// Stay safe and as soon as the parent module is reachable, consider this module reachable as well
[| LongIdent.Empty |]
else
synModuleDecls |> moduleSigDecls |> combine longId
// 'module A.B' is equivalent to 'namespace A; module B', meaning that 'A' is opened implicitly
if
synModuleOrNamespaceKind.IsModule && longId.Length > 1
then
[| longId.GetSlice(None, Some <| longId.Length - 2); longId |]
else
[| longId |]

and moduleSigDecls (x: SynModuleSigDecl list) : Eit =
let emptyState = Eit.Nested [||]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#nowarn "1182"

open System
open System.Collections.Concurrent
open System.Collections.Generic
open System.IO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ let internal codebaseToConfig code method =
WorkingDir = Some code.WorkDir
}

/// Before running these tests, you must prepare the codebase by running the script 'FCS.prepare.ps1'
[<TestCaseSource(nameof (codebases))>]
[<Explicit("Before running these tests, you must prepare the codebase by running FCS.prepare.ps1")>]
let ``Test graph-based type-checking`` (code: Codebase) =
let config = codebaseToConfig code Method.Graph
TestCompilerFromArgs config

[<TestCaseSource(nameof (codebases))>]
[<Explicit("Before running these tests, you must prepare the codebase by running FCS.prepare.ps1")>]
[<Explicit("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`` (code: Codebase) =
let config = codebaseToConfig code Method.Sequential
TestCompilerFromArgs config
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ open ParallelTypeCheckingTests.Types
open ParallelTypeCheckingTests.Utils
open ParallelTypeCheckingTests.DepResolving
open NUnit.Framework
open Newtonsoft.Json

let buildFiles (files: (string * string) seq) =
files
Expand Down Expand Up @@ -50,6 +49,84 @@ open A
let expectedEdges = [ "B.fs", [ "A.fs" ] ]
assertGraphEqual deps expectedEdges

[<Test>]
let ``When defining a top-level module, the implicit parent namespace is taken into account when considering references to the file - .fsi pair`` () =
let files =
[|
"A.fsi", """
module A.B.C1
type X = X of int
"""
"B.fsi", """
module A.B.C2
val x : C1.X -> unit
"""
|] |> buildFiles

let deps = DependencyResolution.detectFileDependencies files

let expectedEdges = ["B.fsi", ["A.fsi"]]
assertGraphEqual deps expectedEdges


[<Test>]
let ``When defining a top-level module, the implicit parent namespace is taken into account when considering references to the file - .fs, .fsi pair`` () =
let files =
[|
"A.fs", """
module A.B.C1
type X = X of int
"""
"B.fsi", """
module A.B.C2
val x : C1.X -> unit
"""
|] |> buildFiles

let deps = DependencyResolution.detectFileDependencies files

let expectedEdges = ["B.fsi", ["A.fs"]]
assertGraphEqual deps expectedEdges


[<Test>]
let ``When defining a top-level module, the implicit parent namespace is taken into account when considering references to the file - .fsi, .fs pair`` () =
let files =
[|
"A.fsi", """
module A.B.C1
type X = X of int
"""
"B.fs", """
module A.B.C2
let x : C1.X -> unit = failwith ""
"""
|] |> buildFiles

let deps = DependencyResolution.detectFileDependencies files

let expectedEdges = ["B.fs", ["A.fsi"]]
assertGraphEqual deps expectedEdges

[<Test>]
let ``When defining a top-level module, the implicit parent namespace is taken into account when considering references to the file - .fs, .fs pair`` () =
let files =
[|
"A.fs", """
module A.B.C1
type X = X of int
"""
"B.fs", """
module A.B.C2
let x : C1.X -> unit = failwith ""
"""
|] |> buildFiles

let deps = DependencyResolution.detectFileDependencies files

let expectedEdges = ["B.fs", ["A.fs"]]
assertGraphEqual deps expectedEdges

[<Test>]
let ``With no references there is no dependency`` () =
let files =
Expand Down

0 comments on commit 6a482d6

Please sign in to comment.