dousha4804 2015-03-28 04:16
浏览 55
已采纳

转到示例将无法运行

I'm trying to add an example to a package, and run the example via go test, however the example is never run.

For example, see this gist: https://gist.github.com/85469ecc65bb5bb85857

The gist has example_test.go:

package cow_test

import (
    cow "gist.github.com/85469ecc65bb5bb85857"
)

func Example() {
    cow.Poke()
}

Yet when I run this:

# go test -v example_test.go 
testing: warning: no tests to run
PASS
ok      command-line-arguments  0.002s

However other packages from stdlib work just fine:

# cd /usr/lib/go/src/errors
# go test -v example_test.go 
=== RUN: Example
--- PASS: Example (0.00s)
PASS
ok      command-line-arguments  0.002s

What is wrong with my example?

  • 写回答

1条回答 默认 最新

  • douxiyi2418 2015-03-28 06:42
    关注

    From the documentation:

    Example functions without output comments are compiled but not executed.

    Add an output comment:

    func Example() {
        junk.Poke()
        // Output: MOOOO!
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探