Skip to content
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

Do not add log output to quickfix list #561

Closed
wants to merge 1 commit into from

Conversation

mrnugget
Copy link
Contributor

@mrnugget mrnugget commented Oct 8, 2015

I ran into a problem where the output of log.Println was added to the quickfix window when some tests failed. Here is some example code the reproduce the issue:

// testing_example.go
package main

import (
    "fmt"
    "log"
)

func SayName() string {
    log.Println("log line")
    fmt.Println("fmt line!")
    return "wrong"
}

// testing_example_test.go
package main

import "testing"

func TestSayname(t *testing.T) {
    result := SayName()

    if result != "foobar" {
        t.Error("foobar")
    }
}

When the tests were run with :GoTest or :GoTest! the log.Println line was included in the quickfix list, which looked like this:

image

My guess was that the regex that's responsible for parsing the output was not meant to parse the log line, but only did so accidently.

So I changed the regex to only parse lines for filenames and linenumbers that begin with at least one whitespace (which log lines do not).

(See the commit message for more details)

What do you think? :)

Before this change a test that made a call to `log.Println` (or
`Printf`, etc.) resulted in the line printed by `log` to be added to the
quickfix window.

This output:

    === RUN TestSayname
    2015/10/08 13:48:45 log line
    --- FAIL: TestSayname (0.00s)
            testing_example_test.go:9: foobar
    FAIL
    exit status 1
    FAIL    github.com/mrnugget/testing_example     0.005s

would result in these two lines to be added to the quickfix window.

    2015/10/08 13:48:45 log line
            testing_example_test.go:9: foobar

The regex that was responsible for this was meant to only parse the
latter of these two lines, but it accidentally added the first line too.

This commit changes the regex to add lines that have _at least_ one
whitespace at the beginning, thus ignoring the log output.
@nowk
Copy link
Contributor

nowk commented Oct 8, 2015

Could this be something you enable or flag in? Log output can be very handy at times, as well as extremely annoying, particularly with the auto jump feature. But I feel this would be ideal as something one can opt in/out of...?

@mrnugget
Copy link
Contributor Author

mrnugget commented Oct 9, 2015

I'm sure it could be enabled. In go#Tool#ShowErrors there is this part:

" [...]
        elseif !empty(errors)
            " Preserve indented lines.
            " This comes up especially with multi-line test output.
            if match(line, '^\s') >= 0
                call add(errors, {"text": line})
            endif
        endif
" [...]

This could be modified to always add every line of text to the quickfix window. Which is exactly what happens if you use :make to compile a C program for example:

image

But these lines are not added with a linenumber and a filename. Just the text, which would be the correct thing to do. The way log output is currently parsed incorrectly is definitely a bug. The regex is meant to only parse filename.go:linenumber: text.

I'd say let's fix it first and then look at how to enable all output in the quickfix window.

@mrnugget
Copy link
Contributor Author

mrnugget commented Oct 9, 2015

I think that https://github.com/fatih/vim-go/pull/547/files is related to this issue, albeit it's triggered by building/running a Go program and not testing. But I think merging this change here would fix the problems in PR 547 too, with a much simpler solution.

@mrnugget
Copy link
Contributor Author

mrnugget commented Oct 9, 2015

Okay, I just realized that this PR would break the behaviour of :GoVet/:GoRun/:GoBuild since they output their errors without whitespace at the beginning of the line.

I think maybe the best approach would be to add a separate ShowTestErrors function that only parses test output (which is quite different than other output) and takes arguments to show the full output.

@mrnugget
Copy link
Contributor Author

So, just to clarify: do not merge this, since it breaks the other commands. I'll keep this open for now, so maybe we can discuss this problem. But, if it's the better approach, we can move the discussion to #547.

@fatih
Copy link
Owner

fatih commented Oct 18, 2015

Hi @mrnugget

The issue #547 issue is quite good. I've tested it with the example file on #287 and it works perfect. I'm closing this so we can focus on #547. Thanks

@fatih fatih closed this Oct 18, 2015
@mrnugget mrnugget deleted the ignore_log_quickfix branch October 23, 2015 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants