11package fi .helsinki .cs .tmc .cli .command ;
22
3+ import static fi .helsinki .cs .tmc .langs .domain .RunResult .Status .PASSED ;
4+
35import fi .helsinki .cs .tmc .cli .Application ;
46import fi .helsinki .cs .tmc .cli .command .core .AbstractCommand ;
57import fi .helsinki .cs .tmc .cli .command .core .Command ;
68import fi .helsinki .cs .tmc .cli .io .Color ;
79import fi .helsinki .cs .tmc .cli .io .Io ;
810import fi .helsinki .cs .tmc .cli .io .ResultPrinter ;
911import fi .helsinki .cs .tmc .cli .io .TmcCliProgressObserver ;
12+ import fi .helsinki .cs .tmc .cli .tmcstuff .CourseInfo ;
1013import fi .helsinki .cs .tmc .cli .tmcstuff .CourseInfoIo ;
1114import fi .helsinki .cs .tmc .cli .tmcstuff .Settings ;
1215import fi .helsinki .cs .tmc .cli .tmcstuff .WorkDir ;
2528import java .nio .file .Path ;
2629import java .util .List ;
2730
31+
2832@ Command (name = "test" , desc = "Run local exercise tests" )
2933public class RunTestsCommand extends AbstractCommand {
3034
@@ -58,13 +62,13 @@ public void run(CommandLine args, Io io) {
5862 return ;
5963 }
6064 }
61- String courseName = getCourseName (workDir );
6265 List <String > exerciseNames = workDir .getExerciseNames ();
6366
6467 if (exerciseNames .isEmpty ()) {
6568 io .println ("You have to be in a course directory to run tests" );
6669 return ;
6770 }
71+ CourseInfo info = CourseInfoIo .load (workDir .getConfigFile ());
6872
6973 // Local tests don't require login so make sure tmcCore is never null.
7074 app .createTmcCore (new Settings ());
@@ -90,16 +94,30 @@ public void run(CommandLine args, Io io) {
9094
9195 io .println (Color .colorString ("Testing: " + name , Color .AnsiColor .ANSI_YELLOW ));
9296 //name = name.replace("-", File.separator);
93- Exercise exercise = new Exercise (name , courseName );
97+ Exercise exercise = info .getExercise (name );
98+ // Exercise exercise = new Exercise(name, courseName);
9499
95100 // TmcCliProgressObserver progobs = new TmcCliProgressObserver(io);
96101 runResult = core .runTests (ProgressObserver .NULL_OBSERVER , exercise ).call ();
97102 // progobs.end(0);
98103
99- resultPrinter .printRunResult (runResult , isOnlyExercise , color1 , color2 );
104+ resultPrinter .printRunResult (runResult , exercise .isCompleted (),
105+ isOnlyExercise , color1 , color2 );
100106 total += runResult .testResults .size ();
101107 passed += ResultPrinter .passedTests (runResult .testResults );
108+ exercise .setAttempted (true );
109+ if (runResult .status == PASSED && !exercise .isCompleted ()) {
110+ // add exercise to locally tested exercises
111+ if (!info .getLocalCompletedExercises ().contains (exercise .getName ())) {
112+ info .getLocalCompletedExercises ().add (exercise .getName ());
113+ }
114+ } else {
115+ if (info .getLocalCompletedExercises ().contains (exercise .getName ())) {
116+ info .getLocalCompletedExercises ().remove (exercise .getName ());
117+ }
118+ }
102119 }
120+ CourseInfoIo .save (info , workDir .getConfigFile ());
103121 if (total > 0 && !isOnlyExercise ) {
104122 // Print a progress bar showing how the ratio of passed exercises
105123 // But only if more than one exercise was tested
@@ -115,15 +133,6 @@ public void run(CommandLine args, Io io) {
115133 }
116134 }
117135
118- private String getCourseName (WorkDir dirUtil ) {
119- Path courseDir = dirUtil .getCourseDirectory ();
120- try {
121- return courseDir .getName (courseDir .getNameCount () - 1 ).toString ();
122- } catch (Exception e ) {
123- }
124- return null ;
125- }
126-
127136 private String [] parseArgs (CommandLine args ) {
128137 this .showPassed = args .hasOption ("a" );
129138 this .showDetails = args .hasOption ("d" );
0 commit comments