tests: kdoc: improve comparison and output #56
+69
−16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I had to look at the kdoc test output for some patches recently and found
it to be essentially unusable for quickly resolving the warning. Its output
is a diff (not even unified context) format which includes every warning
that merely changed its line number. This results in a lot of messes, as
most warnings will have line numbers change when code is added, removed, or
rearranged.
In addition, the test can sometimes pass even when it should fail. In rare
cases where a patch remove more warnings that it adds, the end result will
be considered acceptable.
Rather than using the raw diff output, I think we can do much better. I
came up with the idea of using two files in parallel: the original file,
and one with line numbers removed. Diff the two stripped files to figure
out which lines changed, then use sed to extract the changed lines from the
original file.
To ensure the diff won't produce results if line numbers change, we sort
the output of kernel-doc first by the warning text, and then by the file
name without the line number. In addition, warnings of the form "... line:"
which reference a following source line are squashed to a single line.
The diff can then easily pick up which warnings are actually new. It also
allows the kdoc script to log how many warnings are removed (i.e. fixed) as
an added bonus.
One critical change that took a while to track down is that we need to use
regular pipes for the merge and sort, otherwise the sub-process might not
be finished before the next steps of the algorithm continue.
I'm also considering scrapping this diff-based approach and writing a
simple python program that takes the kernel-doc output and does its own
comparison instead of trying to implement this in shell. Suggestions
welcome for any other improvements.
Here's an example of the original output compared to the new output:
Vs...
The context description is also improved to include the new/removed count: