-
Notifications
You must be signed in to change notification settings - Fork 790
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move some error and warning tests to NUnit (#7244)
* move some error and warning tests to NUnit * CompilerAssert.ParseWithErrors now uses ParseFile instead of ParseAndCheckFileInProject * merge conflicts
- Loading branch information
Showing
9 changed files
with
152 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
tests/fsharp/Compiler/ErrorMessages/AssignmentErrorTests.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. | ||
|
||
namespace FSharp.Compiler.UnitTests | ||
|
||
open NUnit.Framework | ||
open FSharp.Compiler.SourceCodeServices | ||
|
||
[<TestFixture>] | ||
module ``Errors assigning to mutable objects`` = | ||
|
||
[<Test>] | ||
let ``Assign to immutable error``() = | ||
CompilerAssert.TypeCheckSingleError | ||
""" | ||
let x = 10 | ||
x <- 20 | ||
exit 0 | ||
""" | ||
FSharpErrorSeverity.Error | ||
27 | ||
(3, 1, 3, 8) | ||
"This value is not mutable. Consider using the mutable keyword, e.g. 'let mutable x = expression'." |
108 changes: 108 additions & 0 deletions
108
tests/fsharp/Compiler/Warnings/AssignmentWarningTests.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. | ||
|
||
namespace FSharp.Compiler.UnitTests | ||
|
||
open NUnit.Framework | ||
open FSharp.Compiler.SourceCodeServices | ||
|
||
[<TestFixture>] | ||
module ``Warnings assigning to mutable and immutable objects`` = | ||
|
||
[<Test>] | ||
let ``Unused compare with immutable when assignment might be intended``() = | ||
CompilerAssert.TypeCheckSingleError | ||
""" | ||
let x = 10 | ||
let y = "hello" | ||
let changeX() = | ||
x = 20 | ||
y = "test" | ||
exit 0 | ||
""" | ||
FSharpErrorSeverity.Warning | ||
20 | ||
(6, 5, 6, 11) | ||
"The result of this equality expression has type 'bool' and is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to mutate a value, then mark the value 'mutable' and use the '<-' operator e.g. 'x <- expression'." | ||
|
||
[<Test>] | ||
let ``Unused compare with mutable when assignment might be intended``() = | ||
CompilerAssert.TypeCheckSingleError | ||
""" | ||
let mutable x = 10 | ||
let y = "hello" | ||
let changeX() = | ||
x = 20 | ||
y = "test" | ||
exit 0 | ||
""" | ||
FSharpErrorSeverity.Warning | ||
20 | ||
(6, 5, 6, 11) | ||
"The result of this equality expression has type 'bool' and is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to mutate a value, then use the '<-' operator e.g. 'x <- expression'." | ||
|
||
[<Test>] | ||
let ``Unused comparison of property in dotnet object when assignment might be intended``() = | ||
CompilerAssert.TypeCheckSingleError | ||
""" | ||
open System | ||
let z = new System.Timers.Timer() | ||
let y = "hello" | ||
let changeProperty() = | ||
z.Enabled = true | ||
y = "test" | ||
exit 0 | ||
""" | ||
FSharpErrorSeverity.Warning | ||
20 | ||
(8, 5, 8, 21) | ||
"The result of this equality expression has type 'bool' and is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to set a value to a property, then use the '<-' operator e.g. 'z.Enabled <- expression'." | ||
|
||
[<Test>] | ||
let ``Unused comparison of property when assignment might be intended ``() = | ||
CompilerAssert.TypeCheckSingleError | ||
""" | ||
type MyClass(property1 : int) = | ||
member val Property1 = property1 | ||
member val Property2 = "" with get, set | ||
let x = MyClass(1) | ||
let y = "hello" | ||
let changeProperty() = | ||
x.Property2 = "20" | ||
y = "test" | ||
exit 0 | ||
""" | ||
FSharpErrorSeverity.Warning | ||
20 | ||
(10, 5, 10, 23) | ||
"The result of this equality expression has type 'bool' and is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to set a value to a property, then use the '<-' operator e.g. 'x.Property2 <- expression'." | ||
|
||
[<Test>] | ||
let ``Don't warn if assignment to property without setter ``() = | ||
CompilerAssert.TypeCheckSingleError | ||
""" | ||
type MyClass(property1 : int) = | ||
member val Property2 = "" with get | ||
let x = MyClass(1) | ||
let y = "hello" | ||
let changeProperty() = | ||
x.Property2 = "22" | ||
y = "test" | ||
exit 0 | ||
""" | ||
FSharpErrorSeverity.Warning | ||
20 | ||
(9, 5, 9, 23) | ||
"The result of this equality expression has type 'bool' and is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
tests/fsharpqa/Source/ErrorMessages/NameResolution/E_GlobalQualifierAfterDot.fs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters