-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from dawedawe/test_infrastructure
Test infrastructure
- Loading branch information
Showing
16 changed files
with
1,717 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
**/bin/**/*.fs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.