From d38fffd38d92da2f5833004f6ca141e752affa6e Mon Sep 17 00:00:00 2001 From: Jerome Gaillard Date: Mon, 14 Nov 2016 14:40:26 +0000 Subject: [PATCH] Store failure thumbnails in CWD/out/failures When a test fails in layoutlib, store the resulting png files in out/failures subdirectory of the current working directory. That avoids the risk of collisions if tests for several branches of layoutlib are run at the same time. Test: Run tests in layoutlib with at least one failing test Change-Id: I31594a871e481e6aa410a165926ce544dc7ddcf2 (cherry picked from commit 82ebb9058479de56860f348ab969160e0d8294b6) --- .../layoutlib/bridge/intensive/ImageUtils.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/ImageUtils.java b/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/ImageUtils.java index d81b4ba65022b..d3f0f893f2ec4 100644 --- a/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/ImageUtils.java +++ b/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/ImageUtils.java @@ -179,7 +179,7 @@ public class ImageUtils { g.drawString("Actual", 2 * imageWidth + 10, 20); } - File output = new File(getTempDir(), "delta-" + imageName); + File output = new File(getFailureDir(), "delta-" + imageName); if (output.exists()) { boolean deleted = output.delete(); assertTrue(deleted); @@ -302,15 +302,16 @@ public class ImageUtils { } /** - * Temp directory where to write the thumbnails and deltas. + * Directory where to write the thumbnails and deltas. */ @NonNull - private static File getTempDir() { - if (System.getProperty("os.name").equals("Mac OS X")) { - return new File("/tmp"); //$NON-NLS-1$ - } + private static File getFailureDir() { + String workingDirString = System.getProperty("user.dir"); + File failureDir = new File(workingDirString, "out/failures"); - return new File(System.getProperty("java.io.tmpdir")); //$NON-NLS-1$ + //noinspection ResultOfMethodCallIgnored + failureDir.mkdirs(); + return failureDir; //$NON-NLS-1$ } /** @@ -319,7 +320,7 @@ public class ImageUtils { @NonNull private static String saveImageAndAppendMessage(@NonNull BufferedImage image, @NonNull String initialMessage, @NonNull String relativePath) throws IOException { - File output = new File(getTempDir(), getName(relativePath)); + File output = new File(getFailureDir(), getName(relativePath)); if (output.exists()) { boolean deleted = output.delete(); assertTrue(deleted);