Skip to content

testing: Tests with cover option fail because of syntax error, tests without coverage are passing #10250

@mrfuxi

Description

@mrfuxi

Go version go1.4.1 linux/amd64

When looping over channel without actually looking at value cover is reporting error:

expected operand, found 'range' (and 1 more errors)

However app runs fine and tests without coverage are passing correctly.

Console

$ go test
PASS
ok      _/home/fuxi/test    0.003s

$ go test -cover
# cover _/path/test
2015/03/25 22:45:53 cover: /path/test/main.go: /path/test/main.go:10:9: expected operand, found 'range' (and 1 more errors)
FAIL    _/path/test [build failed]

Code to reproduce:

  • main.go
package main

import (
    "fmt"
    "time"
)

func main() {
    t := time.NewTicker(time.Duration(time.Second))
    for range t.C {
        fmt.Println("Exec")
    }
}
  • main_test.go
package main

import "testing"

func TestMain(t *testing.T) {}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions