Skip to content

Commit

Permalink
Do not escape exception messages in variable substitution.
Browse files Browse the repository at this point in the history
Moved TableTable.isExceptionFailureMessage() up to ScriptTable, so it can be used by Expectations.
  • Loading branch information
amolenaar committed Nov 1, 2012
1 parent c646d74 commit 9414a8f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 12 additions & 2 deletions src/fitnesse/slimTables/SlimTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ protected boolean isExceptionMessage(String value) {
return value != null && (value.startsWith(SlimTestSystem.MESSAGE_FAIL) || value.startsWith(SlimTestSystem.MESSAGE_ERROR));
}

protected boolean isExceptionFailureMessage(String value) {
return value.startsWith("Exception: ");
}

public boolean shouldIgnoreException(String resultKey, String resultString) {
return false;
}
Expand Down Expand Up @@ -626,7 +630,11 @@ class SymbolAssignmentExpectation extends Expectation {

protected String createEvaluationMessage(String actual, String expected) {
setSymbol(symbolName, actual);
return String.format("$%s<-[%s]", symbolName, Utils.escapeHTML(actual));
if (isExceptionFailureMessage(actual)) {
return String.format("$%s<-[%s]", symbolName, actual);
} else {
return String.format("$%s<-[%s]", symbolName, Utils.escapeHTML(actual));
}
}
}

Expand Down Expand Up @@ -655,7 +663,7 @@ else if (replacedExpected.length() == 0)
String expressionMessage = new Comparator(this, replacedExpected, actual, expected).evaluate();
if (expressionMessage != null)
evaluationMessage = expressionMessage;
else if (actual.contains("Exception:")) {
else if (isExceptionFailureMessage(actual)) {
evaluationMessage = error(actual);
} else
evaluationMessage = failMessage(actual,
Expand Down Expand Up @@ -870,4 +878,6 @@ private String matchSimpleComparison() {
return null;
}
}


}
6 changes: 1 addition & 5 deletions src/fitnesse/slimTables/TableTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Released under the terms of the CPL Common Public License version 1.0.
package fitnesse.slimTables;

import static fitnesse.responders.run.slimResponder.SlimTestSystem.*;
import static fitnesse.responders.run.slimResponder.SlimTestSystem.MESSAGE_ERROR;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -46,10 +46,6 @@ public void evaluateReturnValues(Map<String, Object> returnValues) throws Except
resizeTableAndEvaluateRows(returnValues);
}

private boolean isExceptionFailureMessage(String value) {
return value.startsWith("Exception: ");
}

private boolean isTestCaseErrorMessage(String value) {
return value.startsWith(MESSAGE_ERROR);
}
Expand Down

1 comment on commit 9414a8f

@stanio
Copy link
Contributor

@stanio stanio commented on 9414a8f Nov 3, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems the same test should be performed for formatSymbolValue (changed in 58b7000, also) as the variable may already have been assigned an "exception" value.

Try the following table:

|script|test script   |
|$VAR= |calculate|abc |
|$RES= |echo     |$VAR|

With the fixture code:

public class TestScript {

    public Object echo(Object value) {
        return value;
    }

    public Integer calculate(Integer value) {
        return value;
    }

}

The result is:

script test script
$VAR<-[Exception: scriptTable_0_1] calculate abc
$RES<-[$VAR] echo $VAR->[Exception: <a href=#scriptTable_0_1>scriptTable_0_1</a>]

I guess the following is the needed change:

diff --git a/src/fitnesse/slimTables/SlimTable.java b/src/fitnesse/slimTables/SlimTable.java
--- a/src/fitnesse/slimTables/SlimTable.java
+++ b/src/fitnesse/slimTables/SlimTable.java
@@ -570,16 +570,19 @@ public abstract class SlimTable {
   }

   class FullExpansionSymbolReplacer extends SymbolReplacer {
     FullExpansionSymbolReplacer(String s) {
       super(s);
     }

     protected String formatSymbolValue(String name, String value) {
+      if (isExceptionFailureMessage(value)) {
+        return String.format("$%s->[%s]", name, value);
+      }
       return String.format("$%s->[%s]", name, Utils.escapeHTML(value));
     }
   }

   public static class SyntaxError extends Error {
     private static final long serialVersionUID = 1L;

     public SyntaxError(String message) {

Please sign in to comment.