Support `go test` blackbox tests.

Review Request #3327 - Created Jan. 11, 2016 and submitted

Information
John Sirois
pants
jsirois/issues/2787
2787, 2791
Reviewers
pants-reviews
mateor, zundel
The `go test` command supports black box tests.  These are tests that
live in the package directory of code they test, but which declare a
different package, namely a package of the same name as the test file.
For example, `lib/lib.go` might be tested by `lib/lib_test.go` which
declares itself to be in the `lib_test` package.  Since
`lib/lib_test.go` is in a different package from `lib/lib.go` it can
only access its exported symbols, and so black box testing is enforced
by the compiler.

The `go list` command, used by pants to form go roots and generate go
BUILD files categorizes imports from this style of test differently from
"normal" tests; ie: instead of listing these test imports under the
`TestImports` key, they are listed under the `XTestImports` key.  Add
support for this 3rd import category and arrange for `GoBuildgen` to
support these imports while simultaneously removing support for test
imports of either kind from `GoFetch`.  The latter is done for
simplicity since a remote libs test imports would only ever be needed to
run that remote lib's tests locally.

A failing test was added for a target with a black box test that is
fixed by this change.

 contrib/go/src/python/pants/contrib/go/tasks/go_fetch.py                | 16 +++++++++-------
 contrib/go/src/python/pants/contrib/go/tasks/go_task.py                 | 19 ++++++++++++++++---
 contrib/go/tests/python/pants_test/contrib/go/tasks/test_go_buildgen.py | 44 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+), 10 deletions(-)
Failing test added which now runs green.

CIs went green here:
  https://travis-ci.org/pantsbuild/pants/builds/101649933
  http://ec2-54-146-169-50.compute-1.amazonaws.com:8080/job/pants_ci_trigger/67/
John Sirois
John Sirois
John Sirois
Dan Benson
John Sirois
John Sirois
Review request changed

Status: Closed (submitted)

Change Summary:

Now on master:

git log -1 origin/master
commit 98f748208024344881ca7e32b9663de8bc8b64ed
Author: John Sirois <john.sirois@gmail.com>
Date:   Mon Jan 11 11:48:19 2016 -0700

    Support `go test` blackbox tests.
    
    The `go test` command supports black box tests.  These are tests that
    live in the package directory of code they test, but which declare a
    different package, namely a package of the same name as the test file.
    For example, `lib/lib.go` might be tested by `lib/lib_test.go` which
    declares itself to be in the `lib_test` package.  Since
    `lib/lib_test.go` is in a different package from `lib/lib.go` it can
    only access its exported symbols, and so black box testing is enforced
    by the compiler.
    
    The `go list` command, used by pants to form go roots and generate go
    BUILD files categorizes imports from this style of test differently from
    "normal" tests; ie: instead of listing these test imports under the
    `TestImports` key, they are listed under the `XTestImports` key.  Add
    support for this 3rd import category and arrange for `GoBuildgen` to
    support these imports while simultaneously removing support for test
    imports of either kind from `GoFetch`.  The latter is done for
    simplicity since a remote libs test imports would only ever be needed to
    run that remote lib's tests locally.
    
    A failing test was added for a target with a black box test that is
    fixed by this change.
    
    Testing Done:
    Failing test added which now runs green.
    
    CIs went green here:
      https://travis-ci.org/pantsbuild/pants/builds/101649933
      http://ec2-54-146-169-50.compute-1.amazonaws.com:8080/job/pants_ci_trigger/67/
    
    Bugs closed: 2787, 2791
    
    Reviewed at https://rbcommons.com/s/twitter/r/3327/
Loading...