- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.6k
          Output diff of expected and actual values in ConsoleLauncher
          #4017
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 15 commits
e0d2849
              bc1b464
              2fa9a8e
              50552b4
              e8d11bd
              7b4088d
              bb29695
              2c27b53
              af16685
              3d73d1e
              c8a7b95
              53d884c
              26bcaa4
              3248752
              04f789a
              983e090
              eef49f1
              bcd0608
              cc69bfb
              705b4cf
              2383f3e
              82f723a
              536e9c7
              f44f929
              eef975b
              de00ade
              a3f8f25
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Copyright 2015-2024 the original author or authors. | ||
| * | ||
| * All rights reserved. This program and the accompanying materials are | ||
| * made available under the terms of the Eclipse Public License v2.0 which | ||
| * accompanies this distribution and is available at | ||
| * | ||
| * https://www.eclipse.org/legal/epl-v20.html | ||
| */ | ||
|  | ||
| package org.junit.platform.console.tasks; | ||
|  | ||
| import java.io.PrintWriter; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|  | ||
| import com.github.difflib.text.DiffRow; | ||
| import com.github.difflib.text.DiffRowGenerator; | ||
|  | ||
| /** | ||
| * class provide access to printDiff function | ||
| */ | ||
| class DiffPrinter { | ||
| //print the difference of two print to out | ||
| static void printDiff(PrintWriter out, String expected, String actual) { | ||
| DiffRowGenerator generator = DiffRowGenerator.create().showInlineDiffs(true).inlineDiffByWord(true).oldTag( | ||
|         
                  XJ114514 marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| f -> "~").newTag(f -> "**").build(); | ||
|         
                  XJ114514 marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| List<DiffRow> rows = generator.generateDiffRows(Arrays.asList(expected), Arrays.asList(actual)); | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we have to split the  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What the difference is if we split them into lines? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure. I haven't used this library before and I was just curious why it expects lists of Strings. Do you know the reason? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know the details but all their methods use  | ||
| out.printf("\nPlease put the diff result below into a online markdown editor to see markdown effect: \n"); | ||
|         
                  XJ114514 marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| for (DiffRow row : rows) { | ||
|         
                  XJ114514 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| out.printf(" | %s | %s | \n", row.getOldLine(), row.getNewLine()); | ||
|         
                  XJ114514 marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be done in place where we print the exceptions (as it is in #3397). Otherwise, it would be difficult to find the test that belongs to the diff in case of multiple failing tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which part do you wish to change? The first print happens in
DefaultLaucherand the second happens inMutableTestExecutionSummary. Both are injunit-platform-lauchermodule. Changes will affect all Junit API output I believe?I can try to work on it over the weekend if you wish.
At the same time, can you help to find why the package documentation test case fails (Test cases can not find
diff packageonce I add it to the module-info.java for documentation)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to make sure that the diff is printed if a details mode other than
Details.NONE,Details.SUMMARY, orDetails.TREEis used. We should be able to extract the diff-printing code to a separate class and call it fromMutableTestExecutionSummary, and the other listeners (FlatPrintingListeneretc.).Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The solutions I can think of:
junit-platform-commons...util.StringUtilsFlatPrintingListener,TreePrintingListener,VerboseTreePrintingListenerandMutableTestExecutionSummaryI will start to work on it if the solution looks right for you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should stay in junit-platform-console. Please create a separate
DiffPrinterclass or similar.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DiffPrinterclass has been added.FlatPrintingListenerandVerboseTreePrintingListener