main.go
func main() {
fmt.Println("hello")
ch := make(chan struct{}, 1)
<-ch
}
main_test.go
func Test_Main(t *testing.T) {
main()
}
去运行 main.go
hello
fatal error: all goroutines are asleep - deadlock!
goroutine 1 [chan receive]:
main.main()
但是去测试 -v main_test.go -run=Test_Main
=== RUN Test_Main
hello
go test 不会报错,会一直运行。查阅了很多资料,也没有找到解释这个现象的答案。可能是我的方式不对?这个通道方式是在项目中使用的。谢谢。
慕工程0101907
摇曳的蔷薇
随时随地看视频慕课网APP
相关分类