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 1 commit
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
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<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" />
Expand All @@ -19,6 +20,7 @@
<!-- 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" />
Expand Down
46 changes: 38 additions & 8 deletions samples/OptionAnalyzer.Test/UnitTests.fs
Original file line number Diff line number Diff line change
@@ -1,21 +1,51 @@
module OptionAnalyzer.Test

#nowarn "57"

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

let mutable projectOptions: FSharpProjectOptions = FSharpProjectOptions.zero

[<SetUp>]
let Setup () = ()
let Setup () =
projectOptions <-
mkOptionsFromProject
DotNetVersion.Seven
(Some
{
Name = "Newtonsoft.Json"
Version = "13.0.3"
})

[<Test>]
let ``warnings are emitted`` () =

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

[<Test>]
let ``warning is emitted`` () =
let ``expected warning is emitted`` () =

let source =
"""
module M

open Newtonsoft.Json

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

let notUsed() =
let option : Option<int> = None
option.Value
Expand All @@ -26,11 +56,11 @@ let notUsed() =
Code = "OV001"
Fixes = []
Message = "Option.Value shouldn't be used"
Range = Range.mkRange "A.fs" (Position.mkPos 6 4) (Position.mkPos 6 16)
Range = Range.mkRange "A.fs" (Position.mkPos 10 4) (Position.mkPos 10 16)
Severity = Severity.Warning
Type = "Option.Value analyzer"
}

let msgs = TestHelpers.getAnalyzerMsgs source
Assert.IsNotEmpty msgs
Assert.IsTrue(msgs |> Array.contains expectedMsg)
let ctx = getContext projectOptions source
let msgs = optionValueAnalyzer ctx
Assert.IsTrue(msgs |> List.contains expectedMsg)
Loading