Skip to content

Commit

Permalink
Move data folder into FSharp.Analyzers.Tests. (#62)
Browse files Browse the repository at this point in the history
* Move data folder into FSharp.Analyzers.Tests.

* Update path in tests.

* Update scaffold pipeline.
  • Loading branch information
nojaf authored Jan 26, 2024
1 parent d45a09e commit c38454e
Show file tree
Hide file tree
Showing 208 changed files with 87 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .fantomasignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
tests/data
tests/FSharp.Analyzers.Tests/data
6 changes: 3 additions & 3 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pipeline "EnsureTrailingNewline" {
stage "TestData" {
run (fun _ ->
Directory.EnumerateFiles (
Path.Combine (__SOURCE_DIRECTORY__, "tests", "data"),
Path.Combine (__SOURCE_DIRECTORY__, "tests", "FSharp.Analyzers.Tests", "data"),
"*.*",
SearchOption.AllDirectories
)
Expand Down Expand Up @@ -77,7 +77,7 @@ let getLastCompileItem (fsproj : string) =
pipeline "NewAnalyzer" {
stage "Scaffold" {
run (fun _ctx ->
Console.Write ("Enter analyzer name:")
Console.Write "Enter analyzer name:"
let analyzerName = Console.ReadLine().Trim ()

let analyzerName =
Expand Down Expand Up @@ -195,7 +195,7 @@ let NegativeTests (fileName : string) =
printfn "Created %s" analyzerTestsFilePath

let testFolder =
DirectoryInfo (__SOURCE_DIRECTORY__ </> "tests/data" </> testFolderName)
DirectoryInfo (__SOURCE_DIRECTORY__ </> "tests/FSharp.Analyzers.Tests/data" </> testFolderName)

testFolder.Create ()
let sampleFilePath = testFolder.FullName </> "Sample.fs"
Expand Down
2 changes: 1 addition & 1 deletion tests/FSharp.Analyzers.Tests/Common.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ let assertExpected sourceFile messages =
Assert.That (actualContents, Is.EqualTo expectedContents)
}

let dataFolder = Path.Combine (__SOURCE_DIRECTORY__, "..", "data")
let dataFolder = Path.Combine (__SOURCE_DIRECTORY__, "data")

let constructTestCaseEnumeratorAux (files : string seq) : IEnumerator =
files
Expand Down
75 changes: 39 additions & 36 deletions tests/FSharp.Analyzers.Tests/FSharp.Analyzers.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
<GenerateProgramFile>false</GenerateProgramFile>
<IsTestProject>true</IsTestProject>
<AssemblyName>G-Research.FSharp.Analyzers.Tests</AssemblyName>
</PropertyGroup>
<ItemGroup>
<Compile Include="Common.fs" />
<Compile Include="StringAnalyzerTests.fs" />
<Compile Include="PartialAppAnalyzerTests.fs" />
<Compile Include="JsonSerializerOptionsAnalyzerTests.fs" />
<Compile Include="UnionCaseAnalyzerTests.fs" />
<Compile Include="VirtualCallAnalyzerTests.fs" />
<Compile Include="LoggingArgFuncNotFullyAppliedAnalyzerTests.fs" />
<Compile Include="LoggingTemplateMissingValuesAnalyzerTests.fs" />
<Compile Include="TypeAnnotateStringFunctionAnalyzerTests.fs" />
<Compile Include="ImmutableCollectionEqualityAnalyzerTests.fs" />
<Compile Include="TypedInterpolatedStringsAnalyzerTests.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="FSharp.Core" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="coverlet.collector" />
</ItemGroup>
<ItemGroup Condition="'$(UseLocalAnalyzersSDK)' == 'false'">
<PackageReference Include="FSharp.Analyzers.SDK.Testing" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\FSharp.Analyzers\FSharp.Analyzers.fsproj" />
</ItemGroup>
<ItemGroup Condition="'$(UseLocalAnalyzersSDK)' == 'true'">
<ProjectReference Include="$(LocalAnalyzersSDKRepo)/src/FSharp.Analyzers.SDK.Testing/FSharp.Analyzers.SDK.Testing.fsproj" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
<GenerateProgramFile>false</GenerateProgramFile>
<IsTestProject>true</IsTestProject>
<AssemblyName>G-Research.FSharp.Analyzers.Tests</AssemblyName>
</PropertyGroup>
<ItemGroup>
<Compile Include="Common.fs"/>
<Compile Include="StringAnalyzerTests.fs"/>
<Compile Include="PartialAppAnalyzerTests.fs"/>
<Compile Include="JsonSerializerOptionsAnalyzerTests.fs"/>
<Compile Include="UnionCaseAnalyzerTests.fs"/>
<Compile Include="VirtualCallAnalyzerTests.fs"/>
<Compile Include="LoggingArgFuncNotFullyAppliedAnalyzerTests.fs"/>
<Compile Include="LoggingTemplateMissingValuesAnalyzerTests.fs"/>
<Compile Include="TypeAnnotateStringFunctionAnalyzerTests.fs"/>
<Compile Include="ImmutableCollectionEqualityAnalyzerTests.fs"/>
<Compile Include="TypedInterpolatedStringsAnalyzerTests.fs"/>
</ItemGroup>
<ItemGroup>
<None Include="data\**\*.fs*" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="FSharp.Core"/>
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
<PackageReference Include="NUnit"/>
<PackageReference Include="NUnit3TestAdapter"/>
<PackageReference Include="coverlet.collector"/>
</ItemGroup>
<ItemGroup Condition="'$(UseLocalAnalyzersSDK)' == 'false'">
<PackageReference Include="FSharp.Analyzers.SDK.Testing"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\FSharp.Analyzers\FSharp.Analyzers.fsproj"/>
</ItemGroup>
<ItemGroup Condition="'$(UseLocalAnalyzersSDK)' == 'true'">
<ProjectReference Include="$(LocalAnalyzersSDKRepo)/src/FSharp.Analyzers.SDK.Testing/FSharp.Analyzers.SDK.Testing.fsproj"/>
</ItemGroup>
</Project>
97 changes: 43 additions & 54 deletions tests/FSharp.Analyzers.Tests/PartialAppAnalyzerTests.fs
Original file line number Diff line number Diff line change
@@ -1,68 +1,57 @@
namespace GR.FSharp.Analyzers.Tests
module GR.FSharp.Analyzers.Tests.PartialAppAnalyzerTests

module PartialAppAnalyzerTests =
open System.Collections
open System.IO
open NUnit.Framework
open FSharp.Compiler.CodeAnalysis
open FSharp.Analyzers.SDK.Testing
open GR.FSharp.Analyzers
open GR.FSharp.Analyzers.Tests.Common

open System.Collections
open System.IO
open NUnit.Framework
open FSharp.Compiler.CodeAnalysis
open FSharp.Analyzers.SDK.Testing
open GR.FSharp.Analyzers
open GR.FSharp.Analyzers.Tests.Common
let mutable projectOptions : FSharpProjectOptions = FSharpProjectOptions.zero

let mutable projectOptions : FSharpProjectOptions = FSharpProjectOptions.zero
[<SetUp>]
let Setup () =
task {
let! options = mkOptionsFromProject "net7.0" []

[<SetUp>]
let Setup () =
task {
let! options = mkOptionsFromProject "net7.0" []
projectOptions <- options
}

projectOptions <- options
}
type TestCases() =

type TestCases() =
static member DataFolder = Path.Combine (__SOURCE_DIRECTORY__, "..", "data")
interface IEnumerable with
member _.GetEnumerator () : IEnumerator =
constructTestCaseEnumerator [| "partialapp" |]

interface IEnumerable with
member _.GetEnumerator () : IEnumerator =
let testsDirectory = Path.Combine (TestCases.DataFolder, "partialapp")
[<TestCaseSource(typeof<TestCases>)>]
let PartialAppTests (fileName : string) =
task {
let fileName = Path.Combine (dataFolder, fileName)

Directory.EnumerateFiles (testsDirectory, "*.fs")
|> Seq.map (fun f ->
let fileName = Path.GetRelativePath (TestCases.DataFolder, f)
[| fileName :> obj |]
)
|> fun s -> s.GetEnumerator ()
let! messages =
File.ReadAllText fileName
|> getContext projectOptions
|> PartialAppAnalyzer.partialAppCliAnalyzer

[<TestCaseSource(typeof<TestCases>)>]
let PartialAppTests (fileName : string) =
task {
let dataFolder = TestCases.DataFolder
let fileName = Path.Combine (dataFolder, fileName)
do! assertExpected fileName messages
}

let! messages =
File.ReadAllText fileName
|> getContext projectOptions
|> PartialAppAnalyzer.partialAppCliAnalyzer
type NegativeTestCases() =

do! assertExpected fileName messages
}
interface IEnumerable with
member _.GetEnumerator () : IEnumerator =
constructTestCaseEnumerator [| "partialapp" ; "negative" |]

type NegativeTestCases() =
[<TestCaseSource(typeof<NegativeTestCases>)>]
let NegativeTests (fileName : string) =
task {
let fileName = Path.Combine (dataFolder, fileName)

interface IEnumerable with
member _.GetEnumerator () : IEnumerator =
constructTestCaseEnumerator [| "partialapp" ; "negative" |]
let! messages =
File.ReadAllText fileName
|> getContext projectOptions
|> PartialAppAnalyzer.partialAppCliAnalyzer

[<TestCaseSource(typeof<NegativeTestCases>)>]
let NegativeTests (fileName : string) =
task {
let fileName = Path.Combine (dataFolder, fileName)

let! messages =
File.ReadAllText fileName
|> getContext projectOptions
|> PartialAppAnalyzer.partialAppCliAnalyzer

Assert.That (messages, Is.Empty)
}
Assert.That (messages, Is.Empty)
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit c38454e

Please sign in to comment.