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
Closed

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

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

Comments

@rogpeppe
Copy link
Contributor

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
Copy link
Contributor

Comment 1:

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

@josharian
Copy link
Contributor

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.
Projects
None yet
Development

No branches or pull requests

5 participants