Minor improvements to error reporting in TestIndexFunctionFromSpreadsheet

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@891512 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2009-12-17 01:31:29 +00:00
parent 5d9b7a3ee4
commit 6e96d5be74

View File

@ -92,7 +92,7 @@ public final class TestIndexFunctionFromSpreadsheet extends TestCase {
case HSSFCell.CELL_TYPE_FORMULA: // will never be used, since we will call method after formula evaluation case HSSFCell.CELL_TYPE_FORMULA: // will never be used, since we will call method after formula evaluation
throw new AssertionFailedError("Cannot expect formula as result of formula evaluation: " + msg); throw new AssertionFailedError("Cannot expect formula as result of formula evaluation: " + msg);
case HSSFCell.CELL_TYPE_NUMERIC: case HSSFCell.CELL_TYPE_NUMERIC:
assertEquals(expected.getNumericCellValue(), actual.getNumberValue(), 0.0); assertEquals(msg, expected.getNumericCellValue(), actual.getNumberValue(), 0.0);
break; break;
case HSSFCell.CELL_TYPE_STRING: case HSSFCell.CELL_TYPE_STRING:
assertEquals(msg, expected.getRichStringCellValue().getString(), actual.getStringValue()); assertEquals(msg, expected.getRichStringCellValue().getString(), actual.getStringValue());
@ -181,11 +181,11 @@ public final class TestIndexFunctionFromSpreadsheet extends TestCase {
if (c == null || c.getCellType() != HSSFCell.CELL_TYPE_FORMULA) { if (c == null || c.getCellType() != HSSFCell.CELL_TYPE_FORMULA) {
continue; continue;
} }
CellValue actualValue = evaluator.evaluate(c);
HSSFCell expectedValueCell = r.getCell(SS.COLUMN_INDEX_EXPECTED_RESULT); HSSFCell expectedValueCell = r.getCell(SS.COLUMN_INDEX_EXPECTED_RESULT);
String msgPrefix = formatTestCaseDetails(sheetName, r.getRowNum(), c); String msgPrefix = formatTestCaseDetails(sheetName, r.getRowNum(), c);
try { try {
CellValue actualValue = evaluator.evaluate(c);
confirmExpectedResult(msgPrefix, expectedValueCell, actualValue); confirmExpectedResult(msgPrefix, expectedValueCell, actualValue);
_evaluationSuccessCount ++; _evaluationSuccessCount ++;
if(result != Result.SOME_EVALUATIONS_FAILED) { if(result != Result.SOME_EVALUATIONS_FAILED) {
@ -193,14 +193,13 @@ public final class TestIndexFunctionFromSpreadsheet extends TestCase {
} }
} catch (RuntimeException e) { } catch (RuntimeException e) {
_evaluationFailureCount ++; _evaluationFailureCount ++;
printShortStackTrace(System.err, e); printShortStackTrace(System.err, e, msgPrefix);
result = Result.SOME_EVALUATIONS_FAILED; result = Result.SOME_EVALUATIONS_FAILED;
} catch (AssertionFailedError e) { } catch (AssertionFailedError e) {
_evaluationFailureCount ++; _evaluationFailureCount ++;
printShortStackTrace(System.err, e); printShortStackTrace(System.err, e, msgPrefix);
result = Result.SOME_EVALUATIONS_FAILED; result = Result.SOME_EVALUATIONS_FAILED;
} }
} }
} }
@ -210,14 +209,15 @@ public final class TestIndexFunctionFromSpreadsheet extends TestCase {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
CellReference cr = new CellReference(sheetName, rowIndex, c.getColumnIndex(), false, false); CellReference cr = new CellReference(sheetName, rowIndex, c.getColumnIndex(), false, false);
sb.append(cr.formatAsString()); sb.append(cr.formatAsString());
sb.append(" {=").append(c.getCellFormula()).append("}"); sb.append(" [formula: ").append(c.getCellFormula()).append(" ]");
return sb.toString(); return sb.toString();
} }
/** /**
* Useful to keep output concise when expecting many failures to be reported by this test case * Useful to keep output concise when expecting many failures to be reported by this test case
*/ */
private static void printShortStackTrace(PrintStream ps, Throwable e) { private static void printShortStackTrace(PrintStream ps, Throwable e, String msgPrefix) {
System.err.println("Problem with " + msgPrefix);
StackTraceElement[] stes = e.getStackTrace(); StackTraceElement[] stes = e.getStackTrace();
int startIx = 0; int startIx = 0;