Gracefully handle any unrecognized stack frame format

Reviewed By: javache

Differential Revision: D5736692

fbshipit-source-id: e90dc38fa203ae65ac839f37940e96f23b35c330
This commit is contained in:
Adam Ernst
2017-08-31 07:34:06 -07:00
committed by Facebook Github Bot
parent 259161f872
commit 93993799eb
2 changed files with 24 additions and 25 deletions

View File

@@ -9,15 +9,13 @@
package com.facebook.react.devsupport;
import com.facebook.react.devsupport.interfaces.StackFrame;
import static org.fest.assertions.api.Assertions.assertThat;
import com.facebook.react.devsupport.interfaces.StackFrame;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.fest.assertions.api.Assertions.failBecauseExceptionWasNotThrown;
@RunWith(RobolectricTestRunner.class)
public class StackTraceHelperTest {
@@ -43,11 +41,19 @@ public class StackTraceHelperTest {
@Test
public void testParseStackFrameWithInvalidFrame() {
try {
StackTraceHelper.convertJsStackTrace("Test.bundle:ten:twenty");
failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalArgumentException.class);
}
final StackFrame frame = StackTraceHelper.convertJsStackTrace("Test.bundle:ten:twenty")[0];
assertThat(frame.getMethod()).isEqualTo("Test.bundle:ten:twenty");
assertThat(frame.getFileName()).isEqualTo("");
assertThat(frame.getLine()).isEqualTo(-1);
assertThat(frame.getColumn()).isEqualTo(-1);
}
@Test
public void testParseStackFrameWithNativeCodeFrame() {
final StackFrame frame = StackTraceHelper.convertJsStackTrace("forEach@[native code]")[0];
assertThat(frame.getMethod()).isEqualTo("forEach@[native code]");
assertThat(frame.getFileName()).isEqualTo("");
assertThat(frame.getLine()).isEqualTo(-1);
assertThat(frame.getColumn()).isEqualTo(-1);
}
}