Skip to content

Commit 50bdbb6

Browse files
committed
This revision attempts to make code coverage work within DrJava. It
includes more logging and for some reason blows up later than the previous code even though the only intended changes were additional logging statements. Code coverage fails because loading an instrumented class generates an "initalizationError". I don't yet know why. I updated JUnit to the latest build and tried adding jacocoagent.jar to the drjava.jar but it did not help. The following files were modified. modified: lib/buildlib/junit.jar modified: src/edu/rice/cs/drjava/CommandLineTest.java modified: src/edu/rice/cs/drjava/model/junit/JUnitTestManager.java
1 parent 057aa60 commit 50bdbb6

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

drjava/lib/buildlib/junit.jar

129 KB
Binary file not shown.

drjava/src/edu/rice/cs/drjava/CommandLineTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@
5050
import edu.rice.cs.util.StringOps;
5151
import edu.rice.cs.util.swing.Utilities;
5252

53-
/** * Tests opening/creating files specified as command line arguments.
54-
* @version $Id$
55-
*/
53+
/** Tests opening/creating files specified as command line arguments.
54+
* @version $Id$
55+
*/
5656
public final class CommandLineTest extends DrJavaTestCase {
5757
/** File separator, i.e. '/' or '\\'. */
5858
private static final char FS = File.separatorChar;

drjava/src/edu/rice/cs/drjava/model/junit/JUnitTestManager.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public JUnitResultTuple getLastResult() {
135135
public List<String> findTestClasses(final List<String> classNames,
136136
final List<File> files, CoverageMetadata coverageMetadata) {
137137

138-
_log.log("findTestClasses(" + classNames + ", " + files + ") called");
138+
_log.log("findTestClasses(" + classNames + ", " + files + ", " + coverageMetadata + ") called");
139139
boolean doCoverage = coverageMetadata.getFlag();
140140

141141
// Set up the loader
@@ -154,7 +154,7 @@ public List<String> findTestClasses(final List<String> classNames,
154154

155155
// The Instrumenter creates a modified version of our test target class
156156
// that contains additional probes for execution data recording:
157-
for (int i = 0 ; i< files.size() ; i++) {
157+
for (int i = 0 ; i < files.size() ; i++) {
158158

159159
// Instrument the i-th file
160160
try {
@@ -174,7 +174,10 @@ public List<String> findTestClasses(final List<String> classNames,
174174

175175
loader = new MemoryClassLoader();
176176
for (int i = 0; i < classNames.size(); i++) {
177-
((MemoryClassLoader)loader).addDefinition(classNames.get(i), instrumenteds.get(i));
177+
String name = classNames.get(i);
178+
byte[] code = instrumenteds.get(i);
179+
_log.log("Loading class file for '" + name + "' consisting of " + code.length + " bytes");
180+
((MemoryClassLoader)loader).addDefinition(classNames.get(i), instrumenteds.get(i));
178181
}
179182

180183
try {
@@ -184,9 +187,6 @@ public List<String> findTestClasses(final List<String> classNames,
184187
}
185188
}
186189

187-
// debug.logStart(new String[]{"classNames", "files"}, classNames, files);
188-
_log.log("findTestClasses(" + classNames + ", " + files + ")");
189-
190190
if (_testClassNames != null && ! _testClassNames.isEmpty())
191191
throw new IllegalStateException("Test suite is still pending!");
192192

@@ -200,6 +200,7 @@ public List<String> findTestClasses(final List<String> classNames,
200200
String cName = pair.first();
201201
try {
202202
Class<?> possibleTest = _testRunner.loadPossibleTest(cName);
203+
_log.log("Exploring possibleTest " + possibleTest);
203204
if (_isJUnitTest(possibleTest)) {
204205
_testClassNames.add(cName);
205206
_testFiles.add(pair.second());
@@ -336,11 +337,19 @@ private void _reset() {
336337
* @return true iff the given class is an instance of junit.framework.Test
337338
*/
338339
private boolean _isJUnitTest(Class<?> c) {
339-
340-
boolean result = (Test.class.isAssignableFrom(c) && !Modifier.isAbstract(c.getModifiers()) && !Modifier.isInterface(c.getModifiers()) ||
341-
(new JUnit4TestAdapter(c).getTests().size()>0)) && !new JUnit4TestAdapter(c).getTests().get(0).toString().contains("initializationError")
342-
; //had to add specific check for initializationError. Is there a better way of checking if a class contains a test?
343-
debug.logValues(new String[]{"c", "isJUnitTest(c)"}, c, result);
340+
boolean isAssignable = Test.class.isAssignableFrom(c);
341+
boolean isAbstract = Modifier.isAbstract(c.getModifiers());
342+
boolean isInterface = Modifier.isInterface(c.getModifiers());
343+
JUnit4TestAdapter a = new JUnit4TestAdapter(c);
344+
boolean isJUnit4Test = (a.getTests().size() > 0) && ! a.getTests().get(0).toString().contains("initializationError");
345+
//had to add specific check for initializationError. Is there a better way of checking if a class contains a test?
346+
347+
_log.log("isAssignable = " + isAssignable + " isAbstract = " + isAbstract + " isInterface = " + isInterface +
348+
" isJUnit4Test = " + isJUnit4Test);
349+
350+
boolean result = (isAssignable && !isAbstract && !isInterface) || isJUnit4Test;
351+
352+
_log.log("isJUnitTest(" + c + ") = " + result);
344353
return result;
345354
}
346355

0 commit comments

Comments
 (0)