fluentasserts.core.evaluation 21/21(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
540
550
560
570
580
590
600
610
620
630
640
650
660
670
680
690
70368
710
720
730
740
755447
760
770
780
795447
800
810
820
83107
84107
85107
860
870
880
895351
905351
915351
925351
930
9496
950
960
9774
980
990
10096
1010
1020
1030
1040
1050
1060
1071
1080
1090
1102
1110
1121
1131
1140
1150
1160
1170
1180
1191
1200
1210
1223
1230
1241
1251
1260
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; import fluentasserts.core.base : TestException; /// struct ValueEvaluation { /// The exception thrown during evaluation Throwable throwable; /// Time needed to evaluate the value Duration duration; /// Serialized value as string string strValue; /// Human readable value string niceValue; /// The name of the type before it was converted to string string typeName; /// Other info about the value string[string] meta; } /// class Evaluation { /// The id of the current evaluation size_t id; /// 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 nice message printed to the user MessageResult message; /// The source code where the assert is located SourceResult source; /// Results generated during evaluation IResult[] results; /// The throwable generated by the evaluation Throwable throwable; /// True when the evaluation is done bool isEvaluated; } /// 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; auto serializedValue = SerializerRegistry.instance.serialize(value); auto niceValue = SerializerRegistry.instance.niceValue(value); return Result(value, ValueEvaluation(null, duration, serializedValue, niceValue, unqualString!TT)); } catch(Throwable t) { T result; static if(isCallable!T) { result = testData; } return Result(result, ValueEvaluation(t, Clock.currTime - begin, result.to!string, 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"); }