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

Use System.Text.Json instead of Newtonsoft.Json in Fake.Core.IntegrationTests #2844

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ group fakerunner
nuget Microsoft.TestPlatform.TestHost
nuget FsCheck
nuget FParsec
nuget Newtonsoft.Json

group fakemodule
source https://api.nuget.org/v3/index.json
Expand Down Expand Up @@ -68,4 +67,4 @@ group fakemodule
nuget BlackFox.VsWhere
nuget System.Runtime.Loader
nuget System.Collections.Immutable
nuget System.Data.SqlClient
nuget System.Data.SqlClient
12 changes: 6 additions & 6 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ NUGET
System.Runtime.Extensions (>= 4.3) - restriction: || (&& (== net472) (< net45)) (== net6.0) (== netcoreapp2.1) (== netstandard2.0)
System.Memory (4.5.5)
System.Buffers (>= 4.5.1) - restriction: || (== net472) (&& (== net6.0) (>= monotouch)) (&& (== net6.0) (>= net461)) (&& (== net6.0) (< netcoreapp2.0)) (&& (== net6.0) (< netstandard1.1)) (&& (== net6.0) (< netstandard2.0)) (&& (== net6.0) (>= xamarinios)) (&& (== net6.0) (>= xamarinmac)) (&& (== net6.0) (>= xamarintvos)) (&& (== net6.0) (>= xamarinwatchos)) (&& (== netcoreapp2.1) (>= monotouch)) (&& (== netcoreapp2.1) (>= net461)) (&& (== netcoreapp2.1) (< netcoreapp2.0)) (&& (== netcoreapp2.1) (< netstandard1.1)) (&& (== netcoreapp2.1) (< netstandard2.0)) (&& (== netcoreapp2.1) (>= xamarinios)) (&& (== netcoreapp2.1) (>= xamarinmac)) (&& (== netcoreapp2.1) (>= xamarintvos)) (&& (== netcoreapp2.1) (>= xamarinwatchos)) (== netstandard2.0)
System.Numerics.Vectors (>= 4.4) - restriction: || (&& (== net472) (< net45)) (&& (== net6.0) (< netcoreapp2.0)) (&& (== netcoreapp2.1) (< netcoreapp2.0)) (== netstandard2.0)
System.Numerics.Vectors (>= 4.4) - restriction: || (&& (== net472) (== net6.0)) (&& (== net472) (== netcoreapp2.1)) (&& (== net472) (< net45)) (&& (== net6.0) (< netcoreapp2.0)) (&& (== netcoreapp2.1) (< netcoreapp2.0)) (== netstandard2.0)
System.Numerics.Vectors (>= 4.5) - restriction: || (== net472) (&& (== net6.0) (>= net461)) (&& (== netcoreapp2.1) (>= net461)) (&& (== netstandard2.0) (>= net461))
System.Runtime.CompilerServices.Unsafe (>= 4.5.3) - restriction: || (== net472) (&& (== net6.0) (>= monotouch)) (&& (== net6.0) (>= net461)) (&& (== net6.0) (< netcoreapp2.0)) (&& (== net6.0) (< netcoreapp2.1)) (&& (== net6.0) (< netstandard1.1)) (&& (== net6.0) (< netstandard2.0)) (&& (== net6.0) (>= uap10.1)) (&& (== net6.0) (>= xamarinios)) (&& (== net6.0) (>= xamarinmac)) (&& (== net6.0) (>= xamarintvos)) (&& (== net6.0) (>= xamarinwatchos)) (&& (== netcoreapp2.1) (>= monotouch)) (&& (== netcoreapp2.1) (>= net461)) (&& (== netcoreapp2.1) (< netcoreapp2.0)) (&& (== netcoreapp2.1) (< netstandard1.1)) (&& (== netcoreapp2.1) (< netstandard2.0)) (&& (== netcoreapp2.1) (>= uap10.1)) (&& (== netcoreapp2.1) (>= xamarinios)) (&& (== netcoreapp2.1) (>= xamarinmac)) (&& (== netcoreapp2.1) (>= xamarintvos)) (&& (== netcoreapp2.1) (>= xamarinwatchos)) (== netstandard2.0)
System.Net.Http (4.3.4) - restriction: || (&& (== net472) (< net461)) (== net6.0) (== netcoreapp2.1) (== netstandard2.0)
Expand Down Expand Up @@ -1092,7 +1092,7 @@ NUGET
System.Reflection.Primitives (>= 4.3) - restriction: || (&& (== net472) (< net45)) (== net6.0) (== netcoreapp2.1) (== netstandard2.0)
System.Runtime (>= 4.3) - restriction: || (&& (== net472) (< net45)) (== net6.0) (== netcoreapp2.1) (== netstandard2.0)
System.Reflection.Emit (4.7)
System.Reflection.Emit.ILGeneration (>= 4.7) - restriction: || (&& (== net472) (< net45)) (&& (== net472) (< netstandard1.1)) (&& (== net472) (< netstandard2.0) (>= wpa81)) (&& (== net472) (>= uap10.1)) (&& (== net6.0) (< netcoreapp2.0) (< netstandard2.1)) (&& (== net6.0) (< netstandard1.1)) (&& (== net6.0) (< netstandard2.0)) (&& (== net6.0) (>= uap10.1)) (&& (== netcoreapp2.1) (< netcoreapp2.0)) (&& (== netcoreapp2.1) (< netstandard1.1)) (&& (== netcoreapp2.1) (< netstandard2.0)) (&& (== netcoreapp2.1) (>= uap10.1)) (== netstandard2.0)
System.Reflection.Emit.ILGeneration (>= 4.7) - restriction: || (&& (== net472) (== net6.0)) (&& (== net472) (== netcoreapp2.1)) (&& (== net472) (< net45)) (&& (== net472) (< netstandard1.1)) (&& (== net472) (< netstandard2.0) (>= wpa81)) (&& (== net472) (>= uap10.1)) (&& (== net6.0) (< netcoreapp2.0) (< netstandard2.1)) (&& (== net6.0) (< netstandard1.1)) (&& (== net6.0) (< netstandard2.0)) (&& (== net6.0) (>= uap10.1)) (&& (== netcoreapp2.1) (< netcoreapp2.0)) (&& (== netcoreapp2.1) (< netstandard1.1)) (&& (== netcoreapp2.1) (< netstandard2.0)) (&& (== netcoreapp2.1) (>= uap10.1)) (== netstandard2.0)
System.Reflection.Emit.ILGeneration (4.7) - restriction: || (&& (== net472) (== net6.0)) (&& (== net472) (== netcoreapp2.1)) (&& (== net472) (< net45)) (&& (== net472) (< netstandard1.1)) (&& (== net472) (< netstandard2.0) (>= wpa81)) (&& (== net472) (>= uap10.1)) (&& (== net6.0) (< netcoreapp2.0) (< netstandard2.1)) (&& (== net6.0) (< netstandard1.1)) (&& (== net6.0) (< netstandard2.0)) (&& (== net6.0) (>= uap10.1)) (&& (== netcoreapp2.1) (< netcoreapp2.0)) (&& (== netcoreapp2.1) (< netstandard1.1)) (&& (== netcoreapp2.1) (< netstandard2.0)) (&& (== netcoreapp2.1) (>= uap10.1)) (== netstandard2.0)
System.Reflection.Metadata (8.0)
System.Collections.Immutable (>= 8.0)
Expand Down Expand Up @@ -1178,10 +1178,10 @@ NUGET
System.Security.Cryptography.OpenSsl (5.0) - restriction: || (&& (== net472) (< net45)) (== net6.0) (== netcoreapp2.1) (== netstandard2.0)
System.Formats.Asn1 (>= 5.0) - restriction: || (&& (== net472) (>= netcoreapp3.0)) (== net6.0) (&& (== netcoreapp2.1) (>= netcoreapp3.0)) (&& (== netstandard2.0) (>= netcoreapp3.0))
System.Security.Cryptography.Pkcs (7.0.3) - restriction: || (&& (== net472) (>= net5.0)) (== net6.0) (== netcoreapp2.1) (== netstandard2.0)
System.Buffers (>= 4.5.1) - restriction: || (&& (== net472) (< net462)) (&& (== net6.0) (< netstandard2.1)) (== netcoreapp2.1) (== netstandard2.0)
System.Buffers (>= 4.5.1) - restriction: || (&& (== net472) (== net6.0)) (&& (== net472) (< net462)) (&& (== net6.0) (< netstandard2.1)) (== netcoreapp2.1) (== netstandard2.0)
System.Formats.Asn1 (>= 7.0) - restriction: || (&& (== net472) (< net462)) (&& (== net472) (>= netstandard2.1)) (== net6.0) (== netcoreapp2.1) (== netstandard2.0)
System.Memory (>= 4.5.5) - restriction: || (&& (== net472) (< net462)) (&& (== net6.0) (< netstandard2.1)) (== netcoreapp2.1) (== netstandard2.0)
System.Security.Cryptography.Cng (>= 5.0) - restriction: || (&& (== net472) (< net462)) (&& (== net472) (>= netstandard2.1)) (&& (== net6.0) (< netstandard2.1)) (== netcoreapp2.1) (== netstandard2.0)
System.Memory (>= 4.5.5) - restriction: || (&& (== net472) (== net6.0)) (&& (== net472) (< net462)) (&& (== net6.0) (< netstandard2.1)) (== netcoreapp2.1) (== netstandard2.0)
System.Security.Cryptography.Cng (>= 5.0) - restriction: || (&& (== net472) (== net6.0)) (&& (== net472) (< net462)) (&& (== net472) (>= netstandard2.1)) (&& (== net6.0) (< netstandard2.1)) (== netcoreapp2.1) (== netstandard2.0)
System.Security.Cryptography.Primitives (4.3) - restriction: || (&& (== net472) (< net45)) (== net6.0) (== netcoreapp2.1) (== netstandard2.0)
System.Diagnostics.Debug (>= 4.3) - restriction: || (&& (== net472) (< net46)) (== net6.0) (== netcoreapp2.1) (== netstandard2.0)
System.Globalization (>= 4.3) - restriction: || (&& (== net472) (< net46)) (== net6.0) (== netcoreapp2.1) (== netstandard2.0)
Expand All @@ -1191,7 +1191,7 @@ NUGET
System.Threading (>= 4.3) - restriction: || (&& (== net472) (< net46)) (== net6.0) (== netcoreapp2.1) (== netstandard2.0)
System.Threading.Tasks (>= 4.3) - restriction: || (&& (== net472) (< net46)) (== net6.0) (== netcoreapp2.1) (== netstandard2.0)
System.Security.Cryptography.ProtectedData (6.0)
System.Memory (>= 4.5.4) - restriction: || (&& (== net472) (< net461)) (== netcoreapp2.1) (== netstandard2.0)
System.Memory (>= 4.5.4) - restriction: || (&& (== net472) (== net6.0)) (&& (== net472) (< net461)) (== netcoreapp2.1) (== netstandard2.0)
System.Security.Cryptography.X509Certificates (4.3.2) - restriction: || (&& (== net472) (< net45)) (&& (== net472) (< net461)) (== net6.0) (== netcoreapp2.1) (== netstandard2.0)
Microsoft.NETCore.Platforms (>= 1.1) - restriction: || (&& (== net472) (< net46)) (== net6.0) (== netcoreapp2.1) (== netstandard2.0)
runtime.native.System (>= 4.3) - restriction: || (&& (== net472) (< net46)) (== net6.0) (== netcoreapp2.1) (== netstandard2.0)
Expand Down
53 changes: 28 additions & 25 deletions src/test/Fake.Core.IntegrationTests/SimpleHelloWorldTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ open Expecto
open Expecto.Flip
open System
open System.IO
open Newtonsoft.Json.Linq
open System.Text.Json
open Fake.Core

