Ensure go source is correct without building / running tests?

agolangf · · 378 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m trying to write a little command into my editor to ensure that my Go source builds, but without actually building a binary or running tests. Is there a good method to do this?</p> <hr/>**评论:**<br/><br/>jerf: <pre><p>It depends on exactly what you are looking for, but there is a <a href="https://stackoverflow.com/questions/16863014/is-there-a-command-line-tool-in-golang-to-only-check-syntax-of-my-source-code" rel="nofollow">gofmt -e option to check syntax only</a>.</p> <p>If you demand that it be very fast, that&#39;s probably the best option. That still doesn&#39;t prove it will build, because there can be non-syntax problems, but if you start down that road you end up at &#34;you&#39;re gonna have to compile it&#34; pretty quick.</p> <p>You may also be surprised at how fast the &#34;compile it&#34; option can be. Check out <a href="https://github.com/dougm/goflymake" rel="nofollow">go-flymake</a> for an example. It runs fairly well for me in emacs. Some of it is whether or not you can run processes without freezing the rest of the editor. (Emacs usually has trouble with that but apparently it can do this OK somehow.)</p></pre>epiris: <pre><p>To ensure Go source builds, you must build it. There is no way around this, what are you actually trying to achieve? If it’s to lower the time between feedback while writing Go code- “go build” may be suitable so I would start there.</p> <p>If you have found it takes to long than maybe you have a project with large amounts of compiled code inside it, which could be moved to another package to lower compile times. As a last resort you could run go build without any ssa passes by passing -N via gcflags which should disable the lions share of the processing time.</p></pre>

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

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