是否有“hg bisect --command”的推荐命令?
我有一个紧急错误,我明天必须找到它。我知道以前的 hg 修订版很好,所以我正在考虑使用 hg bisect。
然而,我使用的是 Windows,不想接触 DOS 脚本。
理想情况下,我能够编写一个 Python 单元测试并让 hg bisect 使用它。这是我的第一次尝试。
bisector.py
#!/usr/bin/env python
import sys
import unittest
class TestCase(unittest.TestCase):
def test(self):
#raise Exception('Exception for testing.')
#self.fail("Failure for testing.")
pass
def main():
suite = unittest.defaultTestLoader.loadTestsFromTestCase(TestCase)
result = unittest.TestResult()
suite.run(result)
if result.errors:
# Skip the revision
return 125
if result.wasSuccessful():
return 0
else:
return 1
if '__main__' == __name__:
sys.exit(main())
也许我可以运行:
hg bisect --reset
hg bisect --bad
hg bisect --good -r 1
hg bisect --command=bisector.py
有更好的方法吗?感谢您的任何建议。
I have an emergent bug that I've got to track down tomorrow. I know a previous hg revision which was good so I'm thinking about using hg bisect.
However, I'm on Windows and don't want to get into DOS scripting.
Ideally, I'd be able to write a Python unit test and have hg bisect use that. This is my first attempt.
bisector.py
#!/usr/bin/env python
import sys
import unittest
class TestCase(unittest.TestCase):
def test(self):
#raise Exception('Exception for testing.')
#self.fail("Failure for testing.")
pass
def main():
suite = unittest.defaultTestLoader.loadTestsFromTestCase(TestCase)
result = unittest.TestResult()
suite.run(result)
if result.errors:
# Skip the revision
return 125
if result.wasSuccessful():
return 0
else:
return 1
if '__main__' == __name__:
sys.exit(main())
Perhaps I could then run:
hg bisect --reset
hg bisect --bad
hg bisect --good -r 1
hg bisect --command=bisector.py
Is there a better way of doing it? Thanks for any advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
感谢所有人,特别是威尔·麦卡琴。
最有效的解决方案如下。
bisector.py
困难的部分是正确获取 hg bisect 命令:
或者在 Windows 上,最后一个命令是:
Thanks to all, especially to Will McCutchen.
The solution that worked best is below.
bisector.py
The hard part was getting the hg bisect commands right:
or on Windows, the last command is:
我认为您可以删除
main()
函数并使用以下块来运行测试:对
unittest.main()
的调用将运行它在此找到的测试文件并以适当的状态代码退出,具体取决于所有测试是通过还是失败。I think you can remove your
main()
function and use the following block to run the tests:The call to
unittest.main()
will run the tests it finds in this file and exit with an appropriate status code depending on whether all the tests pass or fail.如果您有一些 UNIX 工具可供使用,请注意“grep”以一种有用的方式设置其退出状态。因此,如果您的单元测试通过时打印“PASS”,您可以这样做:
这会工作得非常好。
In case you have some unix tools at your disposal, note that 'grep' sets its exit status in a useful way. So if your unit test prints "PASS" when it passes, you can do:
and that'll work pretty darn well.