Skip to content

Commit

Permalink
Add test case for annotation processor option with space
Browse files Browse the repository at this point in the history
Add a test to reproduce bazelbuild/bazel#19360

Fixes #272

FUTURE_COPYBARA_INTEGRATE_REVIEW=#272 from guw:main b2b7c2b
PiperOrigin-RevId: 564393335
  • Loading branch information
guw authored and Javac Team committed Sep 11, 2023
1 parent 3417047 commit 0eec36e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
7 changes: 1 addition & 6 deletions java/com/google/turbine/options/TurbineOptionsParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import static com.google.common.base.Preconditions.checkArgument;

import com.google.common.base.CharMatcher;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.turbine.options.TurbineOptions.ReducedClasspathMode;
import java.io.IOException;
Expand Down Expand Up @@ -159,9 +157,6 @@ private static void parse(TurbineOptions.Builder builder, Deque<String> argument
}
}

private static final Splitter ARG_SPLITTER =
Splitter.on(CharMatcher.breakingWhitespace()).omitEmptyStrings().trimResults();

/**
* Pre-processes an argument list, expanding arguments of the form {@code @filename} by reading
* the content of the file and appending whitespace-delimited options to {@code argumentDeque}.
Expand All @@ -186,7 +181,7 @@ private static void expandParamsFiles(Deque<String> argumentDeque, Iterable<Stri
if (!Files.exists(paramsPath)) {
throw new AssertionError("params file does not exist: " + paramsPath);
}
expandParamsFiles(argumentDeque, ARG_SPLITTER.split(Files.readString(paramsPath)));
expandParamsFiles(argumentDeque, Files.readAllLines(paramsPath));
} else {
argumentDeque.addLast(arg);
}
Expand Down
14 changes: 12 additions & 2 deletions javatests/com/google/turbine/options/TurbineOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,15 @@ public void optionalTargetLabel() throws Exception {
public void paramsFile() throws Exception {
Iterable<String> paramsArgs =
Iterables.concat(
BASE_ARGS, Arrays.asList("--javacopts", "-source", "8", "-target", "8", "--"));
BASE_ARGS,
Arrays.asList(
"--javacopts",
"-source",
"8",
"-target",
"8",
"-Aconnector.opt=with,space, here",
"--"));
Path params = tmpFolder.newFile("params.txt").toPath();
Files.write(params, paramsArgs, StandardCharsets.UTF_8);

Expand All @@ -206,7 +214,9 @@ public void paramsFile() throws Exception {
TurbineOptions options = TurbineOptionsParser.parse(Arrays.asList(lines));

// assert that options were read from params file
assertThat(options.javacOpts()).containsExactly("-source", "8", "-target", "8").inOrder();
assertThat(options.javacOpts())
.containsExactly("-source", "8", "-target", "8", "-Aconnector.opt=with,space, here")
.inOrder();
// ... and directly from the command line
assertThat(options.targetLabel()).hasValue("//custom/label");
}
Expand Down

0 comments on commit 0eec36e

Please sign in to comment.