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

Test infrastructure #88

Merged
merged 20 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .fantomasignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/bin/**/*.fs
47 changes: 27 additions & 20 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<MsBuildPackageVersion>17.2.0</MsBuildPackageVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="FSharp.Core" Version="7.0.400" />
<PackageVersion Include="FSharp.Compiler.Service" Version="43.7.400" />
<PackageVersion Include="Ionide.KeepAChangelog.Tasks" Version="0.1.8" PrivateAssets="all" />
<PackageVersion Include="McMaster.NETCore.Plugins" Version="1.4.0" />
<PackageVersion Include="Argu" Version="6.1.1" />
<PackageVersion Include="Glob" Version="1.1.9" />
<PackageVersion Include="Ionide.ProjInfo.ProjectSystem" Version="0.62.0" />
<PackageVersion Include="Microsoft.Build" Version="$(MsBuildPackageVersion)" ExcludeAssets="runtime" />
<PackageVersion Include="Microsoft.Build.Framework" Version="$(MsBuildPackageVersion)" ExcludeAssets="runtime" />
<PackageVersion Include="Microsoft.Build.Tasks.Core" Version="$(MsBuildPackageVersion)" ExcludeAssets="runtime" />
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="$(MsBuildPackageVersion)" ExcludeAssets="runtime" />
<PackageVersion Include="Microsoft.Build.Locator" Version="1.4.1" />
<!-- Need to update Directory.Build.props DotNet.ReproducibleBuilds.Isolated version when updating this-->
<PackageVersion Include="DotNet.ReproducibleBuilds" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<MsBuildPackageVersion>17.2.0</MsBuildPackageVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="CliWrap" Version="3.6.4" />
<PackageVersion Include="FSharp.Core" Version="7.0.400" />
<PackageVersion Include="FSharp.Compiler.Service" Version="43.7.400" />
<PackageVersion Include="Ionide.KeepAChangelog.Tasks" Version="0.1.8" PrivateAssets="all" />
<PackageVersion Include="McMaster.NETCore.Plugins" Version="1.4.0" />
<PackageVersion Include="Argu" Version="6.1.1" />
<PackageVersion Include="Glob" Version="1.1.9" />
<PackageVersion Include="Ionide.ProjInfo.ProjectSystem" Version="0.62.0" />
<PackageVersion Include="Microsoft.Build" Version="$(MsBuildPackageVersion)" ExcludeAssets="runtime" />
<PackageVersion Include="Microsoft.Build.Framework" Version="$(MsBuildPackageVersion)" ExcludeAssets="runtime" />
<PackageVersion Include="Microsoft.Build.Tasks.Core" Version="$(MsBuildPackageVersion)" ExcludeAssets="runtime" />
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="$(MsBuildPackageVersion)" ExcludeAssets="runtime" />
<PackageVersion Include="Microsoft.Build.Locator" Version="1.4.1" />
<!-- Need to update Directory.Build.props DotNet.ReproducibleBuilds.Isolated version when updating this-->
<PackageVersion Include="DotNet.ReproducibleBuilds" Version="1.1.1" PrivateAssets="All" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageVersion Include="MSBuild.StructuredLogger" Version="2.1.815" />
<PackageVersion Include="NUnit" Version="3.13.3" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageVersion Include="NUnit.Analyzers" Version="3.6.1" />
<PackageVersion Include="coverlet.collector" Version="3.2.0" />
</ItemGroup>
</Project>
15 changes: 15 additions & 0 deletions FSharp.Analyzers.SDK.sln
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
.github\workflows\ci.yml = .github\workflows\ci.yml
EndProjectSection
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "OptionAnalyzer.Test", "samples\OptionAnalyzer.Test\OptionAnalyzer.Test.fsproj", "{9A9AC3F8-E34B-4C30-A52A-A507D6E0CA01}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -83,12 +85,25 @@ Global
{E4FAFA1A-4E26-4553-81F2-844C94B85349}.Release|x64.Build.0 = Release|Any CPU
{E4FAFA1A-4E26-4553-81F2-844C94B85349}.Release|x86.ActiveCfg = Release|Any CPU
{E4FAFA1A-4E26-4553-81F2-844C94B85349}.Release|x86.Build.0 = Release|Any CPU
{9A9AC3F8-E34B-4C30-A52A-A507D6E0CA01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9A9AC3F8-E34B-4C30-A52A-A507D6E0CA01}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A9AC3F8-E34B-4C30-A52A-A507D6E0CA01}.Debug|x64.ActiveCfg = Debug|Any CPU
{9A9AC3F8-E34B-4C30-A52A-A507D6E0CA01}.Debug|x64.Build.0 = Debug|Any CPU
{9A9AC3F8-E34B-4C30-A52A-A507D6E0CA01}.Debug|x86.ActiveCfg = Debug|Any CPU
{9A9AC3F8-E34B-4C30-A52A-A507D6E0CA01}.Debug|x86.Build.0 = Debug|Any CPU
{9A9AC3F8-E34B-4C30-A52A-A507D6E0CA01}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A9AC3F8-E34B-4C30-A52A-A507D6E0CA01}.Release|Any CPU.Build.0 = Release|Any CPU
{9A9AC3F8-E34B-4C30-A52A-A507D6E0CA01}.Release|x64.ActiveCfg = Release|Any CPU
{9A9AC3F8-E34B-4C30-A52A-A507D6E0CA01}.Release|x64.Build.0 = Release|Any CPU
{9A9AC3F8-E34B-4C30-A52A-A507D6E0CA01}.Release|x86.ActiveCfg = Release|Any CPU
{9A9AC3F8-E34B-4C30-A52A-A507D6E0CA01}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{C1D38B7A-0193-46AA-B033-ADBBF642AAA0} = {95A9FA19-723D-4D2C-A936-F0B45656B0D6}
{96582FA1-CF16-455B-AF80-D825C1A40DB2} = {95A9FA19-723D-4D2C-A936-F0B45656B0D6}
{E4FAFA1A-4E26-4553-81F2-844C94B85349} = {0FE81935-26A8-45E1-A62E-5148C73BA6A2}
{7A9A1C69-ADF2-421C-90F8-AB3304D6E197} = {937D2F4A-7EF4-469F-8DDA-3D75F3D32C69}
{452A16E1-35C3-4392-B969-548E701748D5} = {7A9A1C69-ADF2-421C-90F8-AB3304D6E197}
{9A9AC3F8-E34B-4C30-A52A-A507D6E0CA01} = {0FE81935-26A8-45E1-A62E-5148C73BA6A2}
EndGlobalSection
EndGlobal
32 changes: 32 additions & 0 deletions samples/OptionAnalyzer.Test/OptionAnalyzer.Test.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RollForward>LatestMajor</RollForward>

