Skip to content

Commit

Permalink
Merge pull request #57 from gedaiu/55-update-code-parsing
Browse files Browse the repository at this point in the history
move source result init in Result struct
  • Loading branch information
gedaiu authored Dec 2, 2017
2 parents 8f12176 + 47a071e commit fe12bff
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
19 changes: 11 additions & 8 deletions core/fluentasserts/core/base.d
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,22 @@ struct Result {
string file;
size_t line;

private string reason;

void because(string reason) {
message.prependText("Because " ~ reason ~ ", ");
this.reason = "Because " ~ reason ~ ", ";
}

void perform() {
if(!willThrow) {
return;
}

throw new TestException(cast(IResult) message ~ results, file, line);
auto sourceResult = new SourceResult(file, line);
message.prependValue(sourceResult.getValue);
message.prependText(reason);

throw new TestException(cast(IResult) message ~ results ~ sourceResult, file, line);
}

~this() {
Expand Down Expand Up @@ -179,12 +185,11 @@ mixin template ShouldCommons()
}

Result result(bool value, IResult res, string file, size_t line) {
return result(value, [], [ res ], file, line);
return result(value, [], [ res ], file, line);
}

Result result(bool value, Message[] msg, IResult[] res, const string file, const size_t line) {
auto sourceResult = new SourceResult(file, line);
auto finalMessage = new MessageResult(sourceResult.getValue ~ " should");
auto finalMessage = new MessageResult(" should");

messages ~= Message(false, ".");

Expand All @@ -200,9 +205,7 @@ mixin template ShouldCommons()
}
}

IResult[] results = res ~ cast(IResult) sourceResult;

return Result(expectedValue != value, results, finalMessage, file, line);
return Result(expectedValue != value, res, finalMessage, file, line);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/fluentasserts/core/callable.d
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ unittest
}

t.should.not.beNull;
t.msg.split("\n")[0].should.equal("({ throw new CustomException(\"test\"); }) should throw a `CustomException` with message equal `other`. `test` is not equal to `other`.");
t.msg.should.startWith("({\n throw new CustomException(\"test\");\n }) should throw a `CustomException` with message equal `other`. `test` is not equal to `other`.");
}

/// Should fail if an exception is not thrown
Expand Down Expand Up @@ -196,7 +196,7 @@ unittest
}

exception.should.not.beNull.because("we wait 20 milliseconds");
exception.msg.split("\n")[0].should.startWith("({ Thread.sleep(2.msecs); }) should have execution time less than `1 ms`.");
exception.msg.should.startWith("({\n Thread.sleep(2.msecs);\n }) should have execution time less than `1 ms`.");
}

/// It should check if a delagate is null
Expand Down
4 changes: 4 additions & 0 deletions core/fluentasserts/core/results.d
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ class MessageResult : IResult
this.messages = Message(false, text) ~ this.messages;
}

void prependValue(string text) {
this.messages = Message(true, text) ~ this.messages;
}

void print(ResultPrinter printer)
{
foreach(message; messages) {
Expand Down

0 comments on commit fe12bff

Please sign in to comment.