Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler tests cleanup, part 1 #15690

Merged
merged 4 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions FSharp.Compiler.Service.sln
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Core", "src\FSharp.C
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Compiler.Interactive.Settings", "src\FSharp.Compiler.Interactive.Settings\FSharp.Compiler.Interactive.Settings.fsproj", "{AF887C2E-640D-4CD6-A0BD-88AE1517797D}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Compiler.UnitTests", "tests\FSharp.Compiler.UnitTests\FSharp.Compiler.UnitTests.fsproj", "{0C0BDAF4-7D47-4BDA-9992-077F63D6B494}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -137,6 +139,10 @@ Global
{AF887C2E-640D-4CD6-A0BD-88AE1517797D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AF887C2E-640D-4CD6-A0BD-88AE1517797D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AF887C2E-640D-4CD6-A0BD-88AE1517797D}.Release|Any CPU.Build.0 = Release|Any CPU
{0C0BDAF4-7D47-4BDA-9992-077F63D6B494}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0C0BDAF4-7D47-4BDA-9992-077F63D6B494}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C0BDAF4-7D47-4BDA-9992-077F63D6B494}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C0BDAF4-7D47-4BDA-9992-077F63D6B494}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<Content Include="expected-help-output.bsl">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
<Compile Include="SurfaceArea.fs" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'"/>
<Compile Include="SurfaceArea.fs" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
<Compile Include="..\service\FsUnit.fs">
<Link>FsUnit.fs</Link>
</Compile>
Expand Down Expand Up @@ -67,15 +67,9 @@
<Compile Include="..\service\StructureTests.fs">
<Link>StructureTests.fs</Link>
</Compile>
<Compile Include="..\service\TokenizerTests.fs">
<Link>TokenizerTests.fs</Link>
</Compile>
<Compile Include="..\service\ServiceUntypedParseTests.fs">
<Link>ServiceUntypedParseTests.fs</Link>
</Compile>
<Compile Include="..\service\TreeVisitorTests.fs">
<Link>TreeVisitorTests.fs</Link>
</Compile>
<Compile Include="..\service\PatternMatchCompilationTests.fs">
<Link>PatternMatchCompilationTests.fs</Link>
</Compile>
Expand All @@ -94,9 +88,6 @@
<Compile Include="..\service\XmlDocTests - Units of Measure.fs">
<Link>XmlDocTests - Units of Measure.fs</Link>
</Compile>
<Compile Include="..\service\PrettyNaming.fs">
<Link>PrettyNaming.fs</Link>
</Compile>
<Compile Include="..\service\RangeTests.fs">
<Link>RangeTests.fs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<PropertyGroup>
<TargetFrameworks>net472;net7.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' == 'Unix'">net7.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' == 'Unix' or '$(BUILDING_USING_DOTNET)' == 'true'">net7.0</TargetFrameworks>
<OutputType>Library</OutputType>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<DefineConstants>$(DefineConstants);ASSUME_PREVIEW_FSHARP_CORE</DefineConstants>
Expand All @@ -27,6 +27,7 @@
<Compile Include="BuildGraphTests.fs" />
<Compile Include="FsiTests.fs" />
<Compile Include="AssemblySigningAttributes.fs" />
<Compile Include="PrettyNaming.fs" />
<Compile Include="..\..\tests\service\FsUnit.fs">
<Link>CompilerService\FsUnit.fs</Link>
</Compile>
Expand All @@ -46,9 +47,7 @@
<Compile Include="..\..\tests\service\ProjectAnalysisTests.fs">
<Link>CompilerService\ProjectAnalysisTests.fs</Link>
</Compile>
<Compile Include="..\..\tests\service\TokenizerTests.fs">
<Link>CompilerService\TokenizerTests.fs</Link>
</Compile>
<Compile Include="TokenizerTests.fs" />
<!-- TODO: Fix this test
<Compile Include="..\..\tests\service\MultiProjectAnalysisTests.fs">
<Link>CompilerService\MultiProjectAnalysisTests.fs</Link>
Expand All @@ -75,9 +74,7 @@
<Compile Include="..\..\tests\service\ServiceUntypedParseTests.fs">
<Link>CompilerService\ServiceUntypedParseTests.fs</Link>
</Compile>
<Compile Include="..\..\tests\service\TreeVisitorTests.fs">
<Link>CompilerService\TreeVisitorTests.fs</Link>
</Compile>
<Compile Include="TreeVisitorTests.fs" />
</ItemGroup>

<ItemGroup>
Expand Down
72 changes: 72 additions & 0 deletions tests/FSharp.Compiler.UnitTests/PrettyNaming.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
module FSharp.Compiler.Service.Tests.PrettyNaming

open FSharp.Compiler.Syntax.PrettyNaming
open FSharp.Test
open Xunit

