Skip to content

testing: inconsistent formatting of Test() vs. Example() timing #8175

Closed

Description

@gopherbot

by jsimsa@google.com:

What does 'go version' print?
go version go1.2.2 darwin/amd64

What steps reproduce the problem?
Running the following program with "go test -v":

package simple

import (
        "testing"
        "time"
)

func TestEmpty(*testing.T) {}

func TestNanosecond(*testing.T) {
        time.Sleep(time.Nanosecond)
}

func TestMicrosecond(*testing.T) {
        time.Sleep(time.Microsecond)
}

func TestMillisecond(*testing.T) {
        time.Sleep(time.Millisecond)
}

func TestSecond(*testing.T) {
        time.Sleep(time.Second)
}

func ExampleEmpty() {
        // Output:                                                                                                                                                                                                
}

func ExampleNanosecond() {
        time.Sleep(time.Nanosecond)
        // Output:                                                                                                                                                                                                
}

func ExampleMicroSecond() {
        time.Sleep(time.Microsecond)
        // Output:                                                                                                                                                                                                
}

func ExampleMillisecond() {
        time.Sleep(time.Millisecond)
        // Output:                                                                                                                                                                                                
}

func ExampleSecond() {
        time.Sleep(time.Second)
        // Output:                                                                                                                                                                                                
}

results in the following output:

=== RUN TestEmpty
--- PASS: TestEmpty (0.00 seconds)
=== RUN TestNanosecond
--- PASS: TestNanosecond (0.00 seconds)
=== RUN TestMicrosecond
--- PASS: TestMicrosecond (0.00 seconds)
=== RUN TestMillisecond
--- PASS: TestMillisecond (0.00 seconds)
=== RUN TestSecond
--- PASS: TestSecond (1.00 seconds)
=== RUN: ExampleEmpty
--- PASS: ExampleEmpty (408ns)
=== RUN: ExampleNanosecond
--- PASS: ExampleNanosecond (61.263us)
=== RUN: ExampleMicroSecond
--- PASS: ExampleMicroSecond (42.937us)
=== RUN: ExampleMillisecond
--- PASS: ExampleMillisecond (1.126604ms)
=== RUN: ExampleSecond
--- PASS: ExampleSecond (1.001000532s)
PASS
ok      _/Users/jsimsa/tmp  2.011s

As you can see the formatting of the timing of tests and examples is inconsistent. I
suggest that examples use the same formatting of timing as tests. (The Go distribution
my team uses employs a simple patch to that end in order to simplify post-processing of
test results).

Activity

  1. robpike commented on Jun 9, 2014

    @robpike
    Contributor

    Comment 1:

    Just the kind of inconsistency that gets stuck in my craw. Will fix for next release.
    Note: the use of 'us' for microseconds also sticks in my craw.

    Labels changed: added release-go1.4.

    Owner changed to @robpike.

    Status changed to Accepted.

  2. gopherbot commented on Jun 11, 2014

    @gopherbot
    ContributorAuthor

    Comment 2:

    CL https://golang.org/cl/103320043 mentions this issue.
  3. robpike commented on Jun 18, 2014

    @robpike
    Contributor

    Comment 3:

    This issue was closed by revision 0e92b53.

    Status changed to Fixed.

  4. added this to the Go1.4 milestone on Apr 14, 2015
  5. locked and limited conversation to collaborators on Jun 25, 2016
  6. added a commit that references this issue on Jun 25, 2018
    e3bc532
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