Mercurial > hg > truffle
changeset 22023:fee42ec8c59b
made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 21 Jul 2015 15:56:56 +0200 |
parents | 4e9d4f4a63da |
children | 216e0683bbf1 |
files | truffle/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTestRunner.java truffle/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTestSuite.java |
diffstat | 2 files changed, 36 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTestRunner.java Tue Jul 21 01:15:01 2015 +0200 +++ b/truffle/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTestRunner.java Tue Jul 21 15:56:56 2015 +0200 @@ -23,6 +23,7 @@ package com.oracle.truffle.sl.test; import java.io.*; +import java.net.*; import java.nio.charset.*; import java.nio.file.*; import java.nio.file.attribute.*; @@ -96,17 +97,21 @@ throw new InitializationError(String.format("@%s annotation required on class '%s' to run with '%s'.", SLTestSuite.class.getSimpleName(), c.getName(), SLTestRunner.class.getSimpleName())); } - String[] pathes = suite.value(); + String[] paths = suite.value(); + + Path root = getRootViaResourceURL(c, paths); - Path root = null; - for (String path : pathes) { - root = FileSystems.getDefault().getPath(path); - if (Files.exists(root)) { - break; + if (root == null) { + for (String path : paths) { + Path candidate = FileSystems.getDefault().getPath(path); + if (Files.exists(candidate)) { + root = candidate; + break; + } } } - if (root == null && pathes.length > 0) { - throw new FileNotFoundException(pathes[0]); + if (root == null && paths.length > 0) { + throw new FileNotFoundException(paths[0]); } final Path rootPath = root; @@ -139,6 +144,28 @@ return foundCases; } + private static Path getRootViaResourceURL(final Class<?> c, String[] paths) { + URL url = c.getResource(c.getSimpleName() + ".class"); + if (url != null) { + String externalForm = url.toExternalForm(); + if (externalForm.startsWith("file:")) { + char sep = File.separatorChar; + String suffix = sep + "bin" + sep + c.getName().replace('.', sep) + ".class"; + if (externalForm.endsWith(suffix)) { + String base = externalForm.substring("file:".length(), externalForm.length() - suffix.length()); + System.out.println(base); + for (String path : paths) { + String candidate = base + sep + path; + if (new File(candidate).exists()) { + return FileSystems.getDefault().getPath(candidate); + } + } + } + } + } + return null; + } + private static String readAllLines(Path file) throws IOException { // fix line feeds for non unix os StringBuilder outFile = new StringBuilder();
--- a/truffle/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTestSuite.java Tue Jul 21 01:15:01 2015 +0200 +++ b/truffle/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTestSuite.java Tue Jul 21 15:56:56 2015 +0200 @@ -29,7 +29,7 @@ public @interface SLTestSuite { /** - * Defines the base path of the test suite. Multiple base pathes can be specified. However only + * Defines the base path of the test suite. Multiple base paths can be specified. However only * the first base that exists is used to lookup the test cases. */ String[] value();