<IsPackable>false</IsPackable>
<GenerateProgramFile>false</GenerateProgramFile>
<IsTestProject>true</IsTestProject>
<OutputType>Library</OutputType>
</PropertyGroup>

<ItemGroup>
<Compile Include="UnitTests.fs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="FSharp.Core" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="NUnit.Analyzers" />
<PackageReference Include="coverlet.collector" />
<PackageReference Include="FSharp.Compiler.Service"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\FSharp.Analyzers.SDK\FSharp.Analyzers.SDK.fsproj" />
<ProjectReference Include="..\OptionAnalyzer\OptionAnalyzer.fsproj" />
</ItemGroup>

</Project>
82 changes: 82 additions & 0 deletions samples/OptionAnalyzer.Test/UnitTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
module OptionAnalyzer.Test

open FSharp.Compiler.CodeAnalysis
open NUnit.Framework
open FSharp.Compiler.Text
open FSharp.Analyzers.SDK
open FSharp.Analyzers.SDK.Testing

let mutable projectOptions: FSharpProjectOptions = FSharpProjectOptions.zero

[<SetUp>]
let Setup () =
task {
let! opts =
mkOptionsFromProject
"net7.0"
[
{
Name = "Newtonsoft.Json"
Version = "13.0.3"
}
{
Name = "Fantomas.FCS"
Version = "6.2.0"
}
]

projectOptions <- opts
}

[<Test>]
let ``warnings are emitted`` () =
async {
let source =
"""
module M

let notUsed() =
let option : Option<int> = None
option.Value
"""

let ctx = getContext projectOptions source
let! msgs = optionValueAnalyzer ctx
Assert.IsNotEmpty msgs
Assert.IsTrue(Assert.messageContains "Option.Value" msgs[0])

}

[<Test>]
let ``expected warning is emitted`` () =
async {
let source =
"""
module M

open Newtonsoft.Json
open Fantomas.FCS

let json = JsonConvert.SerializeObject([1;2;3])

let p = Fantomas.FCS.Text.Position.mkPos 23 2

let notUsed() =
let option : Option<int> = None
option.Value
"""

let expectedMsg =
{
Code = "OV001"
Fixes = []
Message = "Option.Value shouldn't be used"
Range = Range.mkRange "A.fs" (Position.mkPos 13 4) (Position.mkPos 13 16)
Severity = Severity.Warning
Type = "Option.Value analyzer"
}

let ctx = getContext projectOptions source
let! msgs = optionValueAnalyzer ctx
Assert.IsTrue(msgs |> List.contains expectedMsg)
}
Loading