mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2025-12-18 19:54:21 +08:00
清理文件
This commit is contained in:
@@ -526,7 +526,7 @@ $ go list -f={{.GoFiles}} fmt
|
||||
[doc.go format.go print.go scan.go]
|
||||
```
|
||||
|
||||
{% endraw %}
|
||||
|
||||
|
||||
TestGoFiles表示的是fmt包内部测试代码,以_test.go为后缀文件名,不过只在测试时被构建:
|
||||
|
||||
@@ -537,7 +537,7 @@ $ go list -f={{.TestGoFiles}} fmt
|
||||
[export_test.go]
|
||||
```
|
||||
|
||||
{% endraw %}
|
||||
|
||||
|
||||
包的测试代码通常都在这些文件中,不过fmt包并非如此;稍后我们再解释export_test.go文件的作用。
|
||||
|
||||
@@ -550,7 +550,7 @@ $ go list -f={{.XTestGoFiles}} fmt
|
||||
[fmt_test.go scan_test.go stringer_test.go]
|
||||
```
|
||||
|
||||
{% endraw %}
|
||||
|
||||
|
||||
有时候外部测试包也需要访问被测试包内部的代码,例如在一个为了避免循环导入而被独立到外部测试包的白盒测试。在这种情况下,我们可以通过一些技巧解决:我们在包内的一个_test.go文件中导出一个内部的实现给外部测试包。因为这些代码只有在测试时才需要,因此一般会放在export_test.go文件中。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user