Skip to content

Commit deb897d

Browse files
brettchabotcopybara-androidxtest
authored andcommitted
Rollback 'Split by whitespace for commands'.
See #2255 PiperOrigin-RevId: 686171833
1 parent 2477a04 commit deb897d

File tree

3 files changed

+1
-52
lines changed

3 files changed

+1
-52
lines changed

runner/android_test_orchestrator/java/androidx/test/orchestrator/TestRunnable.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import java.io.InputStream;
3434
import java.io.OutputStream;
3535
import java.util.ArrayList;
36-
import java.util.Collections;
3736
import java.util.List;
3837

3938
/** Runnable to run a single am instrument command to execute a single test. */
@@ -189,32 +188,19 @@ private Bundle getTargetInstrumentationArguments() {
189188
/**
190189
* Instrumentation params are delimited by comma, each param is stripped from leading and trailing
191190
* whitespace.
192-
*
193-
* <p>The order of the params are critical to the correctness here as we split up params that have
194-
* whitespace (eg: key value) into two different params `key` and `value` which means that those
195-
* two different params must be next to each other the entire time.
196191
*/
197192
private List<String> getInstrumentationParamsAndRemoveBundleArgs(Bundle arguments) {
198193
List<String> cleanedParams = new ArrayList<>();
199194
String forwardedArgs = arguments.getString(ORCHESTRATOR_FORWARDED_INSTRUMENTATION_ARGS);
200195
if (forwardedArgs != null) {
201196
for (String param : forwardedArgs.split(",")) {
202-
// ShellExecutor exhibits weird behavior when a param has a whitespace in it.
203-
// so we need to split by white-space to remove the spaces.
204-
Collections.addAll(cleanedParams, param.strip().split(" "));
197+
cleanedParams.add(param.strip());
205198
}
206199
arguments.remove(ORCHESTRATOR_FORWARDED_INSTRUMENTATION_ARGS);
207200
}
208201
return cleanedParams;
209202
}
210203

211-
/**
212-
* This method must maintain the order of the params
213-
*
214-
* <p>The order of the params are critical to the correctness here as we split up params that have
215-
* whitespace (eg: key value) into two different params `key` and `value` which means that those
216-
* two different params must be next to each other the entire time.
217-
*/
218204
private List<String> buildShellParams(Bundle arguments) throws IOException, ClientNotConnected {
219205
List<String> params = new ArrayList<>();
220206
params.add("instrument");
@@ -229,12 +215,6 @@ private List<String> buildShellParams(Bundle arguments) throws IOException, Clie
229215
params.add(arguments.getString(key));
230216
}
231217
params.add(getTargetInstrumentation());
232-
for (String param : params) {
233-
if (param.isEmpty() || param.contains(" ")) {
234-
throw new IllegalStateException(
235-
"Params must not contain any white-space to avoid encoding issues.");
236-
}
237-
}
238218
return params;
239219
}
240220

runner/android_test_orchestrator/javatests/androidx/test/orchestrator/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ axt_android_local_test(
5252
"//ext/junit",
5353
"//runner/android_test_orchestrator",
5454
"@maven//:com_google_guava_guava",
55-
"@maven//:com_google_truth_truth",
5655
"@maven//:org_hamcrest_hamcrest_core",
5756
"@maven//:org_hamcrest_hamcrest_library",
5857
],

runner/android_test_orchestrator/javatests/androidx/test/orchestrator/TestRunnableTest.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
2121
import static org.hamcrest.Matchers.endsWith;
2222
import static org.hamcrest.Matchers.is;
2323
import static org.hamcrest.Matchers.startsWith;
24-
import static org.junit.Assert.assertThrows;
2524

2625
import android.content.Context;
2726
import android.os.Bundle;
2827
import androidx.test.ext.junit.runners.AndroidJUnit4;
2928
import com.google.common.base.Joiner;
30-
import com.google.common.truth.Truth;
3129
import java.io.ByteArrayOutputStream;
3230
import java.io.IOException;
3331
import java.io.InputStream;
@@ -214,24 +212,6 @@ public void testRun_buildsParams_givenInstrumentationParamsAreHandledCorrectlyMu
214212
assertContainsRunnerArgs(runnable.params, "--A --B --C --key value");
215213
}
216214

217-
@Test
218-
public void testRun_buildsParams_givenValueWithSpaceParamThrows() {
219-
arguments.putString("someArgument", "A B");
220-
FakeListener listener = new FakeListener();
221-
FakeTestRunnable runnable =
222-
new FakeTestRunnable(context, "secret", arguments, outputStream, listener, null, true);
223-
assertThrows(IllegalStateException.class, runnable::run);
224-
}
225-
226-
@Test
227-
public void testRun_buildsParams_givenEmptyStringParamThrows() {
228-
arguments.putString("someArgument", "");
229-
FakeListener listener = new FakeListener();
230-
FakeTestRunnable runnable =
231-
new FakeTestRunnable(context, "secret", arguments, outputStream, listener, null, true);
232-
assertThrows(IllegalStateException.class, runnable::run);
233-
}
234-
235215
private static void assertContainsRunnerArgs(List<String> params, String... containsArgs) {
236216
String cmdArgs = Joiner.on(" ").join(params);
237217
assertThat(cmdArgs, startsWith("instrument -w -r"));
@@ -240,14 +220,4 @@ private static void assertContainsRunnerArgs(List<String> params, String... cont
240220
}
241221
assertThat(cmdArgs, endsWith("targetInstrumentation/targetRunner"));
242222
}
243-
244-
@Test
245-
public void testRun_buildsParams_givenInstrumentationParamsWithSpaceMaintainsOrder() {
246-
arguments.putString("orchestratorInstrumentationArgs", "--A,--B,--key value");
247-
FakeListener listener = new FakeListener();
248-
FakeTestRunnable runnable =
249-
new FakeTestRunnable(context, "secret", arguments, outputStream, listener, null, true);
250-
runnable.run();
251-
Truth.assertThat(runnable.params).containsAtLeast("--A", "--B", "--key", "value").inOrder();
252-
}
253223
}

0 commit comments

Comments
 (0)