Page MenuHomePhabricator

Add a Go unit test engine with support for Race and Godep.
Needs ReviewPublic

Authored by eMxyzptlk on Apr 30 2015, 10:37 AM.

Details

Reviewers
None
Group Reviewers
Blessed Reviewers
Maniphest Tasks
T6867: Add linter and unit test engine for Go(lang)
Summary

Add support for running Unit Test for Go.

This differential adds two new configuration options:

unit.go.godep bool: If enabled and Godeps folder is found at the root of the repository, the tests will run through godep. Default: true
unit.go.race bool: If enabled, race detection will be run. Default: true

Test Plan

Test in https://github.com/julienschmidt/httprouter, must add the following arcconfig file

{
  "phabricator.uri" : "https://secure.phabricator.com/",
  "unit.engine": "GoTestEngine"
}

Then make a breaking change and run 'arc unit'.

Example output:

   PASS   <1ms★  Go::Test::github.com::julienschmidt::httprouter::TestPathClean
   PASS   <1ms★  Go::Test::github.com::julienschmidt::httprouter::TestPathCleanMallocs
   PASS   <1ms★  Go::Test::github.com::julienschmidt::httprouter::TestParams
   PASS   <1ms★  Go::Test::github.com::julienschmidt::httprouter::TestRouter
   PASS   <1ms★  Go::Test::github.com::julienschmidt::httprouter::TestRouterAPI
   PASS   <1ms★  Go::Test::github.com::julienschmidt::httprouter::TestRouterRoot
   PASS   <1ms★  Go::Test::github.com::julienschmidt::httprouter::TestRouterNotAllowed
   PASS   <1ms★  Go::Test::github.com::julienschmidt::httprouter::TestRouterNotFound
   PASS   <1ms★  Go::Test::github.com::julienschmidt::httprouter::TestRouterPanicHandler
   PASS   <1ms★  Go::Test::github.com::julienschmidt::httprouter::TestRouterLookup
   PASS   <1ms★  Go::Test::github.com::julienschmidt::httprouter::TestRouterServeFiles
   PASS   <1ms★  Go::Test::github.com::julienschmidt::httprouter::TestCountParams
   FAIL  Go::Test::github.com::julienschmidt::httprouter::TestTreeAddAndGet
tree_test.go:100: maxParams mismatch for node 'ntact': is 0, should be 0

   FAIL  Go::Test::github.com::julienschmidt::httprouter::TestTreeWildcard
tree_test.go:100: maxParams mismatch for node ':query': is 1, should be 1

   PASS   <1ms★  Go::Test::github.com::julienschmidt::httprouter::TestTreeWildcardConflict
   PASS   <1ms★  Go::Test::github.com::julienschmidt::httprouter::TestTreeChildConflict
   PASS   <1ms★  Go::Test::github.com::julienschmidt::httprouter::TestTreeDupliatePath
   PASS   <1ms★  Go::Test::github.com::julienschmidt::httprouter::TestEmptyWildcardName
   PASS   <1ms★  Go::Test::github.com::julienschmidt::httprouter::TestTreeCatchAllConflict
   PASS   <1ms★  Go::Test::github.com::julienschmidt::httprouter::TestTreeCatchAllConflictRoot
   PASS   <1ms★  Go::Test::github.com::julienschmidt::httprouter::TestTreeDoubleWildcard
   PASS   <1ms★  Go::Test::github.com::julienschmidt::httprouter::TestTreeTrailingSlashRedirect
   PASS   <1ms★  Go::Test::github.com::julienschmidt::httprouter::TestTreeFindCaseInsensitivePath
   PASS   <1ms★  Go::Test::github.com::julienschmidt::httprouter::TestTreeInvalidNodeType

To test the race detection:

Create arc_test.go

package test

import "testing"

func TestShouldNotPassRaceTest(t *testing.T) {
        var myString string

        go func() {
                myString = "hello"
        }()

        go func() {
                myString = "bye"
        }()
}

Output:

   FAIL  Go::Test::_::tmp::test_arc::TestShouldNotPassRaceTest() Race Detected
WARNING: DATA RACE
Write by goroutine 7:
  _/tmp/test_arc.func·002()
      /tmp/test_arc/arc_test.go:13 +0x3a

Previous write by goroutine 6:
  _/tmp/test_arc.func·001()
      /tmp/test_arc/arc_test.go:9 +0x3a

Goroutine 7 (running) created at:
  _/tmp/test_arc.TestShouldNotPassRaceTest()
      /tmp/test_arc/arc_test.go:14 +0x133
  testing.tRunner()
      /usr/local/Cellar/go/1.4.2/libexec/src/testing/testing.go:447 +0x133

Goroutine 6 (finished) created at:
  _/tmp/test_arc.TestShouldNotPassRaceTest()
      /tmp/test_arc/arc_test.go:10 +0xc0
  testing.tRunner()
      /usr/local/Cellar/go/1.4.2/libexec/src/testing/testing.go:447 +0x133

   PASS   <1ms★  Go::Test::_::tmp::test_arc::TestShouldNotPassRaceTest

Refs T6867
Closes D12598, D12537, D12546

Diff Detail

Event Timeline

eMxyzptlk retitled this revision from to Add a Go unit test engine with support for Race, Coverage and Godep..
eMxyzptlk updated this object.
eMxyzptlk edited the test plan for this revision. (Show Details)
eMxyzptlk added a reviewer: Blessed Reviewers.
eMxyzptlk retitled this revision from Add a Go unit test engine with support for Race, Coverage and Godep. to Add a Go unit test engine with support for Race and Godep..Apr 30 2015, 10:40 AM
eMxyzptlk edited edge metadata.
eMxyzptlk updated this object.

@sectioneight Let's add coverage support once this D gets merged.

nice!

src/unit/engine/GoTestEngine.php
59

this is a little awkward, since in the case of non-godep, the $cmd will have a leading space. perhaps:

$cmd = '';
if ($this->useGodep()) {
  $cmd = 'godep ';
}

$cmd .= 'go test -v';

Any word on getting this landed?

See T10038, referenced from the parent task.

rayzyar added inline comments.
src/unit/parser/ArcanistGoTestResultParser.php
20

build failure is not handled here,
I tried to detect by [build failed], but some build failure case does not print this

leoluk removed a subscriber: leoluk.
leoluk added a subscriber: leoluk.