From a2feec0babedda2d2482c3caaee5ab5867691d8b Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 4 Nov 2013 15:28:19 -0600 Subject: [PATCH] Add a pseudo-integration test for getResources() This adds an extra class path element to the VM running the unit tests, writes files with identical file names into both directories and then verifies that SystemClassLoader#getResources can find them. Signed-off-by: Johannes Schindelin --- makefile | 11 +++++++++-- test/Misc.java | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/makefile b/makefile index ae3da55383..4eaeafa092 100755 --- a/makefile +++ b/makefile @@ -1474,13 +1474,20 @@ ifeq ($(continuations),true) $(build)/compile-x86-asm.o: $(src)/continuations-x86.$(asm-format) endif -$(build)/run-tests.sh: $(test-classes) makefile +$(build)/run-tests.sh: $(test-classes) makefile $(build)/extra-dir/multi-classpath-test.txt $(build)/test/multi-classpath-test.txt echo 'cd $$(dirname $$0)' > $(@) echo "sh ./test.sh 2>/dev/null \\" >> $(@) - echo "$(shell echo $(library-path) | sed 's|$(build)|\.|g') ./$(name)-unittest${exe-suffix} ./$(notdir $(test-executable)) $(mode) \"-Djava.library.path=. -cp test\" \\" >> $(@) + echo "$(shell echo $(library-path) | sed 's|$(build)|\.|g') ./$(name)-unittest${exe-suffix} ./$(notdir $(test-executable)) $(mode) \"-Djava.library.path=. -cp test:extra-dir\" \\" >> $(@) echo "$(call class-names,$(test-build),$(filter-out $(test-support-classes), $(test-classes))) \\" >> $(@) echo "$(continuation-tests) $(tail-tests)" >> $(@) +$(build)/extra-dir/multi-classpath-test.txt: + mkdir -p $(build)/extra-dir + echo "$@" > $@ + +$(build)/test/multi-classpath-test.txt: + echo "$@" > $@ + $(build)/test.sh: $(test)/test.sh cp $(<) $(@) diff --git a/test/Misc.java b/test/Misc.java index 91195d5f13..b0fde2d44b 100644 --- a/test/Misc.java +++ b/test/Misc.java @@ -1,3 +1,7 @@ +import java.io.IOException; +import java.net.URL; +import java.util.Enumeration; + public class Misc { private static class μClass { public int μField; @@ -262,6 +266,27 @@ public class Misc { expect((Protected.class.getModifiers() & java.lang.reflect.Modifier.PUBLIC) == 0); + + try { + int count = 0; + boolean test = false, extraDir = false; + ClassLoader loader = Misc.class.getClassLoader(); + Enumeration resources = loader.getResources("multi-classpath-test.txt"); + while (resources.hasMoreElements()) { + ++count; + String url = resources.nextElement().toString(); + if (url.contains("extra-dir")) { + extraDir = true; + } else if (url.contains("test")) { + test = true; + } + } + expect(count == 2); + expect(test); + expect(extraDir); + } catch (IOException e) { + throw new RuntimeException(e); + } } protected class Protected { }