Skip to content

Commit

Permalink
Moving UpcastDowncastTests over to NUnit (#7229)
Browse files Browse the repository at this point in the history
* Moving UpcastDowncastTests over to NUnit

* missing new line
  • Loading branch information
sergey-tihon authored and KevinRansom committed Jul 16, 2019
1 parent 0f24b3e commit 863ec25
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 30 deletions.
51 changes: 51 additions & 0 deletions tests/fsharp/Compiler/ErrorMessages/UpcastDowncastTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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 ``Upcast and Downcast`` =

[<Test>]
let ``Downcast Instead Of Upcast``() =
CompilerAssert.TypeCheckSingleError
"""
open System.Collections.Generic
let orig = Dictionary<obj,obj>() :> IDictionary<obj,obj>
let c = orig :> Dictionary<obj,obj>
"""
FSharpErrorSeverity.Error
193
(5, 9, 5, 36)
"Type constraint mismatch. The type \n 'IDictionary<obj,obj>' \nis not compatible with type\n 'Dictionary<obj,obj>' \n"

[<Test>]
let ``Upcast Instead Of Downcast``() =
CompilerAssert.TypeCheckWithErrors
"""
open System.Collections.Generic
let orig = Dictionary<obj,obj>()
let c = orig :?> IDictionary<obj,obj>
"""
[|
FSharpErrorSeverity.Warning, 67, (5, 9, 5, 38), "This type test or downcast will always hold"
FSharpErrorSeverity.Error, 3198, (5, 9, 5, 38), "The conversion from Dictionary<obj,obj> to IDictionary<obj,obj> is a compile-time safe upcast, not a downcast. Consider using the :> (upcast) operator instead of the :?> (downcast) operator."
|]

[<Test>]
let ``Upcast Function Instead Of Downcast``() =
CompilerAssert.TypeCheckWithErrors
"""
open System.Collections.Generic
let orig = Dictionary<obj,obj>()
let c : IDictionary<obj,obj> = downcast orig
"""
[|
FSharpErrorSeverity.Warning, 67, (5, 32, 5, 45), "This type test or downcast will always hold"
FSharpErrorSeverity.Error, 3198, (5, 32, 5, 45), "The conversion from Dictionary<obj,obj> to IDictionary<obj,obj> is a compile-time safe upcast, not a downcast. Consider using 'upcast' instead of 'downcast'."
|]
1 change: 1 addition & 0 deletions tests/fsharp/FSharpSuite.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<Compile Include="Compiler\ErrorMessages\AccessOfTypeAbbreviationTests.fs" />
<Compile Include="Compiler\ErrorMessages\ElseBranchHasWrongTypeTests.fs" />
<Compile Include="Compiler\ErrorMessages\MissingElseBranch.fs" />
<Compile Include="Compiler\ErrorMessages\UpcastDowncastTests.fs" />
<Compile Include="Compiler\SourceTextTests.fs" />
<Compile Include="Compiler\Language\AnonRecordTests.fs" />
<Compile Include="Compiler\Language\SpanOptimizationTests.fs" />
Expand Down
9 changes: 0 additions & 9 deletions tests/fsharpqa/Source/Warnings/DowncastInsteadOfUpcast.fs

This file was deleted.

This file was deleted.

9 changes: 0 additions & 9 deletions tests/fsharpqa/Source/Warnings/UpcastInsteadOfDowncast.fs

This file was deleted.

3 changes: 0 additions & 3 deletions tests/fsharpqa/Source/Warnings/env.lst
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
SOURCE=SuggestToUseIndexer.fs # SuggestToUseIndexer.fs
SOURCE=RefCellInsteadOfNot.fs # RefCellInsteadOfNot.fs
SOURCE=RefCellInsteadOfNot2.fs # RefCellInsteadOfNot2.fs
SOURCE=UpcastInsteadOfDowncast.fs # UpcastInsteadOfDowncast.fs
SOURCE=UpcastFunctionInsteadOfDowncast.fs # UpcastFunctionInsteadOfDowncast.fs
SOURCE=DowncastInsteadOfUpcast.fs # DowncastInsteadOfUpcast.fs
SOURCE=RuntimeTypeTestInPattern.fs # RuntimeTypeTestInPattern.fs
SOURCE=RuntimeTypeTestInPattern2.fs # RuntimeTypeTestInPattern2.fs
SOURCE=WarnIfExpressionResultUnused.fs # WarnIfExpressionResultUnused.fs
Expand Down

0 comments on commit 863ec25

Please sign in to comment.