Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit

Permalink
8164597: TestIOException.java fails after push for JDK-8164130
Browse files Browse the repository at this point in the history
Reviewed-by: prappo
  • Loading branch information
jonathan-gibbons committed Jun 24, 2020
1 parent 0e60e8a commit 95b9024
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 13 deletions.
1 change: 0 additions & 1 deletion test/langtools/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
###########################################################################
#
# javadoc
jdk/javadoc/doclet/testIOException/TestIOException.java 8164597 windows-all

###########################################################################
#
Expand Down
104 changes: 92 additions & 12 deletions test/langtools/jdk/javadoc/doclet/testIOException/TestIOException.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,49 @@

import java.io.File;
import java.io.FileWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Locale;
import java.util.Map;

import javadoc.tester.JavadocTester;

/**
* Tests IO Exception handling.
*
* Update: Windows does not permit setting folder to be readonly.
* https://support.microsoft.com/en-us/help/326549/you-cannot-view-or-change-the-read-only-or-the-system-attributes-of-fo
*/
public class TestIOException extends JavadocTester {

public static void main(String... args) throws Exception {
TestIOException tester = new TestIOException();
tester.runTests();
}

/**
* Tests a read-only directory.
* On Windows, this test may be skipped.
*/
@Test
public void testReadOnlyDirectory() {
File outDir = new File("out1");
if (!outDir.mkdir()) {
throw new Error("Cannot create directory");
throw error(outDir, "Cannot create directory");
}
if (!outDir.setReadOnly()) {
throw new Error("could not set directory read-only");
if (skip(outDir)) {
return;
}
throw error(outDir, "could not set directory read-only");
}
if (outDir.canWrite()) {
throw new Error("directory is writable");
throw error(outDir, "directory is writable");
}

try {
javadoc("-d", outDir.toString(),
"-Xdoclint:-missing",
new File(testSrc, "TestIOException.java").getPath());
checkExit(Exit.ERROR);
checkOutput(Output.OUT, true,
Expand All @@ -67,24 +85,29 @@ public void testReadOnlyDirectory() {
}
}

/**
* Tests a read-only file.
* @throws Exception if an error occurred
*/
@Test
public void testReadOnlyFile() throws Exception {
File outDir = new File("out2");
if (!outDir.mkdir()) {
throw new Error("Cannot create directory");
throw error(outDir, "Cannot create directory");
}
File index = new File(outDir, "index.html");
try (FileWriter fw = new FileWriter(index)) { }
if (!index.setReadOnly()) {
throw new Error("could not set index read-only");
throw error(index, "could not set index read-only");
}
if (index.canWrite()) {
throw new Error("index is writable");
throw error(index, "index is writable");
}

try {
setOutputDirectoryCheck(DirectoryCheck.NONE);
javadoc("-d", outDir.toString(),
"-Xdoclint:-missing",
new File(testSrc, "TestIOException.java").getPath());

checkExit(Exit.ERROR);
Expand All @@ -96,6 +119,11 @@ public void testReadOnlyFile() throws Exception {
}
}

/**
* Tests a read-only subdirectory.
* On Windows, this test may be skipped.
* @throws Exception if an error occurred
*/
@Test
public void testReadOnlySubdirectory() throws Exception {
// init source file
Expand All @@ -111,19 +139,23 @@ public void testReadOnlySubdirectory() throws Exception {
File outDir = new File("out3");
File pkgOutDir = new File(outDir, "p");
if (!pkgOutDir.mkdirs()) {
throw new Error("Cannot create directory");
throw error(pkgOutDir, "Cannot create directory");
}
if (!pkgOutDir.setReadOnly()) {
throw new Error("could not set directory read-only");
if (skip(pkgOutDir)) {
return;
}
throw error(pkgOutDir, "could not set directory read-only");
}
if (pkgOutDir.canWrite()) {
throw new Error("directory is writable");
throw error(pkgOutDir, "directory is writable");
}

// run javadoc and check results
try {
setOutputDirectoryCheck(DirectoryCheck.NONE);
javadoc("-d", outDir.toString(),
"-Xdoclint:-missing",
src_p_C.getPath());
checkExit(Exit.ERROR);
checkOutput(Output.OUT, true,
Expand All @@ -134,6 +166,11 @@ public void testReadOnlySubdirectory() throws Exception {
}
}

/**
* Tests a read-only doc-files directory.
* On Windows, this test may be skipped.
* @throws Exception if an error occurred
*/
@Test
public void testReadOnlyDocFilesDir() throws Exception {
// init source files
Expand All @@ -155,18 +192,22 @@ public void testReadOnlyDocFilesDir() throws Exception {
File pkgOutDir = new File(outDir, "p");
File docFilesOutDir = new File(pkgOutDir, "doc-files");
if (!docFilesOutDir.mkdirs()) {
throw new Error("Cannot create directory");
throw error(docFilesOutDir, "Cannot create directory");
}
if (!docFilesOutDir.setReadOnly()) {
throw new Error("could not set directory read-only");
if (skip(docFilesOutDir)) {
return;
}
throw error(docFilesOutDir, "could not set directory read-only");
}
if (docFilesOutDir.canWrite()) {
throw new Error("directory is writable");
throw error(docFilesOutDir, "directory is writable");
}

try {
setOutputDirectoryCheck(DirectoryCheck.NONE);
javadoc("-d", outDir.toString(),
"-Xdoclint:-missing",
"-sourcepath", srcDir.getPath(),
"p");
checkExit(Exit.ERROR);
Expand All @@ -177,5 +218,44 @@ public void testReadOnlyDocFilesDir() throws Exception {
docFilesOutDir.setWritable(true);
}
}

private Error error(File f, String message) {
out.println(f + ": " + message);
showAllAttributes(f.toPath());
throw new Error(f + ": " + message);
}

private void showAllAttributes(Path p) {
showAttributes(p, "*");
showAttributes(p, "posix:*");
showAttributes(p, "dos:*");
}

private void showAttributes(Path p, String attributes) {
out.println("Attributes: " + attributes);
try {
Map<String, Object> map = Files.readAttributes(p, attributes);
map.forEach((n, v) -> out.format(" %-10s: %s%n", n, v));
} catch (UnsupportedOperationException e) {
out.println("Attributes not available " + attributes);
} catch (Throwable t) {
out.println("Error accessing attributes " + attributes + ": " + t);
}
}

private boolean skip(File dir) {
if (isWindows()) {
showAllAttributes(dir.toPath());
out.println("Windows: cannot set directory read only:" + dir);
out.println("TEST CASE SKIPPED");
return true;
} else {
return false;
}
}

private boolean isWindows() {
return System.getProperty("os.name").toLowerCase(Locale.US).startsWith("windows");
}
}

0 comments on commit 95b9024

Please sign in to comment.