Skip to content

Commit

Permalink
Add more tests for nested modules and fsx files
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaid-Ajaj committed Jun 6, 2021
1 parent 34e0cea commit 1d1a3ea
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 66 deletions.
13 changes: 8 additions & 5 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
### 3.26.1 - 2021-05-06
* Fix nuget packaging

### 3.26.0 - 2021-05-06
* Allow the SQL parser to handle comments and update to latest FSharp Analyzers SDK

### 3.25.0 - 2021-04-26
* Improvements to the SQL parser
* Improvements to the SQL parser

### 3.24.0 - 2021-04-09
* fixes dynamically applied parameters with more complex expressions
* fixes dynamically applied parameters with more complex expressions

### 3.23.0 - 2021-03-26
* Detect typed let bindings
* Detect typed let bindings

### 3.22.1 - 2021-02-09
* Let the analyzer continue its work when it comes across enum types
* Let the analyzer continue its work when it comes across enum types

### 3.22.0 - 2020-12-08
* Detect queries within sequential expressions or statements
Expand All @@ -32,7 +35,7 @@
* Analyze top level do expressions

### 3.15.0 - 2020-09-15
* Analyze transaction parameter sets
* Analyze transaction parameter sets
* Allow for literal queries on transactions

### 3.14.0 - 2020-09-07
Expand Down
10 changes: 5 additions & 5 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ let dotnetPack ctx =
if exitCode <> 0 then
failwith "dotnet pack failed"
else
match Shell.Exec("dotnet", "publish -c Release --framework netcoreapp2.0", "src" </> "NpgsqlFSharpAnalyzer") with
match Shell.Exec("dotnet", "publish -c Release --framework net5.0", "src" </> "NpgsqlFSharpAnalyzer") with
| 0 ->
let nupkg =
System.IO.Directory.GetFiles(__SOURCE_DIRECTORY__ </> "dist")
Expand All @@ -280,7 +280,7 @@ let dotnetPack ctx =
let nugetParent = DirectoryInfo(nupkg).Parent.FullName
let nugetFileName = IO.Path.GetFileNameWithoutExtension(nupkg)

let publishPath = "src" </> "NpgsqlFSharpAnalyzer" </> "bin" </> "Release" </> "netcoreapp2.0" </> "publish"
let publishPath = "src" </> "NpgsqlFSharpAnalyzer" </> "bin" </> "Release" </> "net5.0" </> "publish"
ZipFile.ExtractToDirectory(nupkg, nugetParent </> nugetFileName)
let nuspecFile = nugetParent </> nugetFileName </> "NpgsqlFSharpAnalyzer.nuspec"
// rewriteNuspec
Expand All @@ -293,8 +293,8 @@ let dotnetPack ctx =
|> fun content -> File.WriteAllLines(nuspecFile, content)

File.Delete nupkg
Shell.deleteDir (nugetParent </> nugetFileName </> "lib" </> "netcoreapp2.0")
Shell.copyDir (nugetParent </> nugetFileName </> "lib" </> "netcoreapp2.0") publishPath (fun _ -> true)
Shell.deleteDir (nugetParent </> nugetFileName </> "lib" </> "net5.0")
Shell.copyDir (nugetParent </> nugetFileName </> "lib" </> "net5.0") publishPath (fun _ -> true)
ZipFile.CreateFromDirectory(nugetParent </> nugetFileName, nupkg)
Shell.deleteDir(nugetParent </> nugetFileName)
| _ ->
Expand Down Expand Up @@ -325,7 +325,7 @@ let packUbik _ =
]

let exitCode = Shell.Exec("dotnet", String.concat " " args, "src" </> "Ubik")
if exitCode <> 0
if exitCode <> 0
then failwith "dotnet pack failed"

Target.create "PackUbik" packUbik
Expand Down
16 changes: 8 additions & 8 deletions src/FParsec/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ open System.Reflection