let fail s = Expect.isTrue s false
Expand Down Expand Up @@ -216,30 +216,33 @@ let tests =
|> ignProc

let json = File.ReadAllText tempFile
let obj = JObject.Parse json
let targets = obj["targets"] :?> JArray

let parseDecl (t: JToken) =
{ File = string t["file"]
Line = int t["line"]
Column = int t["column"]
ErrorDetail = string t["errorDetail"] }

let parseDep (t: JToken) =
{ Name = string t["name"]
Declaration = parseDecl t["declaration"] }

let parseArray parseItem (a: JToken) =
(a :?> JArray) |> Seq.map parseItem |> Seq.toList

let parseTarget (t: JToken) =
{ Name = string t["name"]
Declaration = parseDecl t["declaration"]
HardDependencies = parseArray parseDep t["hardDependencies"]
SoftDependencies = parseArray parseDep t["softDependencies"]
Description = string t["description"] }

let dict = targets |> Seq.map (fun t -> let t = parseTarget t in t.Name, t) |> dict
let obj = JsonDocument.Parse(json)
let targets = obj.RootElement.GetProperty("targets")

let parseDecl (t: JsonElement) =
{ File = string (t.GetProperty("file"))
Line = t.GetProperty("line").GetInt32()
Column = t.GetProperty("column").GetInt32()
ErrorDetail = string (t.GetProperty("errorDetail")) }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: uses string instead of .GetString() because GetString() can return null and the tests expect missing string properties to be an empty string rather than null


let parseDep (t: JsonElement) =
{ Name = string (t.GetProperty("name"))
Declaration = parseDecl (t.GetProperty("declaration")) }

let parseArray parseItem (a: JsonElement) =
a.EnumerateArray() |> Seq.map parseItem |> Seq.toList

let parseTarget (t: JsonElement) =
{ Name = string (t.GetProperty("name"))
Declaration = parseDecl (t.GetProperty("declaration"))
HardDependencies = parseArray parseDep (t.GetProperty("hardDependencies"))
SoftDependencies = parseArray parseDep (t.GetProperty("softDependencies"))
Description = string (t.GetProperty("description")) }

let dict =
targets.EnumerateArray()
|> Seq.map (fun t -> let t = parseTarget t in t.Name, t)
|> dict

Expect.equal "Expected correct number of targets" 4 dict.Count

Expand Down
4 changes: 1 addition & 3 deletions src/test/Fake.Core.IntegrationTests/paket.references
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
group fakerunner

YoloDev.Expecto.TestSdk
Microsoft.TestPlatform.TestHost
FSharp.Core
NETStandard.Library
Expecto
FParsec
Newtonsoft.Json
FParsec
Loading