Skip to content

Commit

Permalink
- rename namespace "G-Research" to "GR" (#11)
Browse files Browse the repository at this point in the history
- rename TASTCollection to TASTCollecting to be in line with ASTCollecting
- consolidate on Testing.dataFolder
  • Loading branch information
dawedawe authored Oct 4, 2023
1 parent 606cd93 commit f55605b
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 78 deletions.
4 changes: 2 additions & 2 deletions src/FSharp.Analyzers/JsonSerializerOptionsAnalyzer.fs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace ``G-Research``.FSharp.Analyzers
namespace GR.FSharp.Analyzers

open System
open FSharp.Analyzers.SDK
open FSharp.Compiler.Symbols
open FSharp.Compiler.Text
open FSharp.Compiler.Symbols.FSharpExprPatterns
open TASTCollection
open GR.FSharp.Analyzers.TASTCollecting

module JsonSerializerOptionsAnalyzer =

Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Analyzers/StringAnalyzers.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ``G-Research``.FSharp.Analyzers
namespace GR.FSharp.Analyzers

open FSharp.Analyzers.SDK
open FSharp.Compiler.Symbols
Expand Down
4 changes: 2 additions & 2 deletions src/FSharp.Analyzers/TASTCollecting.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace ``G-Research``.FSharp.Analyzers
namespace GR.FSharp.Analyzers

module TASTCollection =
module TASTCollecting =

open FSharp.Compiler.Symbols
open FSharp.Compiler.Text
Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Analyzers/UnionCaseAnalyzer.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ``G-Research``.FSharp.Analyzers
namespace GR.FSharp.Analyzers

open FSharp.Analyzers.SDK
open FSharp.Compiler.CodeAnalysis
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ``G-Research``.FSharp.Analyzers.Tests
namespace GR.FSharp.Analyzers.Tests

module JsonSerializerOptionsAnalyzerTests =

Expand All @@ -7,8 +7,8 @@ module JsonSerializerOptionsAnalyzerTests =
open NUnit.Framework
open FSharp.Compiler.CodeAnalysis
open FSharp.Analyzers.SDK.Testing
open ``G-Research``.FSharp.Analyzers
open Testing
open GR.FSharp.Analyzers
open GR.FSharp.Analyzers.Tests.Common

let mutable projectOptions : FSharpProjectOptions = FSharpProjectOptions.zero

Expand Down
7 changes: 3 additions & 4 deletions tests/FSharp.Analyzers.Tests/StringAnalyzerTests.fs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
namespace ``G-Research``.FSharp.Analyzers.Tests
namespace GR.FSharp.Analyzers.Tests

module StringAnalyzerTests =

open System.Collections
open System.IO
open FSharp.Compiler.CodeAnalysis
open NUnit.Framework
open FSharp.Analyzers.SDK
open FSharp.Analyzers.SDK.Testing
open ``G-Research``.FSharp.Analyzers
open Testing
open GR.FSharp.Analyzers
open GR.FSharp.Analyzers.Tests.Common

let mutable projectOptions : FSharpProjectOptions = FSharpProjectOptions.zero

Expand Down
116 changes: 57 additions & 59 deletions tests/FSharp.Analyzers.Tests/Testing.fs
Original file line number Diff line number Diff line change
@@ -1,59 +1,57 @@
namespace ``G-Research``.FSharp.Analyzers.Tests

module Testing =

open System
open System.IO
open System.Threading.Tasks
open NUnit.Framework
open FSharp.Analyzers.SDK
open FSharp.Analyzers.SDK.Testing

let shouldUpdateBaseline () =
Environment.GetEnvironmentVariable "TEST_UPDATE_BSL"
|> Option.ofObj
|> Option.map (fun v -> v.Trim () = "1")
|> Option.defaultValue false

let assertExpected sourceFile messages =
task {
let actualContents =
messages
|> List.map (fun (m : Message) ->
$"%s{m.Code} | %A{m.Severity} | (%i{m.Range.StartLine},%i{m.Range.StartColumn} - %i{m.Range.EndLine},%i{m.Range.EndColumn}) | %s{m.Message}"
)
|> String.concat "\n"
|> fun contents -> String.Concat (contents, "\n")

let expectedFile = $"%s{sourceFile}.expected"
let actualFile = $"%s{sourceFile}.actual"

let! expectedContents =
if File.Exists expectedFile then
File.ReadAllTextAsync expectedFile
else
Task.FromResult "No baseline was found"

let areEqual = expectedContents = actualContents

if shouldUpdateBaseline () then
do! File.WriteAllTextAsync (expectedFile, actualContents)
elif not areEqual then
do! File.WriteAllTextAsync (actualFile, actualContents)
elif File.Exists actualFile then
File.Delete actualFile

Assert.AreEqual (expectedContents, actualContents)
}

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

let constructTestCaseEnumerator (subDataPath : string array) =
let testsDirectory = Path.Combine (dataFolder, Path.Combine subDataPath)

Directory.EnumerateFiles (testsDirectory, "*.fs")
|> Seq.map (fun f ->
let fileName = Path.GetRelativePath (dataFolder, f)
[| fileName :> obj |]
)
|> fun s -> s.GetEnumerator ()
module GR.FSharp.Analyzers.Tests.Common

open System
open System.IO
open System.Threading.Tasks
open NUnit.Framework
open FSharp.Analyzers.SDK
open FSharp.Analyzers.SDK.Testing

let shouldUpdateBaseline () =
Environment.GetEnvironmentVariable "TEST_UPDATE_BSL"
|> Option.ofObj
|> Option.map (fun v -> v.Trim () = "1")
|> Option.defaultValue false

let assertExpected sourceFile messages =
task {
let actualContents =
messages
|> List.map (fun (m : Message) ->
$"%s{m.Code} | %A{m.Severity} | (%i{m.Range.StartLine},%i{m.Range.StartColumn} - %i{m.Range.EndLine},%i{m.Range.EndColumn}) | %s{m.Message}"
)
|> String.concat "\n"
|> fun contents -> String.Concat (contents, "\n")

let expectedFile = $"%s{sourceFile}.expected"
let actualFile = $"%s{sourceFile}.actual"

let! expectedContents =
if File.Exists expectedFile then
File.ReadAllTextAsync expectedFile
else
Task.FromResult "No baseline was found"

let areEqual = expectedContents = actualContents

if shouldUpdateBaseline () then
do! File.WriteAllTextAsync (expectedFile, actualContents)
elif not areEqual then
do! File.WriteAllTextAsync (actualFile, actualContents)
elif File.Exists actualFile then
File.Delete actualFile

Assert.AreEqual (expectedContents, actualContents)
}

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

let constructTestCaseEnumerator (subDataPath : string array) =
let testsDirectory = Path.Combine (dataFolder, Path.Combine subDataPath)

Directory.EnumerateFiles (testsDirectory, "*.fs")
|> Seq.map (fun f ->
let fileName = Path.GetRelativePath (dataFolder, f)
[| fileName :> obj |]
)
|> fun s -> s.GetEnumerator ()
10 changes: 4 additions & 6 deletions tests/FSharp.Analyzers.Tests/UnionCaseAnalyzerTests.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ``G-Research``.FSharp.Analyzers.Tests
namespace GR.FSharp.Analyzers.Tests

module UnionCaseAnalyzerTests =

Expand All @@ -7,8 +7,8 @@ module UnionCaseAnalyzerTests =
open NUnit.Framework
open FSharp.Compiler.CodeAnalysis
open FSharp.Analyzers.SDK.Testing
open ``G-Research``.FSharp.Analyzers
open Testing
open GR.FSharp.Analyzers
open GR.FSharp.Analyzers.Tests.Common

let mutable projectOptions : FSharpProjectOptions = FSharpProjectOptions.zero

Expand All @@ -21,7 +21,6 @@ module UnionCaseAnalyzerTests =
}

type TestCases() =
static member DataFolder = Path.Combine (__SOURCE_DIRECTORY__, "..", "data")

interface IEnumerable with
member _.GetEnumerator () : IEnumerator =
Expand All @@ -30,7 +29,6 @@ module UnionCaseAnalyzerTests =
[<TestCaseSource(typeof<TestCases>)>]
let UnionCaseTests (fileName : string) =
task {
let dataFolder = TestCases.DataFolder
let fileName = Path.Combine (dataFolder, fileName)

let! messages =
Expand All @@ -50,7 +48,7 @@ module UnionCaseAnalyzerTests =
[<TestCaseSource(typeof<NegativeTestCases>)>]
let NegativeTests (fileName : string) =
task {
let fileName = Path.Combine (TestCases.DataFolder, fileName)
let fileName = Path.Combine (dataFolder, fileName)

let! messages =
File.ReadAllText fileName
Expand Down

0 comments on commit f55605b

Please sign in to comment.