2010-03-24 14 views
8

Ho un bug emergente che devo rintracciare domani. Conosco una precedente revisione di hg che era buona quindi sto pensando di usare hg bisect.Esiste un comando consigliato per "hg bisect --command"?

Tuttavia, sono su Windows e non voglio entrare in scripting DOS.

Idealmente, mi piacerebbe essere in grado di scrivere un test di unità Python e hanno hg bisect usare quella. Questo è il mio primo tentativo

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()) 

Forse potrei quindi eseguire:

hg bisect --reset 
hg bisect --bad 
hg bisect --good -r 1 
hg bisect --command=bisector.py 

C'è un modo migliore di farlo? Grazie per qualsiasi consiglio.

+2

Potrebbe essere necessario specificare 'bisector.py' Python come il comando; Non sono sicuro che hg riconoscerà correttamente gli shebang su Windows o no (o se lo shebang sia valido anche sul tuo sistema Windows;)). – Amber

+1

meglio in cosa? Cosa c'è che non va nel tuo approccio, che deve migliorare? – nosklo

risposta

10

Grazie a tutti, in particolare alla volontà McCutchen. La soluzione che ha funzionato meglio è di seguito.

bisector.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() 

La parte più difficile è stata sempre il hg bisect comandi giusti:

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

o su Windows, l'ultimo comando è:

hg bisect --command bisector.py 
+0

Esattamente quello che stavo cercando, grazie! :) – Mizipzor

4

penso che è possibile rimuovere la funzione main() e utilizzare il codice di blocco per eseguire i test:

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

La chiamata a unittest.main() verrà eseguito i test che trova in questo file ed esce con un codice di stato appropriato a seconda se tutti i test superano o falliscono.

1

Nel caso in cui hai a disposizione alcuni strumenti unix, nota che 'grep' imposta il suo stato di uscita in un modo utile. Quindi, se la vostra unità di test stampe "passare" quando passa, si può fare:

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

e che lavorerò maledettamente bene.

+0

Buona idea. Sfortunatamente questo progetto è su Windows ma il tuo suggerimento merita di essere letto. Grazie. – blokeley

+0

Ci sono degli equivalenti di Windows (cygwin e standalone) che faranno la stessa cosa :) – awwaiid

Problemi correlati