4848import java .util .Map ;
4949import java .util .ArrayList ;
5050
51+ import edu .rice .cs .drjava .model .coverage .*;
52+ import edu .rice .cs .drjava .model .compiler .LanguageLevelStackTraceMapper ;
5153import edu .rice .cs .util .Log ;
54+ import edu .rice .cs .util .UnexpectedException ;
5255import edu .rice .cs .util .classloader .ClassFileError ;
5356import edu .rice .cs .plt .io .IOUtil ;
5457import edu .rice .cs .plt .lambda .Lambda ;
6164import static edu .rice .cs .plt .debug .DebugUtil .debug ;
6265import static edu .rice .cs .plt .debug .DebugUtil .error ;
6366
64- import edu .rice .cs .drjava .model .compiler .LanguageLevelStackTraceMapper ;
65-
6667import org .jacoco .core .analysis .Analyzer ;
6768import org .jacoco .core .analysis .CoverageBuilder ;
6869import org .jacoco .core .analysis .IBundleCoverage ;
7273import org .jacoco .core .runtime .IRuntime ;
7374import org .jacoco .core .runtime .LoggerRuntime ;
7475import org .jacoco .core .runtime .RuntimeData ;
75- import edu . rice . cs . drjava . model . coverage .*;
76+
7677
7778import edu .rice .cs .util .UnexpectedException ;
7879import edu .rice .cs .util .swing .Utilities ;
@@ -112,9 +113,9 @@ public class JUnitTestManager {
112113 private JUnitResultTuple lastResult = new JUnitResultTuple (false , null );
113114
114115 /** Standard constructor
115- * @param jmc a JUnitModelCallback
116- * @param loaderFactory factory to create class loaders
117- */
116+ * @param jmc a JUnitModelCallback
117+ * @param loaderFactory factory to create class loaders
118+ */
118119 public JUnitTestManager (JUnitModelCallback jmc , Lambda <ClassLoader , ClassLoader > loaderFactory ) {
119120 _jmc = jmc ;
120121 _loaderFactory = loaderFactory ;
@@ -172,24 +173,27 @@ public List<String> findTestClasses(final List<String> classNames,
172173 }
173174 }
174175
175- loader = new MemoryClassLoader ();
176+ loader = new MemoryClassLoader (JUnitTestManager . class . getClassLoader () );
176177 for (int i = 0 ; i < classNames .size (); i ++) {
177178 String name = classNames .get (i );
178179 byte [] code = instrumenteds .get (i );
179180 _log .log ("Loading class file for '" + name + "' consisting of " + code .length + " bytes" );
180181 ((MemoryClassLoader )loader ).addDefinition (classNames .get (i ), instrumenteds .get (i ));
181182 }
182183
184+ _log .log ("Instrumented class files defined in MemoryClassLoader" );
183185 try {
184186 this .runtime .startup (myData );
185187 } catch (Exception e ) {
188+ _log .log ("In code coverage startup, throwing wrapped exception " + e );
186189 throw new UnexpectedException (e );
187190 }
188191 }
189192
190193 if (_testClassNames != null && ! _testClassNames .isEmpty ())
191194 throw new IllegalStateException ("Test suite is still pending!" );
192195
196+ _log .log ("Preparing to run test cases" );
193197 _testRunner = makeRunner (loader );
194198
195199 _testClassNames = new ArrayList <String >();
@@ -204,7 +208,9 @@ public List<String> findTestClasses(final List<String> classNames,
204208 if (_isJUnitTest (possibleTest )) {
205209 _testClassNames .add (cName );
206210 _testFiles .add (pair .second ());
207- _suite .addTest (new JUnit4TestAdapter (possibleTest ));
211+ Test test = new JUnit4TestAdapter (possibleTest );
212+ _suite .addTest (test );
213+ _log .log ("Adding test " + test + " to test suite" );
208214 }
209215 }
210216 catch (ClassNotFoundException e ) { error .log (e ); }
@@ -239,7 +245,7 @@ public List<String> findTestClasses(final List<String> classNames,
239245// Utilities.show("runTestSuite() in SlaveJVM called");
240246
241247 try {
242- // System.err.println ("Calling _testRunner.runSuite(... )");
248+ _log . log ("Calling _testRunner.runSuite(" + _suite + " )" );
243249 TestResult result = _testRunner .runSuite (_suite );
244250
245251 JUnitError [] errors = new JUnitError [result .errorCount () + result .failureCount ()];
@@ -340,7 +346,8 @@ private boolean _isJUnitTest(Class<?> c) {
340346 boolean isAssignable = Test .class .isAssignableFrom (c );
341347 boolean isAbstract = Modifier .isAbstract (c .getModifiers ());
342348 boolean isInterface = Modifier .isInterface (c .getModifiers ());
343- JUnit4TestAdapter a = new JUnit4TestAdapter (c );
349+ JUnit4TestAdapter a = new JUnit4TestAdapter (c );
350+ _log .log ("a.getTests() = " + a .getTests ());
344351 boolean isJUnit4Test = (a .getTests ().size () > 0 ) && ! a .getTests ().get (0 ).toString ().contains ("initializationError" );
345352 //had to add specific check for initializationError. Is there a better way of checking if a class contains a test?
346353
@@ -494,10 +501,10 @@ private JUnitError _makeJUnitError(TestFailure failure, List<String> classNames,
494501 }
495502
496503 /** Parses the line number out of the stack trace in the given class name.
497- * @param sw stack trace
498- * @param classname class in which stack trace was generated
499- * @return the line number
500- */
504+ * @param sw stack trace
505+ * @param classname class in which stack trace was generated
506+ * @return the line number
507+ */
501508 private int _lineNumber (String sw , String classname ) {
502509 // TODO: use stack trace elements to find line number
503510 int lineNum ;
@@ -520,8 +527,8 @@ private int _lineNumber(String sw, String classname) {
520527 }
521528
522529 /** @param current template for the runner's class loader
523- * @return a fresh JUnitTestRunner with its own class loader instance.
524- */
530+ * @return a fresh JUnitTestRunner with its own class loader instance.
531+ */
525532 private JUnitTestRunner makeRunner (ClassLoader current ) {
526533 return new JUnitTestRunner (_jmc , _loaderFactory .value (current ));
527534 }
0 commit comments