Code coverage exclude code

agolangf · · 369 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hi everyone,</p> <p>I have a project where a big part of its logic is found in a generated go file: I&#39;m using ragel to generate a parsing state machine.</p> <p>I want to test the project and generate code coverage statistics for the package this is included in, but at the same time I want to ignore the thousands lines of generated code from the count. </p> <p>On stackoverflow I found a suggestion to use <code>//+build !test</code> build tag. Unfortunately this doesn&#39;t work, I need the file to be included in the tests, just not counted in code coverage.</p> <p>Did anyone have a similar issue and found a solution?</p> <hr/>**评论:**<br/><br/>natefinch: <pre><p>if you don&#39;t care that it&#39;s not covered.... isn&#39;t that good enough? Just stop caring. Check your coverage manually for the rest of the files in the package.</p> <p>If possible, you could move the generated file to a different package, and then just declare you don&#39;t care about the coverage for that package.</p> <p>But in general... code coverage is a lie. Code coverage tells you what code is definitely not tested <em>by this package</em>. It doesn&#39;t tell you if it actually <em>is</em> tested by anything.</p></pre>habarnam: <pre><p>The thing is that the state-machine generated is very/very verbose. It&#39;s probably impossible to create documents that would cover everything. (Also, more likely, it&#39;s the fact that I&#39;m not yet quite proficient with ragel, and I probably wrote a sub-optimal parser.)</p> <p>Also I think some sort of numbers getting higher every time you push changes is good for the enjoyment of a programming task. Gamification and all that... :D</p></pre>tv64738: <pre><p>Maybe you can put the ragel parser in an <code>internal/parser</code> package, and just ignore the coverage of that package?</p></pre>habarnam: <pre><p>Good idea, thanx. I was already doing something similar, by not exporting the function generated by ragel.</p></pre>everdev: <pre><p>Does it make sense to put the generated code into a package?</p></pre>haikubot-1911: <pre><p><em>Does it make sense to</em></p> <p><em>Put the generated code</em></p> <p><em>Into a package?</em></p> <p> </p> <p>                  <sup>-</sup> <sup>everdev</sup></p> <hr/> <p><sup><sup>I&#39;m</sup></sup> <sup><sup>a</sup></sup> <sup><sup>bot</sup></sup> <sup><sup>made</sup></sup> <sup><sup>by</sup></sup> <sup><sup><a href="/u/Eight1911" rel="nofollow">/u/Eight1911</a>.</sup></sup> <sup><sup>I</sup></sup> <sup><sup>detect</sup></sup> <sup><sup>haiku.</sup></sup></p></pre>habarnam: <pre><p>Well, the generated code results in one low level function containing a ton of goto statements. I use it by wrapping it in a higher level function that I then export. So, in my opinion, it doesn&#39;t really qualify to be in its own package.</p></pre>

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

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