fscheck / FsCheck

Random Testing for .NET
https://fscheck.github.io/FsCheck/
BSD 3-Clause "New" or "Revised" License
1.15k stars 154 forks source link

Incompatibility with F# 4.1 #365

Closed blumu closed 7 years ago

blumu commented 7 years ago

Building FSharpLu.Json with F#4.1 brakes some of our FsCheck-based unit tests with exception System.InvalidCastException:

Test method Microsoft.FSharpLu.Json.Tests+JsonSerializerTests.BackwardCompatible deserializes default Json.Net format and returns same object threw exception: 
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Exception: BackwardCompatibility.get_x1-Falsifiable, after 1 test (0 shrinks) (StdGen (1333139700,296279097)):
Original:
<null>
with exception:
System.InvalidCastException: Unable to cast object of type 'Arrow@202-1[Microsoft.FSharpLu.Json.Tests+ComplexDu,Microsoft.FSharp.Core.Unit]' to type 'Testable`1[Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharpLu.Json.Tests+ComplexDu,Microsoft.FSharp.Core.Unit]]'.
   at Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicFunctions.UnboxGeneric[T](Object source)
   at FsCheck.Testable.evaluate[a,b](FSharpFunc`2 body, a a) in C:\Users\Kurt\Projects\FsCheck\FsCheck\src\FsCheck\Testable.fs:line 151

See https://github.com/Microsoft/fsharplu/issues/14 for more details and repro steps.

This may be related to Issue #364. Feel free to merge the two issues if appropriate. I just thought it may be helpful to track this compatibility issue separately.

kurtschelfthout commented 7 years ago

You probably need to update the target version of FSharp.Core binding redirects in your test project's app.config to 4.4.1.0.

On 18 Mar 2017, at 23:07, William Blum notifications@github.com wrote:

Building FSharpLu.Json with F#4.1 brakes some of our FsCheck-based unit tests with exception System.InvalidCastException:

Test method Microsoft.FSharpLu.Json.Tests+JsonSerializerTests.BackwardCompatible deserializes default Json.Net format and returns same object threw exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Exception: BackwardCompatibility.get_x1-Falsifiable, after 1 test (0 shrinks) (StdGen (1333139700,296279097)): Original:

with exception: System.InvalidCastException: Unable to cast object of type 'Arrow@202-1[Microsoft.FSharpLu.Json.Tests+ComplexDu,Microsoft.FSharp.Core.Unit]' to type 'Testable`1[Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharpLu.Json.Tests+ComplexDu,Microsoft.FSharp.Core.Unit]]'. at Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicFunctions.UnboxGeneric[T](Object source) at FsCheck.Testable.evaluate[a,b](FSharpFunc`2 body, a a) in C:\Users\Kurt\Projects\FsCheck\FsCheck\src\FsCheck\Testable.fs:line 151 See Microsoft/fsharplu#14 for more details and repro steps. This may be related to Issue #364. Feel free to merge the two issues if appropriate. I just thought it may be helpful to track this compatibility issue separately. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
blumu commented 7 years ago

Thanks @kurtschelfthout Bumping up the version in app.config for the unit test project fixed 1 out of 4 failing unit tests. I'm still getting the following exception though. Is this unrelated to FsCheck maybe?

Message: Test method Microsoft.FSharpLu.Json.Tests+JsonSerializerTests.BackwardCompatible deserializes default Json.Net format and returns same object threw exception: 
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Exception: BackwardCompatibility.get_x13-Falsifiable, after 1 test (0 shrinks) (StdGen (2021048758,296279401)):
Original:
<null>
Leaf []
with exception:
Newtonsoft.Json.JsonSerializationException: Cannot create and populate list type Microsoft.FSharp.Collections.FSharpList`1[System.Int32]. Path '', line 4, position 5.
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewList(JsonReader reader, JsonArrayContract contract, Boolean& createdFromNonDefaultCreator)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.Serialization.JsonSerializerProxy.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType, JsonSerializer jsonSerializer)
   at Newtonsoft.Json.Converters.DiscriminatedUnionConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Microsoft.FSharpLu.Json.Default.deserialize[T](String json) in D:\sources\FSharpLu\FSharpLu.Json\NewtonSoft.fs:line 45
   at Microsoft.FSharpLu.Json.Tests.get_x13@147-5.Invoke(Tree`1 x) in D:\sources\FSharpLu\FSharpLu.Tests\JsonTests.fs:line 147
   at FsCheck.Testable.evaluate[a,b](FSharpFunc`2 body, a a) in C:\Users\Kurt\Projects\FsCheck\FsCheck\src\FsCheck\Testable.fs:line 161
blumu commented 7 years ago

It looks like the regression is in F# 4.1 rather than FsCheck so I will close this issue for now.