Browse Source

Test mode can expect exceptions, e.g. using:

// RESULT: Error
It can also check for the presence of one or more words appearing in the error message, e.g.:
// RESULT: Error:non-positive,divisor



git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@4639 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Dave Parker 14 years ago
parent
commit
1955392c65
  1. 18
      prism/src/parser/ast/Property.java
  2. 13
      prism/src/prism/PrismCL.java

18
prism/src/parser/ast/Property.java

@ -175,6 +175,7 @@ public class Property extends ASTElement
* (As required for {@link #checkAgainstExpectedResult(Object)} and {@link #checkAgainstExpectedResult(Object, String)}) * (As required for {@link #checkAgainstExpectedResult(Object)} and {@link #checkAgainstExpectedResult(Object, String)})
* @param strExpected Expected result * @param strExpected Expected result
* @param result The actual result * @param result The actual result
* @return Whether or not the check was performed
*/ */
private boolean checkAgainstExpectedResultString(String strExpected, Object result) throws PrismException private boolean checkAgainstExpectedResultString(String strExpected, Object result) throws PrismException
{ {
@ -183,6 +184,23 @@ public class Property extends ASTElement
return false; return false;
} }
// Check for exceptions
if (result instanceof Exception) {
String errMsg = ((Exception) result).getMessage();
if (strExpected.startsWith("Error")) {
if (strExpected.startsWith("Error:")) {
String words[] = strExpected.substring(6).split(",");
for (String word : words) {
if (!errMsg.contains(word)) {
throw new PrismException("Error message should contain \"" + word + "\"");
}
}
}
return true;
}
throw new PrismException("Unexpected error: " + errMsg);
}
// Check expected/actual result // Check expected/actual result
Type type = expr.getType(); Type type = expr.getType();

13
prism/src/prism/PrismCL.java

@ -293,7 +293,7 @@ public class PrismCL implements PrismModelListener
} }
} catch (PrismException e) { } catch (PrismException e) {
// in case of error, report it, store exception as the result and proceed // in case of error, report it, store exception as the result and proceed
error(e.getMessage());
error(e.getMessage(), true);
res = new Result(e); res = new Result(e);
} }
@ -1720,9 +1720,18 @@ public class PrismCL implements PrismModelListener
* Report a (non-fatal) error to the log. * Report a (non-fatal) error to the log.
*/ */
private void error(String s) private void error(String s)
{
error(s, false);
}
/**
* Report a (non-fatal) error to the log.
* Optionally, requested that we do not exit, even if test mode is enabled
*/
private void error(String s, boolean dontExit)
{ {
// If (and only if) we are in "test" (and not "testall") mode, treat any error as fatal // If (and only if) we are in "test" (and not "testall") mode, treat any error as fatal
if (test && testExitsOnFail) {
if (test && testExitsOnFail && !dontExit) {
errorAndExit(s); errorAndExit(s);
} }
// Normal case: just display error message, but don't exit // Normal case: just display error message, but don't exit

Loading…
Cancel
Save