Exception when comparing generated map containing private DU
See original GitHub issueI ran into an exception when running following test:
Message: System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation. ---- System.ArgumentException : The type ‘SiteAgent.MessageGateway.Server.Tests.Foo+Bar’ is an F# union type but its representation is private. You must specify BindingFlags.NonPublic to access private type representations. Parameter name: unionType
open FsCheck
open FsCheck.Xunit
module Foo =
type Bar = private Bar of string
let create bar = Bar bar
module DataTests =
[<Property>]
let ``empty = generated nonEmpty`` (bars: Map<Foo.Bar, string>) =
not (bars.IsEmpty) ==> lazy
let emptyMap : Map<Foo.Bar, string> = Map.empty
emptyMap = bars
When the map is created inside the test it fails correctly without the exception:
[<Property>]
let ``empty = nonEmpty``() =
let bar = Foo.create "bar"
let nonEmptyMap = Map [ bar, "bar" ]
let emptyMap : Map<Foo.Bar, string> = Map.empty
emptyMap = nonEmptyMap
map [] = map [(Bar “bar”, “bar”)] false Expected: True Actual: False
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
How to compare the values of 2 Maps Java
The intersection of the key sets of the maps is the set to be iterated, and if the value from map 1 and...
Read more >Heterogeneous sorted containers should only be used with ...
With heterogeneous containers, the previous code will not create a string , but directly compare keys in the map with the searched char...
Read more >Tired of Null Pointer Exceptions? Consider Using Java SE ...
The variable computer is of type Optional<Computer> , so it is perfectly correct to call the map method. However, getSoundcard() returns an object...
Read more >@EqualsAndHashCode
Any class definition may be annotated with @EqualsAndHashCode to let lombok generate implementations of the equals(Object other) and hashCode() methods.
Read more >MapStruct 1.5.5.Final Reference Guide
Compared to writing mapping code from hand, MapStruct saves time by generating code which is tedious and error-prone to write.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Let’s say we’re considering whether to add it and if yes, how to add automatic generation/shrinking for private types. Imo we can add it but we should make it opt-in.
Meanwhile I’ll close this, as I don’t want to duplicate the discussion here. Feel free to add any thoughts to the other discussion, or re-open if there is anything unrelated that you still have a problem with.
If I understand the pull request you’ve mentioned correctly it actually adds the functionality to generate private DU. That is also what I am seeing when debugging the tests.
I realized that the exception does not occur during the generation but during shrinking for failed tests. This test is passing but when it fails, shrinking will not help me to find the failing values.