Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTestRunner.java @ 15891:09ac9ac9c4fc
Truffle: SourceManager renamed to SourceFactory
- All methods are static, no longer accessed via ExecutionContext
- Sources are indexed with weak references
- File content caching is now optional; off by default
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Sat, 24 May 2014 10:34:43 -0700 |
parents | 4eda2fa64da6 |
children | 915ebb306fcc |
comparison
equal
deleted
inserted
replaced
15842:eb947cc7bff9 | 15891:09ac9ac9c4fc |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
52 | 52 |
53 private static final String LF = System.getProperty("line.separator"); | 53 private static final String LF = System.getProperty("line.separator"); |
54 | 54 |
55 static class TestCase { | 55 static class TestCase { |
56 protected final Description name; | 56 protected final Description name; |
57 protected final Source source; | 57 protected final Path path; |
58 protected final String sourceName; | |
58 protected final String testInput; | 59 protected final String testInput; |
59 protected final String expectedOutput; | 60 protected final String expectedOutput; |
60 protected String actualOutput; | 61 protected String actualOutput; |
61 | 62 |
62 protected TestCase(Class<?> testClass, String name, Source source, String testInput, String expectedOutput) { | 63 protected TestCase(Class<?> testClass, String baseName, String sourceName, Path path, String testInput, String expectedOutput) { |
63 this.name = Description.createTestDescription(testClass, name); | 64 this.name = Description.createTestDescription(testClass, baseName); |
64 this.source = source; | 65 this.sourceName = sourceName; |
66 this.path = path; | |
65 this.testInput = testInput; | 67 this.testInput = testInput; |
66 this.expectedOutput = expectedOutput; | 68 this.expectedOutput = expectedOutput; |
67 } | 69 } |
68 } | 70 } |
69 | 71 |
70 private final SourceManager sourceManager = new SourceManager(); | |
71 private final List<TestCase> testCases; | 72 private final List<TestCase> testCases; |
72 | 73 |
73 public SLTestRunner(Class<?> runningClass) throws InitializationError { | 74 public SLTestRunner(Class<?> runningClass) throws InitializationError { |
74 super(runningClass); | 75 super(runningClass); |
75 try { | 76 try { |
87 @Override | 88 @Override |
88 protected List<TestCase> getChildren() { | 89 protected List<TestCase> getChildren() { |
89 return testCases; | 90 return testCases; |
90 } | 91 } |
91 | 92 |
92 protected List<TestCase> createTests(final Class<?> c) throws IOException, InitializationError { | 93 protected static List<TestCase> createTests(final Class<?> c) throws IOException, InitializationError { |
93 SLTestSuite suite = c.getAnnotation(SLTestSuite.class); | 94 SLTestSuite suite = c.getAnnotation(SLTestSuite.class); |
94 if (suite == null) { | 95 if (suite == null) { |
95 throw new InitializationError(String.format("@%s annotation required on class '%s' to run with '%s'.", SLTestSuite.class.getSimpleName(), c.getName(), SLTestRunner.class.getSimpleName())); | 96 throw new InitializationError(String.format("@%s annotation required on class '%s' to run with '%s'.", SLTestSuite.class.getSimpleName(), c.getName(), SLTestRunner.class.getSimpleName())); |
96 } | 97 } |
97 | 98 |
128 String expectedOutput = ""; | 129 String expectedOutput = ""; |
129 if (Files.exists(outputFile)) { | 130 if (Files.exists(outputFile)) { |
130 expectedOutput = readAllLines(outputFile); | 131 expectedOutput = readAllLines(outputFile); |
131 } | 132 } |
132 | 133 |
133 foundCases.add(new TestCase(c, baseName, sourceManager.get(sourceName, readAllLines(sourceFile)), testInput, expectedOutput)); | 134 foundCases.add(new TestCase(c, baseName, sourceName, sourceFile, testInput, expectedOutput)); |
134 } | 135 } |
135 return FileVisitResult.CONTINUE; | 136 return FileVisitResult.CONTINUE; |
136 } | 137 } |
137 }); | 138 }); |
138 return foundCases; | 139 return foundCases; |
152 notifier.fireTestStarted(testCase.name); | 153 notifier.fireTestStarted(testCase.name); |
153 | 154 |
154 ByteArrayOutputStream out = new ByteArrayOutputStream(); | 155 ByteArrayOutputStream out = new ByteArrayOutputStream(); |
155 PrintStream printer = new PrintStream(out); | 156 PrintStream printer = new PrintStream(out); |
156 try { | 157 try { |
157 SLContext context = new SLContext(sourceManager, new BufferedReader(new StringReader(repeat(testCase.testInput, REPEATS))), printer); | 158 SLContext context = new SLContext(new BufferedReader(new StringReader(repeat(testCase.testInput, REPEATS))), printer); |
158 SLMain.run(context, testCase.source, null, REPEATS); | 159 final Source source = SourceFactory.fromText(readAllLines(testCase.path), testCase.sourceName); |
160 SLMain.run(context, source, null, REPEATS); | |
159 | 161 |
160 String actualOutput = new String(out.toByteArray()); | 162 String actualOutput = new String(out.toByteArray()); |
161 Assert.assertEquals(repeat(testCase.expectedOutput, REPEATS), actualOutput); | 163 Assert.assertEquals(repeat(testCase.expectedOutput, REPEATS), actualOutput); |
162 } catch (Throwable ex) { | 164 } catch (Throwable ex) { |
163 notifier.fireTestFailure(new Failure(testCase.name, ex)); | 165 notifier.fireTestFailure(new Failure(testCase.name, ex)); |