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

testing: external test code not compiled or run if contains no tests #8219

Closed
rogpeppe opened this issue Jun 16, 2014 · 2 comments

Comments

Projects
None yet
5 participants
@rogpeppe
Copy link
Contributor

commented Jun 16, 2014

To reproduce, create the following three files:

testit.go

    package testit

extern_test.go:

    package testit_test

    import (
        "code.google.com/p/rog-go/testit"
    )

    func init() {
        testit.Register()
        unused
    }

intern_test.go:

    package testit
    
    import "testing"
    
    var registered bool
    
    func Register() {
        registered = true
    }
    
    func TestPackage(t *testing.T) {
        if !registered {
            t.Fatal("registry never called")
        }
    }

Running the tests gives the error "registry never called",
indicating that the code in extern_test.go is never run.
Moreover, it's not even compiled - there's no error from
the unused variable.

While it may look contrived, the above configuration mirrors the way
that tests are registered with the popular gocheck testing
package - tests that were previously run correctly may now
be silently skipped.

I have verified that this is a regression since Go 1.2.2.

FWIW, there is an easy workaround (define TestPackage in the external
test file) but it might be better to avoid the regression.
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jun 16, 2014

Comment 1:

Labels changed: added repo-main, release-go1.4.

@josharian

This comment has been minimized.

Copy link
Contributor

commented Sep 17, 2014

Comment 2:

Looks like a duplicate of 8337. Please holler if I'm wrong.

Status changed to Duplicate.

Merged into issue #8337.

@rsc rsc added this to the Go1.4 milestone Apr 14, 2015

@rsc rsc removed the release-go1.4 label Apr 14, 2015

@golang golang locked and limited conversation to collaborators Jun 25, 2016

This issue was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.