Show test results in test results tool window and get multiline test output only...
authorValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Thu, 9 Jun 2016 11:37:41 +0000 (14:37 +0300)
committerValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Thu, 9 Jun 2016 18:17:16 +0000 (21:17 +0300)
python/educational-core/student/src/com/jetbrains/edu/learning/checker/StudyCheckTask.java
python/educational-core/student/src/com/jetbrains/edu/learning/checker/StudyCheckUtils.java
python/educational-core/student/src/com/jetbrains/edu/learning/checker/StudySmartChecker.java
python/educational-core/student/src/com/jetbrains/edu/learning/checker/StudyTestsOutputParser.java
python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyCheckAction.java

index fc6d39649c6b60c025133cdbf20775e0f6448721..dccc94d3ff7782fc4156c2bbc19c592b0594b3a5 100644 (file)
@@ -106,19 +106,22 @@ public class StudyCheckTask extends com.intellij.openapi.progress.Task.Backgroun
         () -> StudyCheckUtils.showTestResultPopUp("Check cancelled", MessageType.WARNING.getPopupBackground(), myProject));
     }
 
-
-    final StudyTestsOutputParser.TestsOutput testsOutput = StudyTestsOutputParser.getTestsOutput(output);
-    String stderr = output.getStderr();
-    if (!stderr.isEmpty()) {
-      ApplicationManager.getApplication().invokeLater(() ->
-                                                        StudyCheckUtils.showTestResultPopUp("Failed to launch checking",
-                                                                                            MessageType.WARNING.getPopupBackground(),
-                                                                                            myProject));
-      //log error output of tests
-      LOG.info("#educational " + stderr);
-      return null;
+    final Course course = StudyTaskManager.getInstance(myProject).getCourse();
+    if (course != null) {
+      final StudyTestsOutputParser.TestsOutput testsOutput = StudyTestsOutputParser.getTestsOutput(output, course.isAdaptive());
+      String stderr = output.getStderr();
+      if (!stderr.isEmpty()) {
+        ApplicationManager.getApplication().invokeLater(() ->
+                                                          StudyCheckUtils.showTestResultPopUp("Failed to launch checking",
+                                                                                              MessageType.WARNING.getPopupBackground(),
+                                                                                              myProject));
+        //log error output of tests
+        LOG.info("#educational " + stderr);
+        return null;
+      }
+      return testsOutput;
     }
-    return testsOutput;
+    return null;
   }
 
   private void checkForAdaptiveCourse(ProgressIndicator indicator) {
@@ -154,15 +157,40 @@ public class StudyCheckTask extends com.intellij.openapi.progress.Task.Backgroun
 
   protected void onTaskFailed(String message) {
     myTaskManger.setStatus(myTask, StudyStatus.Failed);
-    ApplicationManager.getApplication().invokeLater(
-      () -> StudyCheckUtils.showTestResults(myProject, message, false));
+    final Course course = StudyTaskManager.getInstance(myProject).getCourse();
+
+    if (course != null) {
+      if (course.isAdaptive()) {
+        ApplicationManager.getApplication().invokeLater(
+          () -> {
+            StudyCheckUtils.showTestResultPopUp("Failed", MessageType.ERROR.getPopupBackground(), myProject);
+            StudyCheckUtils.showTestResultsToolWindow(myProject, message, false);
+          });
+      }
+      else {
+        ApplicationManager.getApplication()
+          .invokeLater(() -> StudyCheckUtils.showTestResultPopUp(message, MessageType.ERROR.getPopupBackground(), myProject));
+      }
+    }
   }
 
   protected void onTaskSolved(String message) {
     myTaskManger.setStatus(myTask, StudyStatus.Solved);
+    final Course course = StudyTaskManager.getInstance(myProject).getCourse();
 
-    ApplicationManager.getApplication().invokeLater(
-      () -> StudyCheckUtils.showTestResults(myProject, message, true));
+    if (course != null) {
+      if (course.isAdaptive()) {
+        ApplicationManager.getApplication().invokeLater(
+          () -> {
+            StudyCheckUtils.showTestResultPopUp("Congratulations!", MessageType.ERROR.getPopupBackground(), myProject);
+            StudyCheckUtils.showTestResultsToolWindow(myProject, message, true);
+          });
+      }
+      else {
+        ApplicationManager.getApplication()
+          .invokeLater(() -> StudyCheckUtils.showTestResultPopUp(message, MessageType.INFO.getPopupBackground(), myProject));
+      }
+    }
   }
 
   private void runAfterTaskCheckedActions() {
index 38f6e8f91162ca64232618f3ce0a952737ba000b..ce58a0e61261037b612d58f7fed583afaac9fed3 100644 (file)
@@ -196,7 +196,7 @@ public class StudyCheckUtils {
     }
   }
 
-  public static void showTestResults(@NotNull final Project project, @NotNull final String message, boolean solved) {
+  public static void showTestResultsToolWindow(@NotNull final Project project, @NotNull final String message, boolean solved) {
     final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
     ToolWindow window = toolWindowManager.getToolWindow("Test Results");
     if (window == null) {
index 14870203abac9279d8565aa9cb28ebc6d84c0c1a..b1bb10498731bcd44d64bd160eb7d9c92346e8c5 100644 (file)
@@ -14,6 +14,7 @@ import com.jetbrains.edu.learning.core.EduDocumentListener;
 import com.jetbrains.edu.learning.core.EduNames;
 import com.jetbrains.edu.learning.core.EduUtils;
 import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
+import com.jetbrains.edu.learning.courseFormat.Course;
 import com.jetbrains.edu.learning.courseFormat.StudyStatus;
 import com.jetbrains.edu.learning.courseFormat.TaskFile;
 import com.jetbrains.edu.learning.StudyTaskManager;
@@ -67,14 +68,17 @@ public class StudySmartChecker {
         Process smartTestProcess = testRunner.createCheckProcess(project, windowCopy.getPath());
         final CapturingProcessHandler handler = new CapturingProcessHandler(smartTestProcess, null, windowCopy.getPath());
         final ProcessOutput output = handler.runProcess();
-        boolean res = StudyTestsOutputParser.getTestsOutput(output).isSuccess();
-        StudyTaskManager.getInstance(project).setStatus(userAnswerPlaceholder, res ? StudyStatus.Solved : StudyStatus.Failed);
-        StudyUtils.deleteFile(windowCopy);
-        if (fileWindows != null) {
-          StudyUtils.deleteFile(fileWindows);
-        }
-        if (!resourceFile.delete()) {
-          LOG.error("failed to delete", resourceFile.getPath());
+        final Course course = StudyTaskManager.getInstance(project).getCourse();
+        if (course != null) {
+          boolean res = StudyTestsOutputParser.getTestsOutput(output, course.isAdaptive()).isSuccess();
+          StudyTaskManager.getInstance(project).setStatus(userAnswerPlaceholder, res ? StudyStatus.Solved : StudyStatus.Failed);
+          StudyUtils.deleteFile(windowCopy);
+          if (fileWindows != null) {
+            StudyUtils.deleteFile(fileWindows);
+          }
+          if (!resourceFile.delete()) {
+            LOG.error("failed to delete", resourceFile.getPath());
+          }
         }
       }
     }
index fc21b40bc5791d52aabde47dbcc3fcc600b752d5..90cf27d4c9584501a77d57a0bfe4e67fe88f5cc5 100644 (file)
@@ -31,7 +31,7 @@ public class StudyTestsOutputParser {
   }
 
   @NotNull
-  public static TestsOutput getTestsOutput(@NotNull final ProcessOutput processOutput) {
+  public static TestsOutput getTestsOutput(@NotNull final ProcessOutput processOutput, final boolean isAdaptive) {
     String congratulations = CONGRATULATIONS;
     final List<String> lines = processOutput.getStdoutLines();
     for (int i = 0; i < lines.size(); i++) {
@@ -46,18 +46,23 @@ public class StudyTestsOutputParser {
         }
 
         if (line.contains(TEST_FAILED)) {
-          final StringBuilder builder = new StringBuilder(line.substring(line.indexOf(TEST_FAILED) + TEST_FAILED.length()) + "\n");
-          for (int j = i + 1; j < lines.size(); j++) {
-            final String failedTextLine = lines.get(j);
-            if (!failedTextLine.contains(STUDY_PREFIX) || !failedTextLine.contains(CONGRATS_MESSAGE)) {
-              builder.append(failedTextLine);
-              builder.append("\n");
-            }
-            else {
-              break;
-            }
+          if (!isAdaptive) {
+            return new TestsOutput(false, line.substring(line.indexOf(TEST_FAILED) + TEST_FAILED.length()));
           }
-          return new TestsOutput(false, builder.toString());
+          else {
+            final StringBuilder builder = new StringBuilder(line.substring(line.indexOf(TEST_FAILED) + TEST_FAILED.length()) + "\n");
+            for (int j = i + 1; j < lines.size(); j++) {
+              final String failedTextLine = lines.get(j);
+              if (!failedTextLine.contains(STUDY_PREFIX) || !failedTextLine.contains(CONGRATS_MESSAGE)) {
+                builder.append(failedTextLine);
+                builder.append("\n");
+              }
+              else {
+                break;
+              }
+            }
+            return new TestsOutput(false, builder.toString());
+          }          
         }
       }
     }
index 0f5ab396df3f5f5e01c5bc20ae3ca12ed7707afd..14aac4c80d4ef679d4a6a0676cb46089e7ba829a 100644 (file)
@@ -7,6 +7,7 @@ import com.intellij.openapi.command.CommandProcessor;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.progress.ProgressManager;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.MessageType;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.wm.IdeFocusManager;
 import com.jetbrains.edu.learning.actions.StudyCheckAction;
@@ -14,7 +15,6 @@ import com.jetbrains.edu.learning.actions.StudyRunAction;
 import com.jetbrains.edu.learning.checker.StudyCheckTask;
 import com.jetbrains.edu.learning.checker.StudyCheckUtils;
 import com.jetbrains.edu.learning.checker.StudyTestRunner;
-import com.jetbrains.edu.learning.checker.StudyTestsOutputParser;
 import com.jetbrains.edu.learning.core.EduNames;
 import com.jetbrains.edu.learning.courseFormat.Course;
 import com.jetbrains.edu.learning.courseFormat.StudyStatus;
@@ -113,7 +113,16 @@ public class PyStudyCheckAction extends StudyCheckAction {
           }
           final StudyToolWindow toolWindow = StudyUtils.getStudyToolWindow(project);
           if (toolWindow != null) {
-            StudyCheckUtils.showTestResults(project, message, false);
+            final Course course = StudyTaskManager.getInstance(project).getCourse();
+            if (course != null) {
+              if (course.isAdaptive()) {
+                StudyCheckUtils.showTestResultPopUp("Failed", MessageType.ERROR.getPopupBackground(), project);
+                StudyCheckUtils.showTestResultsToolWindow(project, message, false);
+              }
+              else {
+                StudyCheckUtils.showTestResultPopUp(message, MessageType.ERROR.getPopupBackground(), project);
+              }
+            }
             StudyCheckUtils.navigateToFailedPlaceholder(myStudyState, myTask, myTaskDir, project);
           }
         });