Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/instrument/SLInstrumentTestRunner.java @ 17135:ceb34d2d124e
Make fields and constructors protected to allow subclasses in different packages
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Tue, 16 Sep 2014 18:53:11 -0700 |
parents | 997899955e72 |
children | dc2e000bed40 |
rev | line source |
---|---|
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
1 /* |
16776
a24beb9c9993
SL/instrumentation: minor cleanups in sl.test.instrument
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16702
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
4 * |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
8 * |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
14 * |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
18 * |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
21 * questions. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
22 */ |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.sl.test.instrument; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
24 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
25 import java.io.*; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
26 import java.nio.charset.*; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
27 import java.nio.file.*; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
28 import java.nio.file.attribute.*; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
29 import java.util.*; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
30 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
31 import org.junit.*; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
32 import org.junit.internal.*; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
33 import org.junit.runner.*; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
34 import org.junit.runner.manipulation.*; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
35 import org.junit.runner.notification.*; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
36 import org.junit.runners.*; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
37 import org.junit.runners.model.*; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
38 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
39 import com.oracle.truffle.api.*; |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
40 import com.oracle.truffle.api.instrument.*; |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
41 import com.oracle.truffle.api.source.*; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
42 import com.oracle.truffle.sl.nodes.instrument.*; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
43 import com.oracle.truffle.sl.parser.*; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
44 import com.oracle.truffle.sl.runtime.*; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
45 import com.oracle.truffle.sl.test.instrument.SLInstrumentTestRunner.InstrumentTestCase; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
46 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
47 /** |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
48 * This class builds and executes the tests for instrumenting SL. Although much of this class is |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
49 * written with future automation in mind, at the moment the tests that are created are hard-coded |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
50 * according to the file name of the test. To be automated, an automatic way of generating both the |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
51 * node visitor and the node prober is necessary. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
52 * |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
53 * Testing is done via JUnit via comparing execution outputs with expected outputs. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
54 */ |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
55 public final class SLInstrumentTestRunner extends ParentRunner<InstrumentTestCase> { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
56 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
57 private static final String SOURCE_SUFFIX = ".sl"; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
58 private static final String INPUT_SUFFIX = ".input"; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
59 private static final String OUTPUT_SUFFIX = ".output"; |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
60 private static final String ASSIGNMENT_VALUE_SUFFIX = "_assnCount"; |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
61 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
62 private static final String LF = System.getProperty("line.separator"); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
63 private static SLContext slContext; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
64 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
65 static class InstrumentTestCase { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
66 protected final Description name; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
67 protected final Path path; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
68 protected final String baseName; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
69 protected final String sourceName; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
70 protected final String testInput; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
71 protected final String expectedOutput; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
72 protected String actualOutput; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
73 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
74 protected InstrumentTestCase(Class<?> testClass, String baseName, String sourceName, Path path, String testInput, String expectedOutput) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
75 this.name = Description.createTestDescription(testClass, baseName); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
76 this.baseName = baseName; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
77 this.sourceName = sourceName; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
78 this.path = path; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
79 this.testInput = testInput; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
80 this.expectedOutput = expectedOutput; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
81 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
82 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
83 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
84 private final List<InstrumentTestCase> testCases; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
85 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
86 public SLInstrumentTestRunner(Class<?> testClass) throws InitializationError { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
87 super(testClass); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
88 try { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
89 testCases = createTests(testClass); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
90 } catch (IOException e) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
91 throw new InitializationError(e); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
92 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
93 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
94 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
95 @Override |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
96 protected List<InstrumentTestCase> getChildren() { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
97 return testCases; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
98 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
99 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
100 @Override |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
101 protected Description describeChild(InstrumentTestCase child) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
102 return child.name; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
103 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
104 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
105 /** |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
106 * Tests are created based on the files that exist in the directory specified in the passed in |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
107 * annotation. Each test must have a source file and an expected output file. Optionally, each |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
108 * test can also include an input file. Source files have an ".sl" extension. Expected output |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
109 * have a ".output" extension. Input files have an ".input" extension. All these files must |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
110 * share the same base name to be correctly grouped. For example: "test1_assnCount.sl", |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
111 * "test1_assnCount.output" and "test1_assnCount.input" would all be used to create a single |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
112 * test called "test1_assnCount". |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
113 * |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
114 * This method iterates over the files in the directory and creates a new InstrumentTestCase for |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
115 * each group of related files. Each file is also expected to end with an identified at the end |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
116 * of the base name to indicate what visitor needs to be attached. Currently, visitors are hard |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
117 * coded to work on specific lines, so the code here is not currently generalizable. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
118 * |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
119 * @param c The annotation containing the directory with tests |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
120 * @return A list of {@link InstrumentTestCase}s to run. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
121 * @throws IOException If the directory is invalid. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
122 * @throws InitializationError If no directory is provided. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
123 * |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
124 * @see #runChild(InstrumentTestCase, RunNotifier) |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
125 */ |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
126 protected static List<InstrumentTestCase> createTests(final Class<?> c) throws IOException, InitializationError { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
127 SLInstrumentTestSuite suite = c.getAnnotation(SLInstrumentTestSuite.class); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
128 if (suite == null) { |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
129 throw new InitializationError(String.format("@%s annotation required on class '%s' to run with '%s'.", SLInstrumentTestSuite.class.getSimpleName(), c.getName(), |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
130 SLInstrumentTestRunner.class.getSimpleName())); |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
131 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
132 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
133 String[] paths = suite.value(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
134 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
135 Path root = null; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
136 for (String path : paths) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
137 root = FileSystems.getDefault().getPath(path); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
138 if (Files.exists(root)) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
139 break; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
140 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
141 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
142 if (root == null && paths.length > 0) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
143 throw new FileNotFoundException(paths[0]); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
144 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
145 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
146 final Path rootPath = root; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
147 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
148 final List<InstrumentTestCase> testCases = new ArrayList<>(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
149 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
150 // Scaffolding in place for future automation |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
151 Files.walkFileTree(rootPath, new SimpleFileVisitor<Path>() { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
152 @Override |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
153 public FileVisitResult visitFile(Path sourceFile, BasicFileAttributes attrs) throws IOException { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
154 String sourceName = sourceFile.getFileName().toString(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
155 if (sourceName.endsWith(SOURCE_SUFFIX)) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
156 String baseName = sourceName.substring(0, sourceName.length() - SOURCE_SUFFIX.length()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
157 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
158 Path inputFile = sourceFile.resolveSibling(baseName + INPUT_SUFFIX); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
159 String testInput = ""; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
160 if (Files.exists(inputFile)) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
161 testInput = readAllLines(inputFile); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
162 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
163 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
164 Path outputFile = sourceFile.resolveSibling(baseName + OUTPUT_SUFFIX); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
165 String expectedOutput = ""; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
166 if (Files.exists(outputFile)) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
167 expectedOutput = readAllLines(outputFile); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
168 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
169 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
170 testCases.add(new InstrumentTestCase(c, baseName, sourceName, sourceFile, testInput, expectedOutput)); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
171 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
172 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
173 return FileVisitResult.CONTINUE; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
174 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
175 }); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
176 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
177 return testCases; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
178 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
179 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
180 private static String readAllLines(Path file) throws IOException { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
181 // fix line feeds for non unix os |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
182 StringBuilder outFile = new StringBuilder(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
183 for (String line : Files.readAllLines(file, Charset.defaultCharset())) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
184 outFile.append(line).append(LF); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
185 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
186 return outFile.toString(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
187 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
188 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
189 /** |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
190 * Executes the passed in test case. Instrumentation is added according to the name of the file |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
191 * as explained in {@link #createTests(Class)}. Note that this code is not generalizable. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
192 */ |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
193 @Override |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
194 protected void runChild(InstrumentTestCase testCase, RunNotifier notifier) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
195 // TODO Current tests are hard-coded, automate this eventually |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
196 notifier.fireTestStarted(testCase.name); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
197 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
198 ByteArrayOutputStream out = new ByteArrayOutputStream(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
199 PrintStream printer = new PrintStream(out); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
200 try { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
201 // We use the name of the file to determine what visitor to attach to it. |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
202 if (testCase.baseName.endsWith(ASSIGNMENT_VALUE_SUFFIX)) { |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
203 // Set up the execution context for Simple and register our two listeners |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
204 slContext = new SLContext(new BufferedReader(new StringReader(testCase.testInput)), printer); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
205 |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
206 final Source source = Source.fromText(readAllLines(testCase.path), testCase.sourceName); |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
207 Parser.parseSL(slContext, source); |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
208 List<SLFunction> functionList = slContext.getFunctionRegistry().getFunctions(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
209 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
210 // Since only functions can be global in SL, this guarantees that we instrument |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
211 // everything of interest. Parsing must occur before accepting the visitors since |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
212 // the visitor which creates our instrumentation points expects a complete AST. |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
213 |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
214 for (SLFunction function : functionList) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
215 RootCallTarget rootCallTarget = function.getCallTarget(); |
16958
997899955e72
Instrumentation: removed ExecutionContext parameter from probe method in Instrumentable
David Piorkowski <david.piorkowski@oracle.com>
parents:
16880
diff
changeset
|
216 rootCallTarget.getRootNode().accept(new SLInstrumenter()); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
217 } |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
218 |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
219 // We iterate over all tags the SLInsturmenter tagged as assignments and attach our |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
220 // test instrument to those. |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
221 for (Probe probe : slContext.findProbesTaggedAs(StandardSyntaxTag.ASSIGNMENT)) { |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
222 if (probe.isTaggedAs(StandardSyntaxTag.ASSIGNMENT)) { |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
223 probe.addInstrument(new SLPrintAssigmentValueInstrument(printer)); |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
224 } |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
225 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
226 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
227 SLFunction main = slContext.getFunctionRegistry().lookup("main"); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
228 main.getCallTarget().call(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
229 } else { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
230 notifier.fireTestFailure(new Failure(testCase.name, new UnsupportedOperationException("No instrumentation found."))); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
231 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
232 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
233 String actualOutput = new String(out.toByteArray()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
234 Assert.assertEquals(testCase.expectedOutput, actualOutput); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
235 } catch (Throwable ex) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
236 notifier.fireTestFailure(new Failure(testCase.name, ex)); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
237 } finally { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
238 notifier.fireTestFinished(testCase.name); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
239 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
240 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
241 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
242 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
243 public static void runInMain(Class<?> testClass, String[] args) throws InitializationError, NoTestsRemainException { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
244 JUnitCore core = new JUnitCore(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
245 core.addListener(new TextListener(System.out)); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
246 SLInstrumentTestRunner suite = new SLInstrumentTestRunner(testClass); |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
247 if (args.length > 0) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
248 suite.filter(new NameFilter(args[0])); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
249 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
250 Result r = core.run(suite); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
251 if (!r.wasSuccessful()) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
252 System.exit(1); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
253 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
254 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
255 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
256 private static final class NameFilter extends Filter { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
257 private final String pattern; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
258 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
259 private NameFilter(String pattern) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
260 this.pattern = pattern.toLowerCase(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
261 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
262 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
263 @Override |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
264 public boolean shouldRun(Description description) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
265 return description.getMethodName().toLowerCase().contains(pattern); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
266 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
267 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
268 @Override |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
269 public String describe() { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
270 return "Filter contains " + pattern; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
271 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
272 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
273 } |