Skip to content

testing: panic during Example function omits stack trace #2691

Closed

Description

@gopherbot

by raul.san@sent.com:

The exampe functions are masking the errors.

===
import "testing"
import "fmt"

func TestNone(t *testing.T) {}

func Example_ff() {
        var a map[int][]string
        a[1][10] = "foo"

        fmt.Println(a[1])
}

===
$ gotest
PASS

8c6f3122826c+ tip (last weekly)
Ubuntu 11.10, AMD64 


Related to
http://groups.google.com/group/golang-nuts/browse_thread/thread/6f43e7b5a7c82251

Activity

  1. rsc commented on Jan 12, 2012

    @rsc
    Contributor

    Comment 1:

    What you have written is correct behavior:
    a test that does not call t.Error or t.Fatal is a
    passing test, so TestNone is a passing test.
    You have no output comment in the example to check
    against, so the example just needs to build, not run.
    So everything here is okay, so the test should print PASS.
    Did you have something else in mind?

    Status changed to WaitingForReply.

  2. gopherbot commented on Jan 12, 2012

    @gopherbot
    ContributorAuthor

    Comment 2 by raul.san@sent.com:

    I added TestNone for that it does not show the warning (due to don't use a test
    function). Sorry! Now, the next one is more clear:
    ===
    import "testing"
    import "fmt"
    // nothing
    func Example_ff() {
            var a map[int][]string
            a[1][10] = "foo"
            fmt.Println(a[1])
    }
    ===
    $ gotest
    testing: warning: no tests to run
    --- FAIL: Example_ff
    panic: runtime error: index out of range
    gotest: "./6.out" failed: exit status 1
    * * *
    ===
    import "testing"
    import "fmt"
    // nothing
    func TestConst(t *testing.T) {
            var a map[int][]string
            a[1][10] = "foo"
            fmt.Println(a[1])
    }
    ===
    $ gotest
    panic: runtime error: index out of range
    goroutine 2 [running]:
    github.com/kless/GoJscript/gojs.TestConst()
        /home/neo/Pub/Projects/Go/GoJscript/gojs/gojs_test.go:27 +0x63
    testing.tRunner(0xf840000c40, 0x590fe0, 0x0, 0x0)
        /var/tmp/go/src/pkg/testing/testing.go:198 +0x41
    created by testing.RunTests
        /var/tmp/go/src/pkg/testing/testing.go:275 +0x772
    goroutine 1 [chan receive]:
    testing.RunTests(0x400c00, 0x590fe0, 0x100000001, 0xf84002cc01, 0x40673f, ...)
        /var/tmp/go/src/pkg/testing/testing.go:276 +0x795
    testing.Main(0x400c00, 0x590fe0, 0x100000001, 0x59eda8, 0x0, ...)
        /var/tmp/go/src/pkg/testing/testing.go:211 +0x62
    main.main()
        /home/neo/Pub/Projects/Go/GoJscript/gojs/_testmain.go:29 +0x91
    gotest: "./6.out" failed: exit status 2
    * * * 
    Note: that the example functions doesn't show all error message (the stack) like is done
    with the test functions
  3. rsc commented on Jan 12, 2012

    @rsc
    Contributor

    Comment 3:

    Labels changed: added priority-go1, removed priority-triage.

    Owner changed to @adg.

    Status changed to Accepted.

  4. robpike commented on Jan 13, 2012

    @robpike
    Contributor

    Comment 4:

    Owner changed to builder@golang.org.

  5. robpike commented on Jan 19, 2012

    @robpike
    Contributor

    Comment 5:

    This issue was closed by revision d888ab8.

    Status changed to Fixed.

  6. added this to the Go1 milestone on Apr 10, 2015
  7. locked and limited conversation to collaborators on Jun 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions