use of com.oracle.truffle.sl.test.SLTestRunner.TestCase in project graal by oracle.
the class SLTestRunner method createTests.
protected static List<TestCase> createTests(final Class<?> c) throws IOException, InitializationError {
SLTestSuite suite = c.getAnnotation(SLTestSuite.class);
if (suite == null) {
throw new InitializationError(String.format("@%s annotation required on class '%s' to run with '%s'.", SLTestSuite.class.getSimpleName(), c.getName(), SLTestRunner.class.getSimpleName()));
}
String[] paths = suite.value();
Class<?> testCaseDirectory = c;
if (suite.testCaseDirectory() != SLTestSuite.class) {
testCaseDirectory = suite.testCaseDirectory();
}
Path root = getRootViaResourceURL(testCaseDirectory, paths);
if (root == null) {
for (String path : paths) {
Path candidate = FileSystems.getDefault().getPath(path);
if (Files.exists(candidate)) {
root = candidate;
break;
}
}
}
if (root == null && paths.length > 0) {
throw new FileNotFoundException(paths[0]);
}
final Path rootPath = root;
final List<TestCase> foundCases = new ArrayList<>();
Files.walkFileTree(rootPath, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path sourceFile, BasicFileAttributes attrs) throws IOException {
String sourceName = sourceFile.getFileName().toString();
if (sourceName.endsWith(SOURCE_SUFFIX)) {
String baseName = sourceName.substring(0, sourceName.length() - SOURCE_SUFFIX.length());
Path inputFile = sourceFile.resolveSibling(baseName + INPUT_SUFFIX);
String testInput = "";
if (Files.exists(inputFile)) {
testInput = readAllLines(inputFile);
}
Path outputFile = sourceFile.resolveSibling(baseName + OUTPUT_SUFFIX);
String expectedOutput = "";
if (Files.exists(outputFile)) {
expectedOutput = readAllLines(outputFile);
}
foundCases.add(new TestCase(c, baseName, sourceName, sourceFile, testInput, expectedOutput));
}
return FileVisitResult.CONTINUE;
}
});
return foundCases;
}
Aggregations