Skip to content

Commit bc4b669

Browse files
committed
bubbling non-koanincompleteexceptions to the console
1 parent 6fb4c30 commit bc4b669

6 files changed

Lines changed: 33 additions & 18 deletions

File tree

‎koans-lib/src/com/sandwich/koan/cmdline/behavior/Test.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ public class Test extends AbstractArgumentBehavior{
88

99
public void run(String value) throws IOException {
1010
FileCompiler.compileRelative("koans-tests", "test", "bin");
11-
1211
}
1312

1413
}

‎koans-lib/src/com/sandwich/koan/constant/ArgumentType.java‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,16 @@ public void run(String value) {
7474
behavior.run(value);
7575
behavior.getSuccessMessage();
7676
}catch(Throwable t){
77-
Logger.getAnonymousLogger().severe(t.getLocalizedMessage());
78-
System.out.println(behavior.getErrorMessage());
77+
if(behavior instanceof RunKoans){
78+
if(t instanceof RuntimeException){
79+
throw (RuntimeException)t;
80+
}else{
81+
throw new RuntimeException(t);
82+
}
83+
}else{
84+
Logger.getAnonymousLogger().severe(t.getLocalizedMessage());
85+
System.out.println(behavior.getErrorMessage());
86+
}
7987
}
8088
}
8189
public String getErrorMessage() {

‎koans-lib/src/com/sandwich/koan/runner/RunKoans.java‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ KoanSuiteResult runKoans() throws IllegalArgumentException,
9595
String message = failure != null
9696
&& KoanIncompleteException.class.isAssignableFrom(failure.getClass()) ?
9797
failure.getMessage() : formatNormalException(failure);
98-
if (message != null && message.contains(EXPECTED_LEFT + __ + EXPECTED_RIGHT)) {
98+
if (failure instanceof KoanIncompleteException && message.contains(EXPECTED_LEFT + __ + EXPECTED_RIGHT)) {
9999
logExpectationOnWrongSideWarning(firstFailingSuite,
100100
firstFailingMethod.getMethod());
101101
}
@@ -109,7 +109,7 @@ KoanSuiteResult runKoans() throws IllegalArgumentException,
109109
}
110110

111111
private String formatNormalException(Throwable failure) {
112-
return failure == null ? "" : failure.getMessage();
112+
return failure == null ? "" : fillStackTrace(failure).toString();
113113
}
114114

115115
/**
@@ -121,23 +121,30 @@ private String formatNormalException(Throwable failure) {
121121
* @return
122122
*/
123123
static String getOriginalLineNumber(Throwable t, Class<?> failingSuite){
124-
StringWriter stringWriter = new StringWriter();
125-
if(t == null){
126-
return null;
127-
}
128-
t.printStackTrace(new PrintWriter(stringWriter));
124+
StringWriter stringWriter = fillStackTrace(t);
129125
String[] lines = stringWriter.toString().split(EOLS);
130-
for(int i = lines.length - 1; i >= 0; --i){
131-
String line = lines[i];
132-
if(line.contains(failingSuite.getName())){
133-
return line.substring(
134-
line.indexOf(KoanConstants.LINE_NO_START)+KoanConstants.LINE_NO_START.length(),
135-
line.lastIndexOf(KoanConstants.LINE_NO_END));
126+
if(failingSuite != null){
127+
for(int i = lines.length - 1; i >= 0; --i){
128+
String line = lines[i];
129+
if(line.contains(failingSuite.getName())){
130+
return line.substring(
131+
line.indexOf(KoanConstants.LINE_NO_START)+KoanConstants.LINE_NO_START.length(),
132+
line.lastIndexOf(KoanConstants.LINE_NO_END));
133+
}
136134
}
137135
}
138136
return null;
139137
}
140138

139+
private static StringWriter fillStackTrace(Throwable t) {
140+
StringWriter stringWriter = new StringWriter();
141+
if(t == null){
142+
return stringWriter;
143+
}
144+
t.printStackTrace(new PrintWriter(stringWriter));
145+
return stringWriter;
146+
}
147+
141148
private Path getPathToEnlightement() {
142149
if(pathToEnlightenment == null){
143150
pathToEnlightenment = PathToEnlightenment.getPathToEnlightment();

‎koans/lib/koans.jar‎

108 Bytes
Binary file not shown.

‎koans/src/PathToEnlightment.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
<koan name="innerClassesInMethods" />
172172
<koan name="innerClassesInMethodsThatEscape" />
173173
<koan name="creatingAnonymousInnerClasses" />
174-
<koan name="creatingAnonymousInnerClassesToImplementIntercae" />
174+
<koan name="creatingAnonymousInnerClassesToImplementInterface" />
175175
<koan name="innerClassAndIneritance" />
176176
<koan name="innerClassAndIneritanceOther" />
177177
<koan name="staticInnerClass" />

‎koans/src/intermediate/AboutInnerClasses.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ public void creatingAnonymousInnerClasses() {
7676
assertEquals(anonymous.theAnswer(), __);
7777
}
7878

79+
@SuppressWarnings("null")
7980
@Koan
80-
public void creatingAnonymousInnerClassesToImplementIntercae() {
81+
public void creatingAnonymousInnerClassesToImplementInterface() {
8182
Ignorable ignorable = null; // Complete the code so that the statement below is correct.
8283
// Look at the koan above for inspiration
8384
assertEquals(ignorable.ignoreAll(), "SomeInterestingString");

0 commit comments

Comments
 (0)