Skip to content

Commit

Permalink
Remove duplicate code for 'debug' option
Browse files Browse the repository at this point in the history
'debug' support has been added through PR cucumber#613
  • Loading branch information
friederbluemle committed Oct 21, 2013
1 parent c55f0d0 commit be024b8
Showing 1 changed file with 3 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@
public class CucumberInstrumentation extends Instrumentation {
public static final String REPORT_VALUE_ID = "CucumberInstrumentation";
public static final String REPORT_KEY_NUM_TOTAL = "numtests";
public static final int DEFAULT_DEBUGGER_TIMEOUT = 10000;
public static final String TAG = "cucumber-android";

private final Bundle results = new Bundle();
private int debuggerTimeout;
private boolean justCount;
private int testCount;

Expand All @@ -56,21 +54,10 @@ public void onCreate(Bundle arguments) {
super.onCreate(arguments);

if (arguments != null) {
String debug = arguments.getString("debug");
if (debug != null) {
try {
debuggerTimeout = Integer.parseInt(debug);
} catch (NumberFormatException e) {
if (Boolean.parseBoolean(debug)) {
debuggerTimeout = DEFAULT_DEBUGGER_TIMEOUT;
}
}
}
debug = getBooleanArgument(arguments, "debug");
justCount = getBooleanArgument(arguments, "count");
}

debug = getBooleanArgument(arguments, "debug");

InstrumentationArguments instrumentationArguments = new InstrumentationArguments(arguments);

Context context = getContext();
Expand Down Expand Up @@ -126,17 +113,13 @@ private DexFile newDexFile(String apkPath) {
public void onStart() {
Looper.prepare();

if (debug) {
Debug.waitForDebugger();
}

if (justCount) {
results.putString(Instrumentation.REPORT_KEY_IDENTIFIER, REPORT_VALUE_ID);
results.putInt(REPORT_KEY_NUM_TOTAL, testCount);
finish(Activity.RESULT_OK, results);
} else {
if (debuggerTimeout != 0) {
waitForDebugger(debuggerTimeout);
if (debug) {
Debug.waitForDebugger();
}

runtimeOptions.getFormatters().add(new AndroidInstrumentationReporter(runtime, this, testCount));
Expand All @@ -158,37 +141,6 @@ public void onStart() {
}
}

/**
* Waits the specified time for a debugger to attach.
* <p />
* For some reason {@link Debug#waitForDebugger()} is not blocking and thinks a debugger is
* attached when there isn't.
*
* @param timeout the time in milliseconds to wait
*/
private void waitForDebugger(int timeout) {
System.out.println("waiting " + timeout + "ms for debugger to attach.");
long elapsed = 0;
while (!Debug.isDebuggerConnected() && elapsed < timeout) {
try {
System.out.println("waiting for debugger to attach...");
Thread.sleep(1000);
elapsed += 1000;
} catch (InterruptedException ie) {
}
}
if (Debug.isDebuggerConnected()) {
System.out.println("waiting for debugger to settle...");
try {
Thread.sleep(1300);
} catch (InterruptedException e) {
}
System.out.println("debugger connected.");
} else {
System.out.println("no debugger connected.");
}
}

private void printSummary() {
// TODO move this stuff into the AndroidLogcatReporter
for (Throwable t : runtime.getErrors()) {
Expand Down

0 comments on commit be024b8

Please sign in to comment.