Skip to content

Commit

Permalink
modified the test so that it can print out some meaningful message wh…
Browse files Browse the repository at this point in the history
…en the result does not match the predicate
  • Loading branch information
verhas committed Oct 29, 2024
1 parent 2bfea5d commit 46ecf61
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions jamal-git/src/test/java/javax0/jamal/git/TestCommit.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ public void latestCommit() throws Exception {
final var result = new String[]{"[0-9a-f]{40}", "Peter Verhas", "\\d+", "\\d+", "Rev: chicken was added", "Rev: chicken was added", "[0-9a-f]{7}", "Peter Verhas", "[0-9a-f]{40}", "[0-9a-f]{40}",};
for (int i = 0; i < what.length; i++) {
final int j = i;
TestThat.theInput("{@git location=\"" + repoDir.getAbsolutePath() + "\"}{@git:commit branch=main last " + what[j] + "}")
.results(s -> s.matches(result[j]));
final var theInput = "{@git location=\"" + repoDir.getAbsolutePath() + "\"}{@git:commit branch=main last " + what[j] + "}";
TestThat.theInput(theInput)
.results(s -> s.matches(result[j]), r-> String.format("For the %s expected: %s, got: %s", theInput,result[j], r));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -208,6 +209,16 @@ public void results(Predicate<String> test) throws
Assertions.assertTrue(test.test(result), "The result '" + result + "' does not match the predicate");
}

public void results(Predicate<String> test, final Function<String,String> message) throws
NoSuchMethodException,
IllegalAccessException,
InstantiationException,
InvocationTargetException,
BadSyntax {
final var result = resultsClose();
Assertions.assertTrue(test.test(result), message.apply(result));
}

/**
* Create a new macro, a new processor and test that the input creates the expected output. If they are not the same
* then JUnit5 assertion failure will happen.
Expand Down

0 comments on commit 46ecf61

Please sign in to comment.