// invalid operator name
[<Theory>]
[<InlineData ("op_Dollarfoo", false)>]
// random stuff
[<InlineData ("foo", false)>]
// operator display representations
[<InlineData ("~%%", false)>]
[<InlineData ("~%", false)>]
// not infix operators
[<InlineData ("op_BitwiseOr", false)>]
[<InlineData ("op_Equality", false)>]
// valid logical names
[<InlineData ("op_Splice", true)>]
[<InlineData ("op_SpliceUntyped", true)>]
let ``IsLogicalPrefixOperator`` (logicalName: string, result: bool) =
IsLogicalPrefixOperator logicalName
|> Assert.shouldBe result

// empty string
[<Theory>]
[<InlineData ("", false)>]
// invalid operators
[<InlineData ("op_Dynamic", false)>]
[<InlineData ("op_RangeStep", false)>]
// display representation
[<InlineData ("?<-", false)>]
// correct option
[<InlineData ("op_DynamicAssignment", true)>]
let ``IsLogicalTernaryOperator`` (logicalName: string, result: bool) =
IsLogicalTernaryOperator logicalName
|> Assert.shouldBe result

// words in operator name
[<Theory>]
[<InlineData ("$foo hoo", false)>]
[<InlineData ("@foo hoo", false)>]
// typo in operator name
[<InlineData ("op_Nagation", false)>]
// invalid operator name
[<InlineData ("op_Dollarfoo", false)>]
[<InlineData ("foo", false)>]
[<InlineData ("$foo", false)>]
// random symbols
[<InlineData ("$", false)>]
// operator display representations
[<InlineData ("+", false)>]
[<InlineData ("[]", false)>]
[<InlineData ("::", false)>]
[<InlineData ("~++", false)>]
[<InlineData (".. ..", false)>]
// not infix operators
[<InlineData ("op_Splice", false)>]
[<InlineData ("op_SpliceUntyped", false)>]
// valid logical names
[<InlineData ("op_Addition", true)>]
[<InlineData ("op_Append", true)>]
[<InlineData ("op_ColonColon", true)>]
[<InlineData ("op_BitwiseOr", true)>]
[<InlineData ("op_GreaterThanOrEqual", true)>]
[<InlineData ("op_Dynamic", true)>]
[<InlineData ("op_ArrayLookup", true)>]
[<InlineData ("op_DynamicAssignment", true)>]
[<InlineData ("op_ArrayAssign", true)>]
let ``IsLogicalInfixOpName`` (logicalName: string, result: bool) =
IsLogicalInfixOpName logicalName
|> Assert.shouldBe result
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@

#if INTERACTIVE
#r "../../artifacts/bin/fcs/net461/FSharp.Compiler.Service.dll" // note, build FSharp.Compiler.Service.Tests.fsproj to generate this, this DLL has a public API so can be used from F# Interactive
#r "../../artifacts/bin/fcs/net461/nunit.framework.dll"
#load "FsUnit.fs"
#load "Common.fs"
#r "../../artifacts/bin/fcs/net461/xunit.dll"
#else
module FSharp.Compiler.Service.Tests.TokenizerTests
#endif

open FSharp.Compiler.Tokenization
open FsUnit
open NUnit.Framework
open FSharp.Test
open Xunit

let sourceTok = FSharpSourceTokenizer([], Some "C:\\test.fsx", None, None)

Expand All @@ -30,7 +28,7 @@ let tokenizeLines (lines:string[]) =
let tokenizer = sourceTok.CreateLineTokenizer(line)
yield n, parseLine(line, state, tokenizer) |> List.ofSeq ]

[<Test>]
[<Fact>]
let ``Tokenizer test - simple let with string``() =
let tokenizedLines =
tokenizeLines
Expand All @@ -56,9 +54,9 @@ let ``Tokenizer test - simple let with string``() =
if actual <> expected then
printfn "actual = %A" actual
printfn "expected = %A" expected
Assert.Fail(sprintf "actual and expected did not match,actual =\n%A\nexpected=\n%A\n" actual expected)
actual |> Assert.shouldBeEqualWith expected (sprintf "actual and expected did not match,actual =\n%A\nexpected=\n%A\n" actual expected)

[<Test>]
[<Fact>]
let ``Tokenizer test 2 - single line non-nested string interpolation``() =
let tokenizedLines =
tokenizeLines
Expand Down Expand Up @@ -121,10 +119,9 @@ let ``Tokenizer test 2 - single line non-nested string interpolation``() =
if actual <> expected then
printfn "actual = %A" actual
printfn "expected = %A" expected
Assert.Fail(sprintf "actual and expected did not match,actual =\n%A\nexpected=\n%A\n" actual expected)
actual |> Assert.shouldBeEqualWith expected (sprintf "actual and expected did not match,actual =\n%A\nexpected=\n%A\n" actual expected)