[<assembly: AssemblyTitleAttribute("FParsec")>]
[<assembly: AssemblyProductAttribute("NpgsqlFSharpAnalyzer")>]
[<assembly: AssemblyVersionAttribute("3.26.0")>]
[<assembly: AssemblyVersionAttribute("3.26.1")>]
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2021-05-06T00:00:00.0000000")>]
[<assembly: AssemblyFileVersionAttribute("3.26.0")>]
[<assembly: AssemblyInformationalVersionAttribute("3.26.0")>]
[<assembly: AssemblyFileVersionAttribute("3.26.1")>]
[<assembly: AssemblyInformationalVersionAttribute("3.26.1")>]
[<assembly: AssemblyMetadataAttribute("ReleaseChannel","release")>]
[<assembly: AssemblyMetadataAttribute("GitHash","89f1b78fc64964e3bc01f0738f8780c3f12099ae")>]
[<assembly: AssemblyMetadataAttribute("GitHash","237f46ee0d5505c9adc4e1615dd231b89cb1b992")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "FParsec"
let [<Literal>] AssemblyProduct = "NpgsqlFSharpAnalyzer"
let [<Literal>] AssemblyVersion = "3.26.0"
let [<Literal>] AssemblyVersion = "3.26.1"
let [<Literal>] AssemblyMetadata_ReleaseDate = "2021-05-06T00:00:00.0000000"
let [<Literal>] AssemblyFileVersion = "3.26.0"
let [<Literal>] AssemblyInformationalVersion = "3.26.0"
let [<Literal>] AssemblyFileVersion = "3.26.1"
let [<Literal>] AssemblyInformationalVersion = "3.26.1"
let [<Literal>] AssemblyMetadata_ReleaseChannel = "release"
let [<Literal>] AssemblyMetadata_GitHash = "89f1b78fc64964e3bc01f0738f8780c3f12099ae"
let [<Literal>] AssemblyMetadata_GitHash = "237f46ee0d5505c9adc4e1615dd231b89cb1b992"
16 changes: 8 additions & 8 deletions src/NpgsqlFSharpAnalyzer.Core/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ open System.Reflection

[<assembly: AssemblyTitleAttribute("NpgsqlFSharpAnalyzer.Core")>]
[<assembly: AssemblyProductAttribute("NpgsqlFSharpAnalyzer")>]
[<assembly: AssemblyVersionAttribute("3.26.0")>]
[<assembly: AssemblyVersionAttribute("3.26.1")>]
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2021-05-06T00:00:00.0000000")>]
[<assembly: AssemblyFileVersionAttribute("3.26.0")>]
[<assembly: AssemblyInformationalVersionAttribute("3.26.0")>]
[<assembly: AssemblyFileVersionAttribute("3.26.1")>]
[<assembly: AssemblyInformationalVersionAttribute("3.26.1")>]
[<assembly: AssemblyMetadataAttribute("ReleaseChannel","release")>]
[<assembly: AssemblyMetadataAttribute("GitHash","89f1b78fc64964e3bc01f0738f8780c3f12099ae")>]
[<assembly: AssemblyMetadataAttribute("GitHash","237f46ee0d5505c9adc4e1615dd231b89cb1b992")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "NpgsqlFSharpAnalyzer.Core"
let [<Literal>] AssemblyProduct = "NpgsqlFSharpAnalyzer"
let [<Literal>] AssemblyVersion = "3.26.0"
let [<Literal>] AssemblyVersion = "3.26.1"
let [<Literal>] AssemblyMetadata_ReleaseDate = "2021-05-06T00:00:00.0000000"
let [<Literal>] AssemblyFileVersion = "3.26.0"
let [<Literal>] AssemblyInformationalVersion = "3.26.0"
let [<Literal>] AssemblyFileVersion = "3.26.1"
let [<Literal>] AssemblyInformationalVersion = "3.26.1"
let [<Literal>] AssemblyMetadata_ReleaseChannel = "release"
let [<Literal>] AssemblyMetadata_GitHash = "89f1b78fc64964e3bc01f0738f8780c3f12099ae"
let [<Literal>] AssemblyMetadata_GitHash = "237f46ee0d5505c9adc4e1615dd231b89cb1b992"
16 changes: 8 additions & 8 deletions src/NpgsqlFSharpAnalyzer/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ open System.Reflection

[<assembly: AssemblyTitleAttribute("NpgsqlFSharpAnalyzer")>]
[<assembly: AssemblyProductAttribute("NpgsqlFSharpAnalyzer")>]
[<assembly: AssemblyVersionAttribute("3.26.0")>]
[<assembly: AssemblyVersionAttribute("3.26.1")>]
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2021-05-06T00:00:00.0000000")>]
[<assembly: AssemblyFileVersionAttribute("3.26.0")>]
[<assembly: AssemblyInformationalVersionAttribute("3.26.0")>]
[<assembly: AssemblyFileVersionAttribute("3.26.1")>]
[<assembly: AssemblyInformationalVersionAttribute("3.26.1")>]
[<assembly: AssemblyMetadataAttribute("ReleaseChannel","release")>]
[<assembly: AssemblyMetadataAttribute("GitHash","89f1b78fc64964e3bc01f0738f8780c3f12099ae")>]
[<assembly: AssemblyMetadataAttribute("GitHash","237f46ee0d5505c9adc4e1615dd231b89cb1b992")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "NpgsqlFSharpAnalyzer"
let [<Literal>] AssemblyProduct = "NpgsqlFSharpAnalyzer"
let [<Literal>] AssemblyVersion = "3.26.0"
let [<Literal>] AssemblyVersion = "3.26.1"
let [<Literal>] AssemblyMetadata_ReleaseDate = "2021-05-06T00:00:00.0000000"
let [<Literal>] AssemblyFileVersion = "3.26.0"
let [<Literal>] AssemblyInformationalVersion = "3.26.0"
let [<Literal>] AssemblyFileVersion = "3.26.1"
let [<Literal>] AssemblyInformationalVersion = "3.26.1"
let [<Literal>] AssemblyMetadata_ReleaseChannel = "release"
let [<Literal>] AssemblyMetadata_GitHash = "89f1b78fc64964e3bc01f0738f8780c3f12099ae"
let [<Literal>] AssemblyMetadata_GitHash = "237f46ee0d5505c9adc4e1615dd231b89cb1b992"
16 changes: 8 additions & 8 deletions src/NpgsqlFSharpParser/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ open System.Reflection

[<assembly: AssemblyTitleAttribute("NpgsqlFSharpParser")>]
[<assembly: AssemblyProductAttribute("NpgsqlFSharpAnalyzer")>]
[<assembly: AssemblyVersionAttribute("3.26.0")>]
[<assembly: AssemblyVersionAttribute("3.26.1")>]
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2021-05-06T00:00:00.0000000")>]
[<assembly: AssemblyFileVersionAttribute("3.26.0")>]
[<assembly: AssemblyInformationalVersionAttribute("3.26.0")>]
[<assembly: AssemblyFileVersionAttribute("3.26.1")>]
[<assembly: AssemblyInformationalVersionAttribute("3.26.1")>]
[<assembly: AssemblyMetadataAttribute("ReleaseChannel","release")>]
[<assembly: AssemblyMetadataAttribute("GitHash","89f1b78fc64964e3bc01f0738f8780c3f12099ae")>]
[<assembly: AssemblyMetadataAttribute("GitHash","237f46ee0d5505c9adc4e1615dd231b89cb1b992")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "NpgsqlFSharpParser"
let [<Literal>] AssemblyProduct = "NpgsqlFSharpAnalyzer"
let [<Literal>] AssemblyVersion = "3.26.0"
let [<Literal>] AssemblyVersion = "3.26.1"
let [<Literal>] AssemblyMetadata_ReleaseDate = "2021-05-06T00:00:00.0000000"
let [<Literal>] AssemblyFileVersion = "3.26.0"
let [<Literal>] AssemblyInformationalVersion = "3.26.0"
let [<Literal>] AssemblyFileVersion = "3.26.1"
let [<Literal>] AssemblyInformationalVersion = "3.26.1"
let [<Literal>] AssemblyMetadata_ReleaseChannel = "release"
let [<Literal>] AssemblyMetadata_GitHash = "89f1b78fc64964e3bc01f0738f8780c3f12099ae"
let [<Literal>] AssemblyMetadata_GitHash = "237f46ee0d5505c9adc4e1615dd231b89cb1b992"
16 changes: 8 additions & 8 deletions src/Ubik/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ open System.Reflection

[<assembly: AssemblyTitleAttribute("Ubik")>]
[<assembly: AssemblyProductAttribute("NpgsqlFSharpAnalyzer")>]
[<assembly: AssemblyVersionAttribute("3.26.0")>]
[<assembly: AssemblyVersionAttribute("3.26.1")>]
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2021-05-06T00:00:00.0000000")>]
[<assembly: AssemblyFileVersionAttribute("3.26.0")>]
[<assembly: AssemblyInformationalVersionAttribute("3.26.0")>]
[<assembly: AssemblyFileVersionAttribute("3.26.1")>]
[<assembly: AssemblyInformationalVersionAttribute("3.26.1")>]
[<assembly: AssemblyMetadataAttribute("ReleaseChannel","release")>]
[<assembly: AssemblyMetadataAttribute("GitHash","89f1b78fc64964e3bc01f0738f8780c3f12099ae")>]
[<assembly: AssemblyMetadataAttribute("GitHash","237f46ee0d5505c9adc4e1615dd231b89cb1b992")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "Ubik"
let [<Literal>] AssemblyProduct = "NpgsqlFSharpAnalyzer"
let [<Literal>] AssemblyVersion = "3.26.0"
let [<Literal>] AssemblyVersion = "3.26.1"
let [<Literal>] AssemblyMetadata_ReleaseDate = "2021-05-06T00:00:00.0000000"
let [<Literal>] AssemblyFileVersion = "3.26.0"
let [<Literal>] AssemblyInformationalVersion = "3.26.0"
let [<Literal>] AssemblyFileVersion = "3.26.1"
let [<Literal>] AssemblyInformationalVersion = "3.26.1"
let [<Literal>] AssemblyMetadata_ReleaseChannel = "release"
let [<Literal>] AssemblyMetadata_GitHash = "89f1b78fc64964e3bc01f0738f8780c3f12099ae"
let [<Literal>] AssemblyMetadata_GitHash = "237f46ee0d5505c9adc4e1615dd231b89cb1b992"
16 changes: 8 additions & 8 deletions tests/NpgsqlFSharpAnalyzer.Tests/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ open System.Reflection

[<assembly: AssemblyTitleAttribute("NpgsqlFSharpAnalyzer.Tests")>]
[<assembly: AssemblyProductAttribute("NpgsqlFSharpAnalyzer")>]
[<assembly: AssemblyVersionAttribute("3.26.0")>]
[<assembly: AssemblyVersionAttribute("3.26.1")>]
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2021-05-06T00:00:00.0000000")>]
[<assembly: AssemblyFileVersionAttribute("3.26.0")>]
[<assembly: AssemblyInformationalVersionAttribute("3.26.0")>]
[<assembly: AssemblyFileVersionAttribute("3.26.1")>]
[<assembly: AssemblyInformationalVersionAttribute("3.26.1")>]
[<assembly: AssemblyMetadataAttribute("ReleaseChannel","release")>]
[<assembly: AssemblyMetadataAttribute("GitHash","89f1b78fc64964e3bc01f0738f8780c3f12099ae")>]
[<assembly: AssemblyMetadataAttribute("GitHash","237f46ee0d5505c9adc4e1615dd231b89cb1b992")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "NpgsqlFSharpAnalyzer.Tests"
let [<Literal>] AssemblyProduct = "NpgsqlFSharpAnalyzer"
let [<Literal>] AssemblyVersion = "3.26.0"
let [<Literal>] AssemblyVersion = "3.26.1"
let [<Literal>] AssemblyMetadata_ReleaseDate = "2021-05-06T00:00:00.0000000"
let [<Literal>] AssemblyFileVersion = "3.26.0"
let [<Literal>] AssemblyInformationalVersion = "3.26.0"
let [<Literal>] AssemblyFileVersion = "3.26.1"
let [<Literal>] AssemblyInformationalVersion = "3.26.1"
let [<Literal>] AssemblyMetadata_ReleaseChannel = "release"
let [<Literal>] AssemblyMetadata_GitHash = "89f1b78fc64964e3bc01f0738f8780c3f12099ae"
let [<Literal>] AssemblyMetadata_GitHash = "237f46ee0d5505c9adc4e1615dd231b89cb1b992"
44 changes: 44 additions & 0 deletions tests/NpgsqlFSharpAnalyzer.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,50 @@ let tests =
Expect.equal 2 parameters.Length "There are 2 parameters"
}

test "Semantic analysis: finding SQL blocks in multiple nested modules which query a non-public schema" {
use db = createTestDatabase()

Sql.connect db.ConnectionString
|> Sql.query "CREATE EXTENSION IF NOT EXISTS citext;CREATE SCHEMA test; CREATE TABLE test.articles (id BIGINT PRIMARY KEY NOT NULL,art_name CITEXT UNIQUE NOT NULL, stock BIGINT NOT NULL);"
|> Sql.executeNonQuery
|> raiseWhenFailed

match context (find "../examples/hashing/MultipleNestedModules.fs") with
| None -> failwith "Could not crack project"
| Some context ->
let operations = SyntacticAnalysis.findSqlOperations context
Expect.equal 1 operations.Length "There should be one syntactic block found"
match SqlAnalysis.databaseSchema db.ConnectionString with
| Result.Error connectionError ->
failwith connectionError
| Result.Ok schema ->
let errors = SqlAnalysis.analyzeOperation operations.[0] db.ConnectionString schema
Expect.equal 1 errors.Length "There should be one error message"
Expect.stringContains errors.[0].Message "column \"x\" does not exist" "There should be an error message"
}

test "Semantic analysis using FSX: finding SQL blocks in multiple nested modules which query a non-public schema" {
use db = createTestDatabase()

Sql.connect db.ConnectionString
|> Sql.query "CREATE EXTENSION IF NOT EXISTS citext;CREATE SCHEMA test; CREATE TABLE test.articles (id BIGINT PRIMARY KEY NOT NULL,art_name CITEXT UNIQUE NOT NULL, stock BIGINT NOT NULL);"
|> Sql.executeNonQuery
|> raiseWhenFailed

match context (find "../examples/hashing/MultipleNestedModules.fsx") with
| None -> failwith "Could not crack project"
| Some context ->
let operations = SyntacticAnalysis.findSqlOperations context
Expect.equal 1 operations.Length "There should be one syntactic block found"
match SqlAnalysis.databaseSchema db.ConnectionString with
| Result.Error connectionError ->
failwith connectionError
| Result.Ok schema ->
let errors = SqlAnalysis.analyzeOperation operations.[0] db.ConnectionString schema
Expect.equal 1 errors.Length "There should be one error message"
Expect.stringContains errors.[0].Message "column \"x\" does not exist" "There should be an error message"
}

test "Syntactic analysis: SQL block found from top-level expression in module" {
match context (find "../examples/hashing/topLevelExpressionIsDetected.fs") with
| None -> failwith "Could not crack project"
Expand Down
16 changes: 8 additions & 8 deletions tests/examples/hashing/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ open System.Reflection

[<assembly: AssemblyTitleAttribute("examples")>]
[<assembly: AssemblyProductAttribute("NpgsqlFSharpAnalyzer")>]
[<assembly: AssemblyVersionAttribute("3.26.0")>]
[<assembly: AssemblyVersionAttribute("3.26.1")>]
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2021-05-06T00:00:00.0000000")>]
[<assembly: AssemblyFileVersionAttribute("3.26.0")>]
[<assembly: AssemblyInformationalVersionAttribute("3.26.0")>]
[<assembly: AssemblyFileVersionAttribute("3.26.1")>]
[<assembly: AssemblyInformationalVersionAttribute("3.26.1")>]
[<assembly: AssemblyMetadataAttribute("ReleaseChannel","release")>]
[<assembly: AssemblyMetadataAttribute("GitHash","89f1b78fc64964e3bc01f0738f8780c3f12099ae")>]
[<assembly: AssemblyMetadataAttribute("GitHash","237f46ee0d5505c9adc4e1615dd231b89cb1b992")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "examples"
let [<Literal>] AssemblyProduct = "NpgsqlFSharpAnalyzer"
let [<Literal>] AssemblyVersion = "3.26.0"
let [<Literal>] AssemblyVersion = "3.26.1"
let [<Literal>] AssemblyMetadata_ReleaseDate = "2021-05-06T00:00:00.0000000"
let [<Literal>] AssemblyFileVersion = "3.26.0"
let [<Literal>] AssemblyInformationalVersion = "3.26.0"
let [<Literal>] AssemblyFileVersion = "3.26.1"
let [<Literal>] AssemblyInformationalVersion = "3.26.1"
let [<Literal>] AssemblyMetadata_ReleaseChannel = "release"
let [<Literal>] AssemblyMetadata_GitHash = "89f1b78fc64964e3bc01f0738f8780c3f12099ae"
let [<Literal>] AssemblyMetadata_GitHash = "237f46ee0d5505c9adc4e1615dd231b89cb1b992"
29 changes: 29 additions & 0 deletions tests/examples/hashing/MultipleNestedModules.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace App

module Domain =
type Article = {
Id : int ;
Name: string;
Stock: int
}

module Data =
open Domain
open Npgsql.FSharp

let getConnectionString () =
System.Environment.GetEnvironmentVariable "DATABASE_CONNECTION_STRING"

[<Literal>]
let getArticlesQuery = "SELECT x FROM test.articles"

let getArticles () =
getConnectionString()
|> Sql.connect
|> Sql.query getArticlesQuery
|> Sql.execute (fun read ->
{
Id = read.int "id"
Name = read.text "art_name"
Stock = read.int "stock"
})
26 changes: 26 additions & 0 deletions tests/examples/hashing/MultipleNestedModules.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#r "nuget:Npgsql.FSharp"

module Domain =
type Article = {
Id : int ;
Name: string;
Stock: int
}

module Data =
open Domain
open Npgsql.FSharp

let getConnectionString () =
System.Environment.GetEnvironmentVariable "DATABASE_CONNECTION_STRING"

let getArticles () =
getConnectionString()
|> Sql.connect
|> Sql.query "SELECT x FROM test.articles"
|> Sql.execute (fun read ->
{
Id = read.int "id"
Name = read.text "art_name"
Stock = read.int "stock"
})
Loading

0 comments on commit 1d1a3ea

Please sign in to comment.