@@ -5,8 +5,6 @@ open Hedgehog.FSharp
55open Hedgehog.Xunit
66open System
77open System.Reflection
8- open System.Runtime .ExceptionServices
9- open System.Threading
108open System.Threading .Tasks
119
1210// ========================================
@@ -110,7 +108,6 @@ let rec wrapReturnValue (x: obj) : Property<unit> =
110108
111109 | _ -> Property.success ()
112110
113-
114111// ========================================
115112// Resource Management
116113// ========================================
@@ -120,33 +117,6 @@ let dispose (o: obj) =
120117 | :? IDisposable as d -> d.Dispose()
121118 | _ -> ()
122119
123- // ========================================
124- // Value Formatting & Display
125- // ========================================
126-
127- let printValue ( value : obj ) : string =
128- let prepareForPrinting ( value : obj ) : obj =
129- if isNull value then
130- value
131- else
132- let typeInfo = IntrospectionExtensions.GetTypeInfo( value.GetType())
133- let isResizeArray = typeInfo.IsGenericType && typeInfo.GetGenericTypeDefinition() = typedefof< ResizeArray<_>>
134- if isResizeArray then
135- value :?> System.Collections.IEnumerable
136- |> Seq.cast< obj>
137- |> List.ofSeq
138- :> obj
139- else
140- value
141-
142- value |> prepareForPrinting |> sprintf " %A "
143-
144- let formatParametersWithNames ( parameters : ParameterInfo []) ( values : obj list ) : string =
145- Array.zip parameters ( List.toArray values)
146- |> Array.map ( fun ( param , value ) ->
147- $" %s {param.Name} = %s {printValue value}" )
148- |> String.concat Environment.NewLine
149-
150120// ========================================
151121// Configuration Helpers
152122// ========================================
@@ -219,16 +189,8 @@ module private PropertyBuilder =
219189 else
220190 testMethod
221191
222- try
223- methodToInvoke.Invoke( testClassInstance, args |> Array.ofList)
224- with
225- | :? TargetInvocationException as tie when not ( isNull tie.InnerException) ->
226- // Unwrap reflection exception to show the actual user exception instead of TargetInvocationException.
227- // We use ExceptionDispatchInfo.Capture().Throw() to preserve the original stack trace.
228- // Note: This adds a "--- End of stack trace from previous location ---" marker
229- // and appends additional frames as the exception propagates, which we filter out later.
230- ExceptionDispatchInfo.Capture( tie.InnerException) .Throw()
231- failwith " unreachable"
192+ methodToInvoke.Invoke( testClassInstance, args |> Array.ofList)
193+
232194
233195 /// Creates a property based on the test method's return type
234196 let createProperty
@@ -243,23 +205,23 @@ module private PropertyBuilder =
243205 invokeTestMethod testMethod testClassInstance args
244206 finally
245207 List.iter dispose args
246- with e ->
247- // If the test method throws an exception, we need to handle it
248- // For Property<_> return types, the exception will be caught by Property.map
249- // For other return types, we need to wrap it in a failing property
250- // We return a special marker that wrapReturnValue will recognize
251- box e
208+ with
209+ // Unwrap TargetInvocationException to get the actual exception.
210+ // It is safe to do it because invokeTestMethod uses reflection that adds this wrapper.
211+ | :? TargetInvocationException as e when not ( isNull e.InnerException ) ->
212+ box e.InnerException
213+ | e -> box e
252214
253215 let createJournal args =
254- let formattedParams = formatParametersWithNames parameters args
255- Journal.singleton ( fun () -> formattedParams)
216+ args
217+ |> Seq.zip parameters
218+ |> Seq.map ( fun ( param , value ) -> fun () -> TestParameter ( param.Name, value))
219+ |> Array.ofSeq // not sure if journal will do multiple enumerations
220+ |> Journal.ofSeq
256221
257222 let wrapWithExceptionHandling ( result : obj ) : Property < unit > =
258223 match result with
259- | :? exn as e ->
260- // Exception was thrown - create a failing property
261- Property.counterexample ( fun () -> string e)
262- |> Property.bind ( fun () -> Property.failure)
224+ | :? exn as e -> Property.exn e
263225 | _ -> wrapReturnValue result
264226
265227
0 commit comments