未验证 提交 d504546d 编写于 作者: E Edgar Gonzalez 提交者: GitHub

Unit tests for Calling extension methods on obsolete types and modules (#13297)

* Unit tests for Calling extension methods on obsolete types and modules

* Remove  Unexpected infix operator in definition

* Uopdate test to use withDiagnostics for more exhaustive error message checking

* Update tests/FSharp.Compiler.ComponentTests/Language/AttributeCheckingTests.fs
Co-authored-by: NPetr Semkin <psfinaki@users.noreply.github.com>

* Update tests/FSharp.Compiler.ComponentTests/Language/AttributeCheckingTests.fs
Co-authored-by: NPetr Semkin <psfinaki@users.noreply.github.com>
Co-authored-by: NPetr Semkin <psfinaki@users.noreply.github.com>
上级 080370b4
......@@ -48,7 +48,6 @@ type C() =
Fsx """
open System
type C() =
[<Obsolete("Use B instead", true)>]
......@@ -75,8 +74,9 @@ let c = C()
|> ignoreWarnings
|> compile
|> shouldFail
|> withErrorCode 101
|> withErrorMessage "This construct is deprecated. Use B instead"
|> withDiagnostics [
(Error 101, Line 9, Col 9, Line 9, Col 10, "This construct is deprecated. Use B instead")
]
[<Fact>]
let ``Obsolete attribute is taken into account when used on a member and invoking the member`` () =
......@@ -93,8 +93,9 @@ c.Update()
|> ignoreWarnings
|> compile
|> shouldFail
|> withErrorCode 101
|> withErrorMessage "This construct is deprecated. Use B instead"
|> withDiagnostics [
(Error 101, Line 9, Col 1, Line 9, Col 9, "This construct is deprecated. Use B instead")
]
[<Fact>]
let ``Obsolete attribute is taken into account when used on type and invoking the member`` () =
......@@ -111,9 +112,10 @@ c.Update()
|> ignoreWarnings
|> compile
|> shouldFail
|> withErrorCodes [ 101; 101]
|> withErrorMessages [ "This construct is deprecated. Use B instead"; "This construct is deprecated. Use B instead"]
|> withDiagnostics [
(Error 101, Line 8, Col 9, Line 8, Col 10, "This construct is deprecated. Use B instead");
(Error 101, Line 9, Col 1, Line 9, Col 9, "This construct is deprecated. Use B instead")
]
[<Fact>]
let ``Obsolete attribute is taken into account when used on struct type and invoking the member`` () =
......@@ -127,14 +129,14 @@ type C =
let c = C()
c.Update()
"""
|> ignoreWarnings
|> compile
|> shouldFail
|> withErrorCodes [ 101; 101]
|> withErrorMessages [ "This construct is deprecated. Use B instead"; "This construct is deprecated. Use B instead"]
|> withDiagnostics [
(Error 101, Line 9, Col 9, Line 9, Col 10, "This construct is deprecated. Use B instead");
(Error 101, Line 10, Col 1, Line 10, Col 9, "This construct is deprecated. Use B instead")
]
[<Fact>]
let ``Obsolete attribute is taken into account when used on struct type and instantiate the type`` () =
......@@ -151,15 +153,15 @@ let c = C()
|> ignoreWarnings
|> compile
|> shouldFail
|> withErrorCode 101
|> withErrorMessage "This construct is deprecated. Use B instead"
|> withDiagnostics [
(Error 101, Line 9, Col 9, Line 9, Col 10, "This construct is deprecated. Use B instead")
]
[<Fact>]
let ``Obsolete attribute is taken into account when used on a struct member and invoking the member`` () =
Fsx """
open System
[<Struct>]
type C =
[<Obsolete("Use B instead", true)>]
......@@ -171,16 +173,15 @@ c.Update()
|> ignoreWarnings
|> compile
|> shouldFail
|> withErrorCode 101
|> withErrorMessage "This construct is deprecated. Use B instead"
|> withDiagnostics [
(Error 101, Line 10, Col 1, Line 10, Col 9, "This construct is deprecated. Use B instead")
]
[<Fact>]
let ``Obsolete attribute is taken into account when used on a record property`` () =
Fsx """
open System
type C =
{ [<Obsolete("Use B instead", true)>] X: int }
......@@ -189,16 +190,15 @@ let c = { X = 0 }
|> ignoreWarnings
|> compile
|> shouldFail
|> withErrorCode 101
|> withErrorMessage "This construct is deprecated. Use B instead"
|> withDiagnostics [
(Error 101, Line 7, Col 9, Line 7, Col 18, "This construct is deprecated. Use B instead")
]
[<Fact>]
let ``Obsolete attribute is taken into account when used on a record and member invocation`` () =
Fsx """
open System
[<Obsolete("Use B instead", true)>]
type C =
{ X : int }
......@@ -210,15 +210,15 @@ C.Update()
|> ignoreWarnings
|> compile
|> shouldFail
|> withErrorCode 101
|> withErrorMessage "This construct is deprecated. Use B instead"
|> withDiagnostics [
(Error 101, Line 10, Col 1, Line 10, Col 2, "This construct is deprecated. Use B instead")
]
[<Fact>]
let ``Obsolete attribute is taken into account when used on a record member and method invocation`` () =
Fsx """
open System
type C =
{ X : int }
[<Obsolete("Use B instead", true)>]
......@@ -229,8 +229,9 @@ C.Update()
|> ignoreWarnings
|> compile
|> shouldFail
|> withErrorCode 101
|> withErrorMessage "This construct is deprecated. Use B instead"
|> withDiagnostics [
(Error 101, Line 9, Col 1, Line 9, Col 9, "This construct is deprecated. Use B instead")
]
[<Fact>]
let ``Obsolete attribute is taken into account when used on an enum and invocation`` () =
......@@ -247,8 +248,9 @@ let c = Color.Red
|> ignoreWarnings
|> compile
|> shouldFail
|> withErrorCode 101
|> withErrorMessage "This construct is deprecated. Use B instead"
|> withDiagnostics [
(Error 101, Line 9, Col 9, Line 9, Col 14, "This construct is deprecated. Use B instead")
]
[<Fact>]
let ``Obsolete attribute is taken into account when used on an enum entry and invocation`` () =
......@@ -264,3 +266,271 @@ let c = Color.Red
|> ignoreWarnings
|> compile
|> shouldSucceed
[<Fact>]
let ``Obsolete attribute is taken into account when used on an type and use extension method`` () =
Fsx """
open System
open System.Runtime.CompilerServices
[<Obsolete("Use B instead", true)>]
type Button = { Text : string }
[<Extension>]
type ButtonExtensions =
[<Extension>]
static member inline text(this: Button, text: string) =
{ this with Text = text }
"""
|> ignoreWarnings
|> compile
|> shouldFail
|> withDiagnostics [
(Error 101, Line 13, Col 37, Line 13, Col 43, "This construct is deprecated. Use B instead")
]
[<Fact>]
let ``Obsolete attribute is taken into account when used on an type property and use extension method`` () =
Fsx """
open System
open System.Runtime.CompilerServices
type Button = { [<Obsolete("Use B instead", true)>] Text : string }
[<Extension>]
type ButtonExtensions =
[<Extension>]
static member inline text(this: Button, text: string) =
{ this with Text = text }
"""
|> ignoreWarnings
|> compile
|> shouldFail
|> withDiagnostics [
(Error 101, Line 13, Col 9, Line 13, Col 34, "This construct is deprecated. Use B instead")
]
[<Fact>]
let ``Obsolete attribute is taken into account when used on an type and property and use extension method`` () =
Fsx """
open System
open System.Runtime.CompilerServices
[<Obsolete("Use B instead", true)>]
type Button = { [<Obsolete("Use B instead", true)>] Text : string }
[<Extension>]
type ButtonExtensions =
[<Extension>]
static member inline text(this: Button, text: string) =
{ this with Text = text }
"""
|> ignoreWarnings
|> compile
|> shouldFail
|> withDiagnostics [
(Error 101, Line 12, Col 37, Line 12, Col 43, "This construct is deprecated. Use B instead");
(Error 101, Line 13, Col 9, Line 13, Col 34, "This construct is deprecated. Use B instead")
]
[<Fact>]
let ``Obsolete attribute is taken into account when used on an type property and set via module`` () =
Fsx """
open System
open System.Runtime.CompilerServices
type Button = { [<Obsolete("Use B instead", true)>] Text : string }
module Button =
let set text = { Text = text }
"""
|> ignoreWarnings
|> compile
|> shouldFail
|> withDiagnostics [
(Error 101, Line 9, Col 20, Line 9, Col 36, "This construct is deprecated. Use B instead")
]
[<Fact>]
let ``Obsolete attribute is taken into account when used on an type and set property via module`` () =
Fsx """
open System
open System.Runtime.CompilerServices
[<Obsolete("Use B instead", true)>]
type Button = { [<Obsolete("Use B instead", true)>] Text : string }
module Button =
let set text = { Text = text }
"""
|> ignoreWarnings
|> compile
|> shouldFail
|> withDiagnostics [
(Error 101, Line 10, Col 20, Line 10, Col 36, "This construct is deprecated. Use B instead")
]
[<Fact>]
let ``Obsolete attribute is taken into account when used on an type property and set property via module using an extension method`` () =
Fsx """
open System
open System.Runtime.CompilerServices
type Button = { [<Obsolete("Use B instead", true)>] Text : string }
module Button =
let set text = { Text = text }
[<Extension>]
type ButtonExtensions =
[<Extension>]
static member inline text(this: Button, text: string) =
Button.set text
"""
|> ignoreWarnings
|> compile
|> shouldFail
|> withDiagnostics [
(Error 101, Line 9, Col 20, Line 9, Col 36, "This construct is deprecated. Use B instead")
]
[<Fact>]
let ``Obsolete attribute is taken into account when used on an module and set property via module using an extension method`` () =
Fsx """
open System
open System.Runtime.CompilerServices
type Button = { Text : string }
[<Obsolete("Use B instead", true)>]
module Button =
let set text = { Text = text }
[<Extension>]
type ButtonExtensions =
[<Extension>]
static member inline text(this: Button, text: string) =
Button.set text
"""
|> ignoreWarnings
|> compile
|> shouldFail
|> withDiagnostics [
(Error 101, Line 17, Col 9, Line 17, Col 15, "This construct is deprecated. Use B instead")
]
[<Fact>]
let ``Obsolete attribute is taken into account when used on an moudle and function and set property via module using an extesnion method`` () =
Fsx """
open System
open System.Runtime.CompilerServices
type Button = { Text : string }
[<Obsolete("Use B instead", true)>]
module Button =
[<Obsolete("Use B instead", true)>]
let set text = { Text = text }
[<Extension>]
type ButtonExtensions =
[<Extension>]
static member inline text(this: Button, text: string) =
Button.set text
"""
|> ignoreWarnings
|> compile
|> shouldFail
|> withDiagnostics [
(Error 101, Line 18, Col 9, Line 18, Col 15, "This construct is deprecated. Use B instead")
]
[<Fact>]
let ``Obsolete attribute is taken into account when used on an moudle function and set property via module using an extesnion method`` () =
Fsx """
open System
open System.Runtime.CompilerServices
type Button = { Text : string }
module Button =
[<Obsolete("Use B instead", true)>]
let set text = { Text = text }
[<Extension>]
type ButtonExtensions =
[<Extension>]
static member inline text(this: Button, text: string) =
Button.set text
"""
|> ignoreWarnings
|> compile
|> shouldFail
|> withDiagnostics [
(Error 101, Line 17, Col 9, Line 17, Col 19, "This construct is deprecated. Use B instead")
]
[<Fact>]
let ``Obsolete attribute is taken into account when used on an type extensions and used on an instance`` () =
Fsx """
open System
open System.Runtime.CompilerServices
type Button = { Text : string }
[<Extension>]
[<Obsolete("Use B instead", true)>]
type ButtonExtensions =
[<Extension>]
static member inline text(this: Button, text: string) =
{ this with Text = text }
let b = { Text = "Hello" }
b.text("Hello 2") |> ignore
"""
|> ignoreWarnings
|> compile
|> shouldSucceed
[<Fact>]
let ``Obsolete attribute is taken into account when used on an type extensions static function and used on an instance`` () =
Fsx """
open System
open System.Runtime.CompilerServices
type Button = { Text : string }
[<Extension>]
type ButtonExtensions =
[<Extension>]
[<Obsolete("Use B instead", true)>]
static member inline text(this: Button, text: string) =
{ this with Text = text }
let b = { Text = "Hello" }
b.text("Hello 2") |> ignore
"""
|> ignoreWarnings
|> compile
|> shouldFail
|> withDiagnostics [
(Error 101, Line 16, Col 1, Line 16, Col 7, "This construct is deprecated. Use B instead")
]
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册