Skip to content

Commit 869c2bb

Browse files
forkiKevinRansom
authored andcommitted
Port tests for missing else branch to NUnit (#7209)
1 parent 60c915a commit 869c2bb

6 files changed

Lines changed: 52 additions & 30 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespace FSharp.Compiler.UnitTests
4+
5+
open NUnit.Framework
6+
open FSharp.Compiler.SourceCodeServices
7+
8+
[<TestFixture>]
9+
module ``Else branch is missing`` =
10+
11+
[<Test>]
12+
let ``Fail if else branch is missing``() =
13+
CompilerAssert.TypeCheckSingleError
14+
"""
15+
let x = 10
16+
let y =
17+
if x > 10 then "test"
18+
"""
19+
FSharpErrorSeverity.Error
20+
1
21+
(4, 19, 4, 25)
22+
"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'."
23+
24+
[<Test>]
25+
let ``Fail on type error in condition``() =
26+
CompilerAssert.TypeCheckSingleError
27+
"""
28+
let x = 10
29+
let y =
30+
if x > 10 then
31+
if x <> "test" then printfn "test"
32+
()
33+
"""
34+
FSharpErrorSeverity.Error
35+
1
36+
(5, 14, 5, 20)
37+
"This expression was expected to have type\n 'int' \nbut here has type\n 'string' "
38+
39+
[<Test>]
40+
let ``Fail if else branch is missing in nesting``() =
41+
CompilerAssert.TypeCheckSingleError
42+
"""
43+
let x = 10
44+
let y =
45+
if x > 10 then ("test")
46+
"""
47+
FSharpErrorSeverity.Error
48+
1
49+
(4, 20, 4, 26)
50+
"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'."

tests/fsharp/FSharpSuite.Tests.fsproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33

44
<PropertyGroup>
@@ -33,6 +33,7 @@
3333
<Compile Include="Compiler\ILChecker.fs" />
3434
<Compile Include="Compiler\CompilerAssert.fs" />
3535
<Compile Include="Compiler\ErrorMessages\ElseBranchHasWrongTypeTests.fs" />
36+
<Compile Include="Compiler\ErrorMessages\MissingElseBranch.fs" />
3637
<Compile Include="Compiler\SourceTextTests.fs" />
3738
<Compile Include="Compiler\Language\AnonRecordTests.fs" />
3839
<Compile Include="Compiler\Language\SpanOptimizationTests.fs" />

tests/fsharpqa/Source/Warnings/WarnIfMissingElseBranch.fs

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/fsharpqa/Source/Warnings/WarnIfMissingElseBranch2.fs

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/fsharpqa/Source/Warnings/WarnIfMissingElseBranch3.fs

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/fsharpqa/Source/Warnings/env.lst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
SOURCE=WrongNumericLiteral.fs # WrongNumericLiteral.fs
2-
SOURCE=WarnIfMissingElseBranch.fs # WarnIfMissingElseBranch.fs
3-
SOURCE=WarnIfMissingElseBranch2.fs # WarnIfMissingElseBranch2.fs
4-
SOURCE=WarnIfMissingElseBranch3.fs # WarnIfMissingElseBranch3.fs
52
SOURCE=ReturnInsteadOfReturnBang.fs # ReturnInsteadOfReturnBang.fs
63
SOURCE=YieldInsteadOfYieldBang.fs # YieldInsteadOfYieldBang.fs
74
SOURCE=TupleInAbstractMethod.fs # TupleInAbstractMethod.fs

0 commit comments

Comments
 (0)