Skip to content

Commit

Permalink
Removed Fatal and NonFatal exception (#1976)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldietrich authored May 6, 2017
1 parent dfa1959 commit 425c5be
Show file tree
Hide file tree
Showing 14 changed files with 297 additions and 338 deletions.
56 changes: 34 additions & 22 deletions vavr-test/generator/Generator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,37 +93,37 @@ def generateMainClasses(): Unit = {
}

/**
* Creates an Error caused by an exception when obtaining a generator.
* Creates a CheckError caused by an exception when obtaining a generator.
*
* @param position The position of the argument within the argument list of the property, starting with 1.
* @param size The size hint passed to the {@linkplain Arbitrary} which caused the error.
* @param cause The error which occurred when the {@linkplain Arbitrary} tried to obtain the generator {@linkplain Gen}.
* @return a new Error instance.
* @return a new CheckError instance.
*/
private static Error arbitraryError(int position, int size, Throwable cause) {
return new Error(String.format("Arbitrary %s of size %s: %s", position, size, cause.getMessage()), cause);
private static CheckError arbitraryError(int position, int size, Throwable cause) {
return new CheckError(String.format("Arbitrary %s of size %s: %s", position, size, cause.getMessage()), cause);
}

/**
* Creates an Error caused by an exception when generating a value.
* Creates a CheckError caused by an exception when generating a value.
*
* @param position The position of the argument within the argument list of the property, starting with 1.
* @param size The size hint of the arbitrary which called the generator {@linkplain Gen} which caused the error.
* @param cause The error which occurred when the {@linkplain Gen} tried to generate a random value.
* @return a new Error instance.
* @return a new CheckError instance.
*/
private static Error genError(int position, int size, Throwable cause) {
return new Error(String.format("Gen %s of size %s: %s", position, size, cause.getMessage()), cause);
private static CheckError genError(int position, int size, Throwable cause) {
return new CheckError(String.format("Gen %s of size %s: %s", position, size, cause.getMessage()), cause);
}

/**
* Creates an Error caused by an exception when testing a Predicate.
* Creates a CheckError caused by an exception when testing a Predicate.
*
* @param cause The error which occurred when applying the {@linkplain java.util.function.Predicate}.
* @return a new Error instance.
* @return a new CheckError instance.
*/
private static Error predicateError(Throwable cause) {
return new Error("Applying predicate: " + cause.getMessage(), cause);
private static CheckError predicateError(Throwable cause) {
return new CheckError("Applying predicate: " + cause.getMessage(), cause);
}

${(1 to N).gen(i => {
Expand Down Expand Up @@ -189,7 +189,7 @@ def generateMainClasses(): Unit = {
val optionType = im.getType("io.vavr.control.Option")
val randomType = im.getType("java.util.Random")
val tryType = im.getType("io.vavr.control.Try")
val nonFatalType = "Try.NonFatalException"
val checkException = "CheckException"
val tupleType = im.getType(s"io.vavr.Tuple")

val generics = (1 to i).gen(j => s"T$j")(", ")
Expand Down Expand Up @@ -262,20 +262,20 @@ def generateMainClasses(): Unit = {
return new CheckResult.Falsified(name, i, $tupleType.of(${(1 to i).gen(j => s"val$j")(", ")}));
}
}
} catch($nonFatalType nonFatal) {
logErroneous(name, i, System.currentTimeMillis() - startTime, nonFatal.getCause().getMessage());
return new CheckResult.Erroneous(name, i, (Error) nonFatal.getCause(), $optionType.some($tupleType.of(${(1 to i).gen(j => s"val$j")(", ")})));
} catch(CheckError err) {
logErroneous(name, i, System.currentTimeMillis() - startTime, err.getMessage());
return new CheckResult.Erroneous(name, i, err, $optionType.some($tupleType.of(${(1 to i).gen(j => s"val$j")(", ")})));
}
} catch($nonFatalType nonFatal) {
logErroneous(name, i, System.currentTimeMillis() - startTime, nonFatal.getCause().getMessage());
return new CheckResult.Erroneous(name, i, (Error) nonFatal.getCause(), $optionType.none());
} catch(CheckError err) {
logErroneous(name, i, System.currentTimeMillis() - startTime, err.getMessage());
return new CheckResult.Erroneous(name, i, err, $optionType.none());
}
}
logSatisfied(name, tries, System.currentTimeMillis() - startTime, exhausted);
return new CheckResult.Satisfied(name, tries, exhausted);
} catch($nonFatalType nonFatal) {
logErroneous(name, 0, System.currentTimeMillis() - startTime, nonFatal.getCause().getMessage());
return new CheckResult.Erroneous(name, 0, (Error) nonFatal.getCause(), $optionType.none());
} catch(CheckError err) {
logErroneous(name, 0, System.currentTimeMillis() - startTime, err.getMessage());
return new CheckResult.Erroneous(name, 0, err, $optionType.none());
}
}
}
Expand All @@ -302,6 +302,18 @@ def generateMainClasses(): Unit = {
return precondition && !postcondition;
}
}

/**
* Internally used to provide more specific error messages.
*/
static class CheckError extends Error {

private static final long serialVersionUID = 1L;

CheckError(String message, Throwable cause) {
super(message, cause);
}
}
}
"""
}
Expand Down
Loading

0 comments on commit 425c5be

Please sign in to comment.