You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2012/08/16 14:29:22 UTC

svn commit: r1373804 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/core/ lucene/core/src/test/org/apache/lucene/util/junitcompat/ lucene/test-framework/ lucene/test-framework/src/java/org/apache/lucene/util/

Author: rmuir
Date: Thu Aug 16 12:29:22 2012
New Revision: 1373804

URL: http://svn.apache.org/viewvc?rev=1373804&view=rev
Log:
LUCENE-4308: don't delete a test's files if the test fails

Added:
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestLeaveFilesIfTestFails.java
      - copied, changed from r1373801, lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestLeaveFilesIfTestFails.java
Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/   (props changed)
    lucene/dev/branches/branch_4x/lucene/test-framework/   (props changed)
    lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/CloseableFile.java
    lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/_TestUtil.java

Copied: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestLeaveFilesIfTestFails.java (from r1373801, lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestLeaveFilesIfTestFails.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestLeaveFilesIfTestFails.java?p2=lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestLeaveFilesIfTestFails.java&p1=lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestLeaveFilesIfTestFails.java&r1=1373801&r2=1373804&rev=1373804&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestLeaveFilesIfTestFails.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestLeaveFilesIfTestFails.java Thu Aug 16 12:29:22 2012
@@ -1,15 +1,5 @@
 package org.apache.lucene.util.junitcompat;
 
-import java.io.File;
-
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.util._TestUtil;
-import org.apache.lucene.util.junitcompat.TestFailIfDirectoryNotClosed.Nested1;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.JUnitCore;
-import org.junit.runner.Result;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -27,6 +17,14 @@ import org.junit.runner.Result;
  * limitations under the License.
  */
 
+import java.io.File;
+
+import org.apache.lucene.util._TestUtil;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.JUnitCore;
+import org.junit.runner.Result;
+
 public class TestLeaveFilesIfTestFails extends WithNestedTests {
   public TestLeaveFilesIfTestFails() {
     super(true);

Modified: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/CloseableFile.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/CloseableFile.java?rev=1373804&r1=1373803&r2=1373804&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/CloseableFile.java (original)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/CloseableFile.java Thu Aug 16 12:29:22 2012
@@ -24,25 +24,30 @@ import java.io.*;
  */
 final class CloseableFile implements Closeable {
   private final File file;
+  private final TestRuleMarkFailure failureMarker;
 
-  public CloseableFile(File file) {
+  public CloseableFile(File file, TestRuleMarkFailure failureMarker) {
     this.file = file;
+    this.failureMarker = failureMarker;
   }
 
   @Override
   public void close() throws IOException {
-    if (file.exists()) {
-      try {
-        _TestUtil.rmDir(file);
-      } catch (IOException e) {
-        // Ignore the exception from rmDir.
-      }
-
-      // Re-check.
+    // only if there were no other test failures.
+    if (failureMarker.wasSuccessful()) {
       if (file.exists()) {
-        throw new IOException(
+        try {
+          _TestUtil.rmDir(file);
+        } catch (IOException e) {
+          // Ignore the exception from rmDir.
+        }
+
+        // Re-check.
+        if (file.exists()) {
+          throw new IOException(
             "Could not remove: " + file.getAbsolutePath());
-      }
+        }
+    }
     }
   }
 }
\ No newline at end of file

Modified: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/_TestUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/_TestUtil.java?rev=1373804&r1=1373803&r2=1373804&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/_TestUtil.java (original)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/_TestUtil.java Thu Aug 16 12:29:22 2012
@@ -94,7 +94,7 @@ public class _TestUtil {
     try {
       File f = createTempFile(desc, "tmp", LuceneTestCase.TEMP_DIR);
       f.delete();
-      LuceneTestCase.closeAfterSuite(new CloseableFile(f));
+      LuceneTestCase.closeAfterSuite(new CloseableFile(f, LuceneTestCase.suiteFailureMarker));
       return f;
     } catch (IOException e) {
       throw new RuntimeException(e);
@@ -136,7 +136,7 @@ public class _TestUtil {
     rmDir(destDir);
 
     destDir.mkdir();
-    LuceneTestCase.closeAfterSuite(new CloseableFile(destDir));
+    LuceneTestCase.closeAfterSuite(new CloseableFile(destDir, LuceneTestCase.suiteFailureMarker));
 
     while (entries.hasMoreElements()) {
       ZipEntry entry = entries.nextElement();