gotestfmt icon indicating copy to clipboard operation
gotestfmt copied to clipboard

Fix lines starting with ? being incorrectly interpreted

Open adombeck opened this issue 11 months ago • 1 comments

Please describe the change you are making

Lines starting with ? are interpreted as a package being skipped:

https://github.com/GoTestTools/gotestfmt/blob/4c97682ab858d6bbd26fc020e255cb339c9c8119/tokenizer/tokenizer.go#L183-L188

If a test prints a line that matches this pattern, then that output is incorrectly interpreted as a test being skipped and is therefore printed like this instead of hiding it (yes, the test does actually print a lot of question marks):

image

Looking at the JSON output produced by go test for packages being skipped:

{
  "Time": "2024-11-27T15:44:59.055963303+01:00",
  "Action": "output",
  "Package": "github.com/ubuntu/authd/.scratch/reproduce-gotestfmt-bug/bar",
  "Output": "?   \tgithub.com/ubuntu/authd/.scratch/reproduce-gotestfmt-bug/bar\t[no test files]\n"
}

and the JSON output of a test that prints a line starting with ?:

{
  "Time": "2024-11-27T15:44:59.137559943+01:00",
  "Action": "output",
  "Package": "github.com/ubuntu/authd/.scratch/reproduce-gotestfmt-bug/foo",
  "Test": "TestFoo",
  "Output": "?  foo bar\n"
}

we see that we can distinguish between these two cases on the basis of the Test field.

So this PR only interprets lines starting with ? as a package being skipped when it's not output from a test, i.e. its JSON line doesn't have a Test field. There was no functionality yet to encode such a condition, so this PR adds a precondition function to the stateChange struct.

Your code will be released under the Unlicense into the public domain for everyone to use for any purpose. Are you in the position, and are you willing to release your code under this license?

yes

adombeck avatar Jan 06 '25 14:01 adombeck

ping?

3v1n0 avatar Jan 07 '25 16:01 3v1n0