go test a package with some non-compiling code ?

polaris · · 326 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Let say I have a package containing two source files foo.go and bar.go, and their associated test files foo_test.go and bar_test.go. When I run <em>go test</em> in that package directory everything is fine. </p> <p>Then I refactor code in foo.go. As a consequence bar.go, and the tests don&#39;t compile and run anymore. </p> <p>I then would like to first refactor the foo_test.go to make sure foo is ok, before refactoring bar.go. But <em>go test</em> won&#39;t allow me to execute it because bar.go doesn&#39;t compile. </p> <p>Is there a way to allow me to test foo.go with foo_test.go even if bar.go doesn&#39;t compile ? </p> <p>Now I rename bar.go and bar_test.go into bar.go_lck and bar_test.go_lck, but it&#39;s inconvenient. </p> <hr/>**评论:**<br/><br/>danredux: <pre><p>Add something like</p> <pre><code>// +build imready </code></pre> <p>To the top of the file you want to hide (it&#39;s a build tag). It will no longer be included. Now you can pass in a build tag when you&#39;re ready to start including that file, or just remove the line.</p></pre>chmikes: <pre><p>This is great. Thank you very much. Is there a place where such build tags are listed ? I have seen that there is a similar way to direct the compiler to only compile some code on specific OS. </p></pre>Akkifokkusu: <pre><p>Put them in separate packages? Comment out the parts of <code>bar.go</code> that were broken by the changes to <code>foo.go</code>?</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

326 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传