test/java/module/modinit/RunMTest.java

Print this page

        

*** 59,70 **** Map<String,String> m = (Map<String,String>)(Map)p; defaultProperties = new HashMap<String,String>(m); defaultProperties.put("header", WARNING_HEADER); } ! private final File file; ! private final File outputDirectory; private final List<ModuleDescription> modules; private final List<TestDescription> tests; private RunMTest(File file, String baseDirectory) throws IOException { this.file = file; --- 59,70 ---- Map<String,String> m = (Map<String,String>)(Map)p; defaultProperties = new HashMap<String,String>(m); defaultProperties.put("header", WARNING_HEADER); } ! protected final File file; ! protected final File outputDirectory; private final List<ModuleDescription> modules; private final List<TestDescription> tests; private RunMTest(File file, String baseDirectory) throws IOException { this.file = file;
*** 75,95 **** if (k == -1) { subdir = file.getName(); } else { subdir = cPath.substring(k + mString.length()); } ! System.out.println(">>> Test " + subdir); outputDirectory = new File(baseDirectory, subdir); if (outputDirectory.exists()) { recursiveDelete(outputDirectory); } modules = new ArrayList<ModuleDescription>(); tests = new ArrayList<TestDescription>(); parse(); } ! private String getName() { return file.getName(); } private static String template; --- 75,95 ---- if (k == -1) { subdir = file.getName(); } else { subdir = cPath.substring(k + mString.length()); } ! System.out.println(">>>Test " + subdir); outputDirectory = new File(baseDirectory, subdir); if (outputDirectory.exists()) { recursiveDelete(outputDirectory); } modules = new ArrayList<ModuleDescription>(); tests = new ArrayList<TestDescription>(); parse(); } ! protected String getName() { return file.getName(); } private static String template;
*** 308,327 **** for (TestDescription t : tests) { t.runTest(this); } } - private static class TestDescription { ! private final String name; ! private String result; ! private TestDescription(String name) { this.name = name; } ! private void runTest(RunMTest mTest) throws Exception { System.out.println("> Running test " + name + "..."); Repository parent = sun.module.repository.RepositoryConfig.getSystemRepository(); Repository repository = Modules.newLocalRepository(parent, mTest.getName(), mTest.outputDirectory); ModuleDefinition md = repository.find(name); try { --- 308,360 ---- for (TestDescription t : tests) { t.runTest(this); } } ! // Abstracting the creation of TestDescription instances to a factory ! // allows other tests to override TestDescription.runTest. ! // ! public static class TestDescriptionFactory { ! private static TestDescriptionFactory instance; ! static TestDescription create(String name) { ! return getInstance().doCreate(name); ! } ! ! private static TestDescriptionFactory getInstance() { ! if (instance == null) { ! String factName = System.getProperty("TestDescriptionFactory.classname"); ! if (factName != null) { ! try { ! Class<?> clazz = Class.forName(factName); ! instance = (TestDescriptionFactory) clazz.newInstance(); ! } catch (Throwable t) { ! throw new RuntimeException(t); ! } ! } else { ! instance = new TestDescriptionFactory(); ! } ! } ! return instance; ! } ! ! protected TestDescription doCreate(String name) { ! return new TestDescription(name); ! } ! } ! ! public static class TestDescription { ! ! protected final String name; ! protected String result; ! ! TestDescription(String name) { this.name = name; } ! protected void runTest(RunMTest mTest) throws Exception { System.out.println("> Running test " + name + "..."); Repository parent = sun.module.repository.RepositoryConfig.getSystemRepository(); Repository repository = Modules.newLocalRepository(parent, mTest.getName(), mTest.outputDirectory); ModuleDefinition md = repository.find(name); try {
*** 358,368 **** } private TestDescription parseTest(String header, BufferedReader reader) throws IOException { String[] s = header.split(" "); String name = s[s.length - 1]; ! TestDescription test = new TestDescription(name); while (true) { String line = getLine(reader); if (line == null) { throw new EOFException(); } --- 391,401 ---- } private TestDescription parseTest(String header, BufferedReader reader) throws IOException { String[] s = header.split(" "); String name = s[s.length - 1]; ! TestDescription test = TestDescriptionFactory.create(name); while (true) { String line = getLine(reader); if (line == null) { throw new EOFException(); }