Skip to content

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

@gopherbot

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).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions