Windows Go test编译成功,但Go build没有';T

Windows Go test编译成功,但Go build没有';T,windows,go,testing,compilation,Windows,Go,Testing,Compilation,我试图在go(在Windows中)中测试一个主包,虽然我完全删除了缓存(go clean-cache) 为了测试这一点,我更改了一个文件(parseinput.go),以便它在编译过程中产生一个错误(未定义的变量)。结果是,无法生成主包: go\src\xxx\apimonitor> go build # xxx/apimonitor .\inputparser.go:15:2: undefined: err .\inputparser.go:16:19: undefined: err

我试图在go(在Windows中)中测试一个主包,虽然我完全删除了缓存(
go clean-cache

为了测试这一点,我更改了一个文件(
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
):

关于为什么会发生这种情况以及为什么测试不会重新编译,有什么线索吗?从以前的版本中缓存此包的任何其他位置


更新

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

func parseStoreInput(strArray[]字符串)(inputStoreTransactionHash,错误){
var parsedIn inputStoreTransactionHash
if!validateInput(strArray,1,true){
返回parsedIn,errors.New(“需要一个转义的JSON字符串作为输入”)
}
err=json.Unmarshal([]字节(strArray[0]),&parsedIn)
返回parsedIn,err
}
关于为什么会发生这种情况的任何线索/文件

生成标志由生成、清除、获取、安装、列表共享, 运行、运行和测试命令:

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

用法:

go clean [clean flags] [build flags] [packages]
-cache
标志导致clean删除整个go-build缓存

-testcache
标志会导致go中的所有测试结果的clean过期 构建缓存

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


如果没有实际的代码,很难说……您的测试是否导入了apimonitor包
go test-count 1
是重新运行缓存测试的标准方法。@icio apimonitor是我的主程序包。
go clean [clean flags] [build flags] [packages]