aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/testutil/Scratch.java
diff options
context:
space:
mode:
authorGravatar jcater <jcater@google.com>2018-01-19 10:56:53 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-01-19 10:58:26 -0800
commit1708aad76b5223c233a5f96794345fe35c071da5 (patch)
treef9d8424ccdaa7699ff0a0301cf553c264352d4c8 /src/test/java/com/google/devtools/build/lib/testutil/Scratch.java
parent99f62ef22fd32277fde5fa1236f716a1e20b70c3 (diff)
Simplify the toolchain test case setup.
Also add a new appendFile method on Scratch. PiperOrigin-RevId: 182558199
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/testutil/Scratch.java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/testutil/Scratch.java24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/testutil/Scratch.java b/src/test/java/com/google/devtools/build/lib/testutil/Scratch.java
index a43af98166..689e50f24d 100644
--- a/src/test/java/com/google/devtools/build/lib/testutil/Scratch.java
+++ b/src/test/java/com/google/devtools/build/lib/testutil/Scratch.java
@@ -138,6 +138,30 @@ public final class Scratch {
DEFAULT_CHARSET);
}
+ /** Like {@code scratch.file}, but the lines are added to the end if the file already exists. */
+ public Path appendFile(String pathName, Collection<String> lines) throws IOException {
+ return appendFile(pathName, lines.toArray(new String[lines.size()]));
+ }
+
+ /** Like {@code scratch.file}, but the lines are added to the end if the file already exists. */
+ public Path appendFile(String pathName, String... lines) throws IOException {
+ return appendFile(pathName, DEFAULT_CHARSET, lines);
+ }
+
+ /** Like {@code scratch.file}, but the lines are added to the end if the file already exists. */
+ public Path appendFile(String pathName, Charset charset, String... lines) throws IOException {
+ Path path = resolve(pathName);
+
+ StringBuilder content = new StringBuilder();
+ if (path.exists()) {
+ content.append(readFile(pathName));
+ content.append("\n");
+ }
+ content.append(linesAsString(lines));
+
+ return overwriteFile(pathName, content.toString());
+ }
+
/**
* Like {@code scratch.file}, but the file is first deleted if it already
* exists.