去测试编译成功,但是去编译没有

时间:2019-12-11 21:34:30

标签: windows go testing compilation

尽管我完全删除了缓存(go clean -cache,但我正在尝试在Windows中在go中测试主软件包,并且该测试似乎已被缓存。

要对此进行测试,我更改了一个文件(parseinput.go),以使其在编译期间产生错误(未定义的变量)。结果是,无法构建主软件包:

go\src\xxx\apimonitor> go build
# xxx/apimonitor
.\inputparser.go:15:2: undefined: err
.\inputparser.go:16:19: undefined: err

,但测试仍成功完成(go test甚至go test -a):

go\src\xxx\apimonitor> go test
PASS
ok      xxx/apimonitor  0.786s

关于为什么这种情况不断发生以及为什么测试无法重新编译的任何线索?可以从以前的版本中缓存此软件包的其他任何地方吗?


更新

添加一些打印语句后,测试(go test)似乎可以成功编译 inputparser.go(尽管err变量未定义),但是构建失败(如上所述)。这就是让我相信测试已缓存的原因。这是构建失败的源示例:

func parseStoreInput(strArray []string) (inputStoreTransactionHash, error) {
    var parsedIn inputStoreTransactionHash
    if !validateInput(strArray, 1, true) {
        return parsedIn, errors.New("Expecting an escaped JSON string as input")
    }
    err = json.Unmarshal([]byte(strArray[0]), &parsedIn)
    return parsedIn, err
}

关于为什么会发生这种情况的任何线索/文档?

1 个答案:

答案 0 :(得分:0)

  

Command go

     

Compile packages and dependencies

     

构建标志由构建,清理,获取,安装,列出,   运行并测试命令:

-a
  force rebuilding of packages that are already up-to-date.
-n
  print the commands but do not run them.
-v
  print the names of packages as they are compiled.
-x
  print the commands.
     

Remove object files and cached files

     

用法:

go clean [clean flags] [build flags] [packages]
     

-cache标志会导致clean删除整个go build缓存。

     

-testcache标志会导致clean终止所有测试结果   建立缓存。

     

Testing flags

     

当“ go test”以程序包列表模式运行时,“ go test”成功缓存   打包测试结果,以避免不必要的重复运行测试。   要禁用测试缓存,请使用除   可缓存的标志。明确禁用测试缓存的惯用方式   是使用-count=1

相关问题