[<Test>]
[<Fact>]
let ``Tokenizer test - multiline non-nested string interpolation``() =
let tokenizedLines =
tokenizeLines
Expand All @@ -147,9 +144,9 @@ let ``Tokenizer test - multiline non-nested string interpolation``() =
if actual <> expected then
printfn "actual = %A" actual
printfn "expected = %A" expected
Assert.Fail(sprintf "actual and expected did not match,actual =\n%A\nexpected=\n%A\n" actual expected)
actual |> Assert.shouldBeEqualWith expected (sprintf "actual and expected did not match,actual =\n%A\nexpected=\n%A\n" actual expected)

[<Test>]
[<Fact>]
// checks nested '{' and nested single-quote strings
let ``Tokenizer test - multi-line nested string interpolation``() =
let tokenizedLines =
Expand Down Expand Up @@ -189,9 +186,9 @@ let ``Tokenizer test - multi-line nested string interpolation``() =
if actual <> expected then
printfn "actual = %A" actual
printfn "expected = %A" expected
Assert.Fail(sprintf "actual and expected did not match,actual =\n%A\nexpected=\n%A\n" actual expected)
actual |> Assert.shouldBeEqualWith expected (sprintf "actual and expected did not match,actual =\n%A\nexpected=\n%A\n" actual expected)

[<Test>]
[<Fact>]
let ``Tokenizer test - single-line nested string interpolation``() =
let tokenizedLines =
tokenizeLines
Expand All @@ -212,10 +209,9 @@ let ``Tokenizer test - single-line nested string interpolation``() =
if actual <> expected then
printfn "actual = %A" actual
printfn "expected = %A" expected
Assert.Fail(sprintf "actual and expected did not match,actual =\n%A\nexpected=\n%A\n" actual expected)

actual |> Assert.shouldBeEqualWith expected (sprintf "actual and expected did not match,actual =\n%A\nexpected=\n%A\n" actual expected)

[<Test>]
[<Fact>]
let ``Unfinished idents``() =
let tokenizedLines =
tokenizeLines
Expand All @@ -232,4 +228,4 @@ let ``Unfinished idents``() =
["IDENT", "``a`"]
["IDENT", "```"]]

actual |> shouldEqual expected
actual |> Assert.shouldBe expected
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module Tests.Service.TreeVisitorTests
open FSharp.Compiler.Service.Tests.Common
open FSharp.Compiler.Text.Position
open FSharp.Compiler.Syntax
open NUnit.Framework
open Xunit

[<Test>]
[<Fact>]
let ``Visit type test`` () =
let visitor =
{ new SyntaxVisitorBase<_>() with
Expand All @@ -21,7 +21,7 @@ let ``Visit type test`` () =
SyntaxTraversal.Traverse(mkPos 1 3, parseTree, visitor)
|> Option.iter (fun _ -> failwith "Should not visit type")

[<Test>]
[<Fact>]
let ``Visit record definition test`` () =
let visitor =
{ new SyntaxVisitorBase<_>() with
Expand All @@ -34,7 +34,7 @@ let ``Visit record definition test`` () =
| Some [ SynField (idOpt = Some id1); SynField (idOpt = Some id2) ] when id1.idText = "A" && id2.idText = "B" -> ()
| _ -> failwith "Did not visit record definition"

[<Test>]
[<Fact>]
let ``Visit union definition test`` () =
let visitor =
{ new SyntaxVisitorBase<_>() with
Expand All @@ -47,7 +47,7 @@ let ``Visit union definition test`` () =
| Some [ SynUnionCase (ident = SynIdent(id1,_)); SynUnionCase (ident = SynIdent(id2,_)) ] when id1.idText = "A" && id2.idText = "B" -> ()
| _ -> failwith "Did not visit union definition"

[<Test>]
[<Fact>]
let ``Visit enum definition test`` () =
let visitor =
{ new SyntaxVisitorBase<_>() with
Expand All @@ -60,7 +60,7 @@ let ``Visit enum definition test`` () =
| Some [ SynEnumCase (ident = SynIdent (id1, _)); SynEnumCase (ident = SynIdent (id2, _)) ] when id1.idText = "A" && id2.idText = "B" -> ()
| _ -> failwith "Did not visit enum definition"

[<Test>]
[<Fact>]
let ``Visit recursive let binding`` () =
let visitor =
{ new SyntaxVisitorBase<_>() with
Expand All @@ -74,4 +74,4 @@ let ``Visit recursive let binding`` () =

match SyntaxTraversal.Traverse(pos0, parseTree, visitor) with
| Some [ SynBinding(valData = SynValData(valInfo = SynValInfo(curriedArgInfos = [ [ SynArgInfo(ident = Some id) ] ]))) ] when id.idText = "n" -> ()
| _ -> failwith "Did not visit recursive let binding"
| _ -> failwith "Did not visit recursive let binding"
69 changes: 0 additions & 69 deletions tests/service/PrettyNaming.fs

This file was deleted.