Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Port tests for missing else branch to NUnit (#7209)
  • Loading branch information
forki authored and KevinRansom committed Jul 12, 2019
commit 869c2bb395f18d5970f8f1bd4827d8449285bddf
50 changes: 50 additions & 0 deletions tests/fsharp/Compiler/ErrorMessages/MissingElseBranch.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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 ``Else branch is missing`` =

[<Test>]
let ``Fail if else branch is missing``() =
CompilerAssert.TypeCheckSingleError
"""
let x = 10
let y =
if x > 10 then "test"
"""
FSharpErrorSeverity.Error
1
(4, 19, 4, 25)
"This 'if' expression is missing an 'else' branch. Because 'if' is an expression, and not a statement, add an 'else' branch which also returns a value of type 'string'."

[<Test>]
let ``Fail on type error in condition``() =
CompilerAssert.TypeCheckSingleError
"""
let x = 10
let y =
if x > 10 then
if x <> "test" then printfn "test"
()
"""
FSharpErrorSeverity.Error
1
(5, 14, 5, 20)
"This expression was expected to have type\n 'int' \nbut here has type\n 'string' "

[<Test>]
let ``Fail if else branch is missing in nesting``() =
CompilerAssert.TypeCheckSingleError
"""
let x = 10
let y =
if x > 10 then ("test")
"""
FSharpErrorSeverity.Error
1
(4, 20, 4, 26)
"This 'if' expression is missing an 'else' branch. Because 'if' is an expression, and not a statement, add an 'else' branch which also returns a value of type 'string'."
3 changes: 2 additions & 1 deletion tests/fsharp/FSharpSuite.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
Expand Down Expand Up @@ -33,6 +33,7 @@
<Compile Include="Compiler\ILChecker.fs" />
<Compile Include="Compiler\CompilerAssert.fs" />
<Compile Include="Compiler\ErrorMessages\ElseBranchHasWrongTypeTests.fs" />
<Compile Include="Compiler\ErrorMessages\MissingElseBranch.fs" />
<Compile Include="Compiler\SourceTextTests.fs" />
<Compile Include="Compiler\Language\AnonRecordTests.fs" />
<Compile Include="Compiler\Language\SpanOptimizationTests.fs" />
Expand Down
8 changes: 0 additions & 8 deletions tests/fsharpqa/Source/Warnings/WarnIfMissingElseBranch.fs

This file was deleted.

10 changes: 0 additions & 10 deletions tests/fsharpqa/Source/Warnings/WarnIfMissingElseBranch2.fs

This file was deleted.

8 changes: 0 additions & 8 deletions tests/fsharpqa/Source/Warnings/WarnIfMissingElseBranch3.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
@@ -1,7 +1,4 @@
SOURCE=WrongNumericLiteral.fs # WrongNumericLiteral.fs
SOURCE=WarnIfMissingElseBranch.fs # WarnIfMissingElseBranch.fs
SOURCE=WarnIfMissingElseBranch2.fs # WarnIfMissingElseBranch2.fs
SOURCE=WarnIfMissingElseBranch3.fs # WarnIfMissingElseBranch3.fs
SOURCE=ReturnInsteadOfReturnBang.fs # ReturnInsteadOfReturnBang.fs
SOURCE=YieldInsteadOfYieldBang.fs # YieldInsteadOfYieldBang.fs
SOURCE=TupleInAbstractMethod.fs # TupleInAbstractMethod.fs
Expand Down