Skip to content

Commit

Permalink
Tests for signature files and scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin521 committed Aug 9, 2024
1 parent 6044617 commit 05c45b5
Showing 1 changed file with 55 additions and 7 deletions.
62 changes: 55 additions & 7 deletions tests/FSharp.Compiler.ComponentTests/CompilerDirectives/Nowarn.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ open FSharp.Test.Compiler

module Nowarn =

let private matchNoneErrorMessage = "Incomplete pattern matches on this expression. For example, the value 'Some (_)' may indicate a case not covered by the pattern(s)."
let private warning25Text = "Incomplete pattern matches on this expression. For example, the value 'Some (_)' may indicate a case not covered by the pattern(s)."
let private error3350Text = "Feature '# directives with non-quoted string arguments' is not available in F# 8.0. Please use language version 'PREVIEW' or greater."
let private warning44Text = "This construct is deprecated"

let private sourceForWarningIsSuppressed = """
module A
match None with None -> ()
#nowarn 25
#nowarn "25"
match None with None -> ()
#warnon 25
#warnon "25"
match None with None -> ()
#nowarn 25
#nowarn "25"
match None with None -> ()
"""

Expand All @@ -24,6 +26,52 @@ match None with None -> ()
|> withLangVersionPreview
|> compile
|> withDiagnostics [
(Warning 25, Line 3, Col 7, Line 3, Col 11, matchNoneErrorMessage)
(Warning 25, Line 7, Col 7, Line 7, Col 11, matchNoneErrorMessage)
]
Warning 25, Line 3, Col 7, Line 3, Col 11, warning25Text
Warning 25, Line 7, Col 7, Line 7, Col 11, warning25Text
]

let private scriptForWarningIsSuppressed = """
match None with None -> ()
#nowarn "25"
match None with None -> ()
#warnon "25"
match None with None -> ()
#nowarn "25"
match None with None -> ()
"""

[<Fact>]
let ``warning is suppressed between nowarn and warnon directives (in script)`` () =
Fsx scriptForWarningIsSuppressed
|> withLangVersionPreview
|> compile
|> withDiagnostics [
// These warnings should appear if we make scripts spec-compliant
// Warning 25, Line 3, Col 7, Line 3, Col 11, matchNoneErrorMessage
// Warning 25, Line 7, Col 7, Line 7, Col 11, matchNoneErrorMessage
]

let private sourceForWarningIsSuppressedInSigFile = """
module A
open System
[<Obsolete>]
type T = class end
type T2 = T
#nowarn "44"
type T3 = T
#warnon "44"
type T4 = T
#nowarn "44"
type T5 = T
"""

[<Fact>]
let ``warning is suppressed between nowarn and warnon directives in a signature file`` () =
Fsi sourceForWarningIsSuppressedInSigFile
|> withLangVersionPreview
|> compile
|> withDiagnostics [
Warning 44, Line 6, Col 11, Line 6, Col 12, warning44Text
Warning 44, Line 10, Col 11, Line 10, Col 12, warning44Text
]

0 comments on commit 05c45b5

Please sign in to comment.