8175336: [TESTBUG] aot junit tests added by 8169588 are not executed
Reviewed-by: kvn
This commit is contained in:
parent
f889b5119c
commit
5b097b494d
@ -20,10 +20,19 @@
|
|||||||
* or visit www.oracle.com if you need additional information or have any
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
* questions.
|
* questions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @modules jdk.aot/jdk.tools.jaotc
|
||||||
|
* jdk.aot/jdk.tools.jaotc.collect
|
||||||
|
* @run junit/othervm jdk.tools.jaotc.test.collect.ClassSearchTest
|
||||||
|
*/
|
||||||
|
|
||||||
package jdk.tools.jaotc.test.collect;
|
package jdk.tools.jaotc.test.collect;
|
||||||
|
|
||||||
|
|
||||||
import jdk.tools.jaotc.LoadedClass;
|
import jdk.tools.jaotc.LoadedClass;
|
||||||
|
import jdk.tools.jaotc.collect.*;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -32,45 +41,90 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
public class ClassSearchTest {
|
public class ClassSearchTest {
|
||||||
@Test(expected = InternalError.class)
|
@Test(expected = InternalError.class)
|
||||||
public void itShouldThrowExceptionIfNoProvidersAvailable() {
|
public void itShouldThrowExceptionIfNoProvidersAvailable() {
|
||||||
ClassSearch target = new ClassSearch();
|
ClassSearch target = new ClassSearch();
|
||||||
SearchPath searchPath = new SearchPath();
|
SearchPath searchPath = new SearchPath();
|
||||||
target.search(list("foo"), searchPath);
|
target.search(list(new SearchFor("foo")), searchPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void itShouldFindAProviderForEachEntry() {
|
public void itShouldFindAProviderForEachEntry() {
|
||||||
Set<String> searched = new HashSet<>();
|
Set<String> searched = new HashSet<>();
|
||||||
ClassSearch target = new ClassSearch();
|
ClassSearch target = new ClassSearch();
|
||||||
target.addProvider(new SourceProvider() {
|
target.addProvider(provider("", (name, searchPath) -> {
|
||||||
@Override
|
|
||||||
public ClassSource findSource(String name, SearchPath searchPath) {
|
|
||||||
searched.add(name);
|
searched.add(name);
|
||||||
return new NoopSource();
|
return new NoopSource();
|
||||||
}
|
}));
|
||||||
});
|
target.search(searchForList("foo", "bar", "foobar"), null);
|
||||||
target.search(list("foo", "bar", "foobar"), null);
|
|
||||||
Assert.assertEquals(hashset("foo", "bar", "foobar"), searched);
|
Assert.assertEquals(hashset("foo", "bar", "foobar"), searched);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SourceProvider provider(String supports, BiFunction<String, SearchPath, ClassSource> fn) {
|
||||||
|
return new SourceProvider() {
|
||||||
|
@Override
|
||||||
|
public ClassSource findSource(String name, SearchPath searchPath) {
|
||||||
|
return fn.apply(name, searchPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supports(String type) {
|
||||||
|
return supports.equals(type);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void itShouldSearchAllProviders() {
|
public void itShouldOnlySearchSupportedProvidersForKnownType() {
|
||||||
Set<String> visited = new HashSet<>();
|
Set<String> visited = new HashSet<>();
|
||||||
ClassSearch target = new ClassSearch();
|
ClassSearch target = new ClassSearch();
|
||||||
target.addProvider((name, searchPath) -> {
|
|
||||||
visited.add("1");
|
target.addProvider(provider("jar", (name, searchPath) -> {
|
||||||
|
visited.add("jar");
|
||||||
return null;
|
return null;
|
||||||
});
|
}));
|
||||||
target.addProvider((name, searchPath) -> {
|
|
||||||
visited.add("2");
|
target.addProvider(provider("dir", (name, searchPath) -> {
|
||||||
|
visited.add("dir");
|
||||||
return null;
|
return null;
|
||||||
});
|
}));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
target.search(list("foo"), null);
|
target.search(list(new SearchFor("some", "dir")), null);
|
||||||
|
} catch (InternalError e) {
|
||||||
|
// throws because no provider gives a source
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.assertEquals(hashset("dir"), visited);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = InternalError.class)
|
||||||
|
public void itShouldThrowErrorIfMultipleSourcesAreAvailable() {
|
||||||
|
ClassSearch target = new ClassSearch();
|
||||||
|
target.addProvider(provider("", (name, searchPath) -> consumer -> Assert.fail()));
|
||||||
|
target.addProvider(provider("", (name, searchPath) -> consumer -> Assert.fail()));
|
||||||
|
|
||||||
|
target.search(searchForList("somethign"), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void itShouldSearchAllProvidersForUnknownType() {
|
||||||
|
Set<String> visited = new HashSet<>();
|
||||||
|
ClassSearch target = new ClassSearch();
|
||||||
|
target.addProvider(provider("", (name, searchPath) -> {
|
||||||
|
visited.add("1");
|
||||||
|
return null;
|
||||||
|
}));
|
||||||
|
target.addProvider(provider("", (name, searchPath) -> {
|
||||||
|
visited.add("2");
|
||||||
|
return null;
|
||||||
|
}));
|
||||||
|
|
||||||
|
try {
|
||||||
|
target.search(searchForList("foo"), null);
|
||||||
} catch (InternalError e) {
|
} catch (InternalError e) {
|
||||||
// throws because no provider gives a source
|
// throws because no provider gives a source
|
||||||
}
|
}
|
||||||
@ -84,6 +138,11 @@ public class ClassSearchTest {
|
|||||||
|
|
||||||
ClassSearch target = new ClassSearch();
|
ClassSearch target = new ClassSearch();
|
||||||
target.addProvider(new SourceProvider() {
|
target.addProvider(new SourceProvider() {
|
||||||
|
@Override
|
||||||
|
public boolean supports(String type) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClassSource findSource(String name, SearchPath searchPath) {
|
public ClassSource findSource(String name, SearchPath searchPath) {
|
||||||
return new ClassSource() {
|
return new ClassSource() {
|
||||||
@ -101,7 +160,7 @@ public class ClassSearchTest {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
java.util.List<LoadedClass> search = target.search(list("/tmp/something"), null);
|
java.util.List<LoadedClass> search = target.search(searchForList("/tmp/something"), null);
|
||||||
Assert.assertEquals(list(new LoadedClass("foo.Bar", null)), search);
|
Assert.assertEquals(list(new LoadedClass("foo.Bar", null)), search);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,8 +174,16 @@ public class ClassSearchTest {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ClassSearch target = new ClassSearch();
|
ClassSearch target = new ClassSearch();
|
||||||
target.addProvider((name, searchPath) -> consumer -> consumer.accept("foo.Bar", classLoader));
|
target.addProvider(provider("", (name, searchPath) -> consumer -> consumer.accept("foo.Bar", classLoader)));
|
||||||
target.search(list("foobar"), null);
|
target.search(searchForList("foobar"), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<SearchFor> searchForList(String... entries) {
|
||||||
|
List<SearchFor> list = new ArrayList<>();
|
||||||
|
for (String entry : entries) {
|
||||||
|
list.add(new SearchFor(entry));
|
||||||
|
}
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> List<T> list(T... entries) {
|
private <T> List<T> list(T... entries) {
|
||||||
|
@ -20,6 +20,14 @@
|
|||||||
* or visit www.oracle.com if you need additional information or have any
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
* questions.
|
* questions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @modules jdk.aot/jdk.tools.jaotc
|
||||||
|
* jdk.aot/jdk.tools.jaotc.collect
|
||||||
|
* @run junit/othervm jdk.tools.jaotc.test.collect.ClassSourceTest
|
||||||
|
*/
|
||||||
|
|
||||||
package jdk.tools.jaotc.test.collect;
|
package jdk.tools.jaotc.test.collect;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
@ -27,6 +27,8 @@ import java.nio.file.Path;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import jdk.tools.jaotc.collect.FileSupport;
|
||||||
|
|
||||||
public class FakeFileSupport extends FileSupport {
|
public class FakeFileSupport extends FileSupport {
|
||||||
private final Set<String> exists = new HashSet<>();
|
private final Set<String> exists = new HashSet<>();
|
||||||
private final Set<String> directories = new HashSet<>();
|
private final Set<String> directories = new HashSet<>();
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
*/
|
*/
|
||||||
package jdk.tools.jaotc.test.collect;
|
package jdk.tools.jaotc.test.collect;
|
||||||
|
|
||||||
|
import jdk.tools.jaotc.collect.SearchPath;
|
||||||
|
|
||||||
import java.nio.file.FileSystem;
|
import java.nio.file.FileSystem;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
@ -20,6 +20,17 @@
|
|||||||
* or visit www.oracle.com if you need additional information or have any
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
* questions.
|
* questions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @modules jdk.aot/jdk.tools.jaotc
|
||||||
|
* jdk.aot/jdk.tools.jaotc.collect
|
||||||
|
*
|
||||||
|
* @build jdk.tools.jaotc.test.collect.Utils
|
||||||
|
* @build jdk.tools.jaotc.test.collect.FakeFileSupport
|
||||||
|
* @run junit/othervm jdk.tools.jaotc.test.collect.SearchPathTest
|
||||||
|
*/
|
||||||
|
|
||||||
package jdk.tools.jaotc.test.collect;
|
package jdk.tools.jaotc.test.collect;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -30,6 +41,8 @@ import java.nio.file.FileSystems;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
import jdk.tools.jaotc.collect.*;
|
||||||
|
|
||||||
import static jdk.tools.jaotc.test.collect.Utils.set;
|
import static jdk.tools.jaotc.test.collect.Utils.set;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@ -21,11 +21,22 @@
|
|||||||
* questions.
|
* questions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @modules jdk.aot/jdk.tools.jaotc
|
||||||
|
* jdk.aot/jdk.tools.jaotc.collect
|
||||||
|
* jdk.aot/jdk.tools.jaotc.collect.directory
|
||||||
|
* @compile ../Utils.java
|
||||||
|
* @compile ../FakeFileSupport.java
|
||||||
|
* @run junit/othervm jdk.tools.jaotc.test.collect.directory.DirectorySourceProviderTest
|
||||||
|
*/
|
||||||
|
|
||||||
package jdk.tools.jaotc.test.collect.directory;
|
package jdk.tools.jaotc.test.collect.directory;
|
||||||
|
|
||||||
import jdk.tools.jaotc.collect.ClassSource;
|
import jdk.tools.jaotc.collect.ClassSource;
|
||||||
|
import jdk.tools.jaotc.collect.directory.DirectorySourceProvider;
|
||||||
import jdk.tools.jaotc.test.collect.FakeFileSupport;
|
import jdk.tools.jaotc.test.collect.FakeFileSupport;
|
||||||
import jdk.tools.jaotc.test.collect.FileSupport;
|
import jdk.tools.jaotc.collect.FileSupport;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -20,9 +20,23 @@
|
|||||||
* or visit www.oracle.com if you need additional information or have any
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
* questions.
|
* questions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @modules jdk.aot/jdk.tools.jaotc
|
||||||
|
* jdk.aot/jdk.tools.jaotc.collect
|
||||||
|
* jdk.aot/jdk.tools.jaotc.collect.jar
|
||||||
|
* @compile ../Utils.java
|
||||||
|
* @compile ../FakeFileSupport.java
|
||||||
|
* @compile ../FakeSearchPath.java
|
||||||
|
*
|
||||||
|
* @run junit/othervm jdk.tools.jaotc.test.collect.jar.JarSourceProviderTest
|
||||||
|
*/
|
||||||
|
|
||||||
package jdk.tools.jaotc.test.collect.jar;
|
package jdk.tools.jaotc.test.collect.jar;
|
||||||
|
|
||||||
import jdk.tools.jaotc.collect.ClassSource;
|
import jdk.tools.jaotc.collect.ClassSource;
|
||||||
|
import jdk.tools.jaotc.collect.jar.JarSourceProvider;
|
||||||
import jdk.tools.jaotc.test.collect.FakeFileSupport;
|
import jdk.tools.jaotc.test.collect.FakeFileSupport;
|
||||||
import jdk.tools.jaotc.test.collect.FakeSearchPath;
|
import jdk.tools.jaotc.test.collect.FakeSearchPath;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
@ -20,15 +20,31 @@
|
|||||||
* or visit www.oracle.com if you need additional information or have any
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
* questions.
|
* questions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @modules jdk.aot/jdk.tools.jaotc
|
||||||
|
* jdk.aot/jdk.tools.jaotc.collect
|
||||||
|
* jdk.aot/jdk.tools.jaotc.collect.module
|
||||||
|
* @compile ../Utils.java
|
||||||
|
* @run junit/othervm jdk.tools.jaotc.test.collect.module.ModuleSourceProviderTest
|
||||||
|
*/
|
||||||
|
|
||||||
package jdk.tools.jaotc.test.collect.module;
|
package jdk.tools.jaotc.test.collect.module;
|
||||||
|
|
||||||
import jdk.tools.jaotc.*;
|
import jdk.tools.jaotc.collect.FileSupport;
|
||||||
import jdk.tools.jaotc.test.collect.FakeSearchPath;
|
import jdk.tools.jaotc.collect.module.ModuleSource;
|
||||||
|
import jdk.tools.jaotc.collect.module.ModuleSourceProvider;
|
||||||
import jdk.tools.jaotc.test.collect.Utils;
|
import jdk.tools.jaotc.test.collect.Utils;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.FileSystem;
|
||||||
import java.nio.file.FileSystems;
|
import java.nio.file.FileSystems;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
@ -36,28 +52,42 @@ import static org.junit.Assert.assertNull;
|
|||||||
public class ModuleSourceProviderTest {
|
public class ModuleSourceProviderTest {
|
||||||
private ClassLoader classLoader;
|
private ClassLoader classLoader;
|
||||||
private ModuleSourceProvider target;
|
private ModuleSourceProvider target;
|
||||||
|
private FileSupport fileSupport;
|
||||||
|
private BiFunction<Path, Path, Path> getSubDirectory = null;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
classLoader = new FakeClassLoader();
|
classLoader = new FakeClassLoader();
|
||||||
target = new ModuleSourceProvider(FileSystems.getDefault(), classLoader);
|
fileSupport = new FileSupport() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDirectory(Path path) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Path getSubDirectory(FileSystem fileSystem, Path root, Path path) throws IOException {
|
||||||
|
if (getSubDirectory == null) {
|
||||||
|
throw new IOException("Nope");
|
||||||
|
}
|
||||||
|
return getSubDirectory.apply(root, path);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
target = new ModuleSourceProvider(FileSystems.getDefault(), classLoader, fileSupport);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void itShouldUseSearchPath() {
|
public void itShouldUseFileSupport() {
|
||||||
FakeSearchPath searchPath = new FakeSearchPath("blah/java.base");
|
getSubDirectory = (root, path) -> {
|
||||||
ModuleSource source = (ModuleSource) target.findSource("java.base", searchPath);
|
if (root.toString().equals("modules") && path.toString().equals("test.module")) {
|
||||||
assertEquals(Utils.set("java.base"), searchPath.entries);
|
return Paths.get("modules/test.module");
|
||||||
assertEquals("blah/java.base", source.getModulePath().toString());
|
}
|
||||||
assertEquals("module:blah/java.base", source.toString());
|
return null;
|
||||||
}
|
};
|
||||||
|
|
||||||
@Test
|
ModuleSource source = (ModuleSource) target.findSource("test.module", null);
|
||||||
public void itShouldReturnNullIfSearchPathReturnsNull() {
|
assertEquals("modules/test.module", source.getModulePath().toString());
|
||||||
FakeSearchPath searchPath = new FakeSearchPath(null);
|
assertEquals("module:modules/test.module", source.toString());
|
||||||
ModuleSource source = (ModuleSource) target.findSource("jdk.base", searchPath);
|
|
||||||
assertEquals(Utils.set("jdk.base"), searchPath.entries);
|
|
||||||
assertNull(source);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class FakeClassLoader extends ClassLoader {
|
private static class FakeClassLoader extends ClassLoader {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user