代码之家  ›  专栏  ›  技术社区  ›  blokeley SERPRO

“hg bisct--command”是否有推荐的命令?

  •  8
  • blokeley SERPRO  · 技术社区  · 16 年前

    我有一个紧急的bug,明天我必须追踪它。我知道以前的hg修订版很好,所以我考虑使用hg平分。

    但是,我在Windows上,不想进入DOS脚本。

    理想情况下,我可以编写一个Python单元测试,并让hgbisct使用它。这是我的第一次尝试。

    平分线.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
    

    有更好的方法吗?谢谢你的建议。

    3 回复  |  直到 16 年前
        1
  •  10
  •   blokeley SERPRO    16 年前

    多亏了所有人,尤其是威尔·麦考岑。 最有效的解决方案如下。

    平分线.py

    #!/usr/bin/env python
    
    import unittest
    
    class TestCase(unittest.TestCase):
    
        def test(self):
            # Raise an assertion error to mark the revision as bad
            pass
    
    
    if '__main__' == __name__:
        unittest.main()
    

    最困难的部分是让hg平分命令正确:

    hg update tip
    hg bisect --reset
    hg bisect --bad
    hg bisect --good 0
    hg bisect --command ./bisector.py
    

    或者在Windows上,最后一个命令是:

    hg bisect --command bisector.py
    
        2
  •  4
  •   Will McCutchen    16 年前

    我想你可以把你的 main() 函数并使用以下块运行测试:

    if __name__ == '__main__':
       unittest.main()
    

    呼唤 unittest.main() 将运行在此文件中找到的测试,并根据所有测试是否通过,使用适当的状态代码退出。

        3
  •  1
  •   awwaiid    16 年前

    如果您可以使用一些Unix工具,请注意“grep”以一种有用的方式设置其退出状态。因此,如果单元测试通过时打印“通过”,则可以执行以下操作:

    hg bisect -c './unittest | grep PASS'
    

    那会很有效的。

    推荐文章