Created
December 13, 2011 18:09
-
-
Save zeroasterisk/1473163 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * This tester is a great tool for testing something in an easy way to make git bisect work for you | |
| * note: not part of the repo, so it's not overwritten by git | |
| * @link http://book.git-scm.com/5_finding_issues_-_git_bisect.html | |
| * @link http://alblue.bandlem.com/2011/07/git-tip-of-week-git-bisect.html | |
| */ | |
| class BisectShell extends Shell{ | |
| var $uses = array('Event', 'Util', 'Asset'); | |
| # test: return true/false | |
| function test(){ | |
| $this->out("{$this->name}:".__function__." Shell - env: ".configure::read('env')." - site: ".configure::read('site')); | |
| $re = false; | |
| # ----------------------------------------------------------- | |
| # write your test here | |
| $old_event_id = 5112; | |
| $countOldTestQuestions = $this->Event->CeuTestQuestion->find('count', array( | |
| 'conditions' => array('event_id' => $old_event_id) | |
| )); | |
| $new_event_id = $this->Event->copy($old_event_id, 0, 'text'); | |
| $countNewTestQuestions = $this->Event->CeuTestQuestion->find('count', array( | |
| 'conditions' => array('event_id' => $new_event_id) | |
| )); | |
| $re = ($old_event_id != $new_event_id && $countOldTestQuestions == $countNewTestQuestions); | |
| # end test ($re should be true/false) | |
| # ----------------------------------------------------------- | |
| $this->out("test = ".($re ? 'good' : 'bad')); | |
| if ($this->command == __function__) { | |
| exit; | |
| } | |
| return $re; | |
| } | |
| # main | |
| function main(){ | |
| $this->out("{$this->name}:".__function__." Shell - env: ".configure::read('env')." - site: ".configure::read('site')); | |
| $this->hr(); | |
| $this->help(); | |
| } | |
| # run: start bisect | |
| function start(){ | |
| $command = 'git bisect start'; | |
| $re = shell_exec($command); | |
| $this->out(print_r($re, true)); | |
| $this->run(); | |
| } | |
| # run: test and bisect-respond | |
| function run(){ | |
| $this->out("{$this->name}:".__function__." Shell - env: ".configure::read('env')." - site: ".configure::read('site')); | |
| $this->hr(); | |
| do { | |
| $response = $this->test(); | |
| $bisect_response = $this->bisect_respond($response); | |
| } while( strpos($bisect_response , 'revisions left to test after this')!==false ); | |
| } | |
| # script: automated test | |
| function script(){ | |
| $re = $this->test(); | |
| if (!$re) { | |
| $this->error("bad", "bad"); | |
| } | |
| } | |
| # test: return true/false | |
| function bisect_respond($goodBad=null) { | |
| $this->out("{$this->name}:".__function__." Shell - env: ".configure::read('env')." - site: ".configure::read('site')); | |
| if ($goodBad==null) { | |
| $goodBad = array_shift($this->args); | |
| } | |
| if (empty($goodBad) || in_array(strtoupper($goodBad), array('B', 'N', 'BAD', 'NO', 'F', 'FAILURE', 'FALSE'))) { | |
| $goodBad = false; | |
| } else { | |
| $goodBad = true; | |
| } | |
| $command = 'git bisect '.($goodBad ? 'good' : 'bad'); | |
| $this->out($command); | |
| $re = shell_exec($command); | |
| $this->out($re); | |
| if ($this->command == __function__) { | |
| exit; | |
| } | |
| return $re; | |
| } | |
| # help | |
| function help(){ | |
| $this->out("{$this->name} Help - env: ".configure::read('env')." - site: ".configure::read('site')); | |
| $this->out(" cake {$this->shell} help List this help"); | |
| $this->out(); | |
| $this->out("suggested usage is through git:"); | |
| $this->out(" cd ".dirname(APP)."; (not app root)"); | |
| $this->out(" [bad] [good]"); | |
| $this->out(" git bisect start dev v1.1.360"); | |
| $this->out(" git bisect run ./bisect-script.sh"); | |
| $this->out(); | |
| $this->out("or you can access the underlying commands manually"); | |
| $this->out(" cake {$this->shell} test Run your test and return good/bad"); | |
| $this->out(" cake {$this->shell} run Run a test and tell bisect good/bad"); | |
| $this->out(); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment