fluentasserts.core.evaluation 19/19(100%) line coverage

      
10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
190
200
210
220
230
240
250
260
270
280
290
300
310
320
330
340
350
360
370
380
390
400
410
420
430
440
450
460
470
480
490
500
510
520
530
54368
550
560
570
580
595316
600
610
620
635316
640
650
660
67502
68500
69500
700
710
720
734834
744834
750
76482
770
780
79460
800
810
82482
830
840
850
860
870
880
891
900
910
922
930
941
951
960
970
980
990
1000
1011
1020
1030
1043
1050
1061
1071
1080
module fluentasserts.core.evaluation; import std.datetime; import std.typecons; import std.traits; import std.conv; import std.range; import std.array; import fluentasserts.core.serializers; import fluentasserts.core.results; /// struct ValueEvaluation { /// The exception thrown during evaluation Throwable throwable; /// Time needed to evaluate the value Duration duration; /// Serialized value as string string strValue; /// The name of the type before it was converted to string string typeName; /// Other info about the value string[string] meta; } /// struct Evaluation { /// The value that will be validated ValueEvaluation currentValue; /// The expected value that we will use to perform the comparison ValueEvaluation expectedValue; /// The operation name string operationName; /// True if the operation result needs to be negated to have a successful result bool isNegated; /// The name of the file where the assert was defined string fileName; /// The file line where the assert was defined size_t line; } /// auto evaluate(T)(lazy T testData) @trusted if(isInputRange!T && !isArray!T && !isAssociativeArray!T) { return evaluate(testData.array); } /// auto evaluate(T)(lazy T testData) @trusted if(!isInputRange!T || isArray!T || isAssociativeArray!T) { auto begin = Clock.currTime; alias Result = Tuple!(T, "value", ValueEvaluation, "evaluation"); try { auto value = testData; alias TT = typeof(value); static if(isCallable!T) { if(value !is null) { begin = Clock.currTime; value(); } } auto duration = Clock.currTime - begin; return Result(value, ValueEvaluation(null, duration, SerializerRegistry.instance.serialize(value), unqualString!TT)); } catch(Throwable t) { T result; static if(isCallable!T) { result = testData; } return Result(result, ValueEvaluation(t, Clock.currTime - begin, result.to!string, unqualString!T)); } } /// evaluate a lazy value should capture an exception unittest { int value() { throw new Exception("message"); } auto result = evaluate(value); assert(result.evaluation.throwable !is null); assert(result.evaluation.throwable.msg == "message"); } /// evaluate should capture an exception thrown by a callable unittest { void value() { throw new Exception("message"); } auto result = evaluate(&value); assert(result.evaluation.throwable !is null); assert(result.evaluation.throwable.msg == "message"); }