HN 提问:你如何区分有意的测试样板代码和真正的重复代码?

7作者: rafaepta5 天前
我正在维护一个开源项目(一个确定性的开源重复代码检测器),一位用户提出了一项功能需求,但我对如何实现它没有清晰的思路。 这似乎是一个非常棘手的问题: * 测试会重复相同的场景。对于结构化检测器来说,这会被标记为重复(代码冗余)。然而,人们通常不希望从代码库中删除测试。 * 测试中的重复(是有意为之的)最终看起来像是不期望的代码重复,而工具无法区分它们。 * 一种解决办法可能是引入“人工干预”(类似于 linter 允许用户一次性接受某个建议,同时保留默认的零配置首次运行)。 我想了解一下您是如何处理这种情况的,以及是否有人有什么想法。 这是我的仓库:https://github.com/Rafaelpta/dupehound 这是更详细的 issue:https://github.com/Rafaelpta/dupehound/issues/23
查看原文
I am maintaining an open-source project (deterministic open source duplicate-code detector) and a user asked for a feature which I don’t have a clear answer on how to implement.<p>This seems a very hard problem to solve:<p>-Tests repeat the same scenario. For a structural detector, this flags as repetition (duplication). However, tests are not something people want to delete from the codebases.<p>-The repetitions from tests (on purpose) end up looking like undesired code duplication and the tools canno tell which is which.<p>-One way to solve this would be something like a human in the loop (kind of how linters allow user to accept something once, while keeping the default first run zero-config).<p>Wonder how you have seen this handle and if anyone have any ideas.<p>Here is the the repo: https:&#x2F;&#x2F;github.com&#x2F;Rafaelpta&#x2F;dupehound<p>And here is the issue with more detail: https:&#x2F;&#x2F;github.com&#x2F;Rafaelpta&#x2F;dupehound&#x2F;issues&#x2F;23