チェンジセット 328

差分発生行の前後
無視リスト:
コミット日時:
2008/04/20 23:44:09 (4 年前)
コミッタ:
yossy
ログメッセージ:

AS3UnitForAsync: 非同期的な実行ができるようにRunnerを修正

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/inter/runners/BeforeAndAfterRunner.as

    r293 r328  
    1717package org.libspark.as3unit.inter.runners 
    1818{ 
    19         public class BeforeAndAfterRunner 
     19        import org.libspark.as3unit.runner.Runner; 
     20         
     21        public class BeforeAndAfterRunner extends Runner 
    2022        { 
    2123                private var beforeAnnotation:Namespace; 
     
    2325                private var testIntrospector:TestIntrospector; 
    2426                private var test:Object; 
     27                private var unprotectedComplete:Boolean; 
    2528                 
    2629                public function BeforeAndAfterRunner(testClass:Class,  
     
    3942                        try { 
    4043                                runBefores(); 
    41                                 runUnprotected(); 
    4244                        } 
    4345                        catch (e:FailedBefore) { 
     46                                runUnprotectedComplete(); 
     47                                return; 
     48                        } 
     49                        var noException:Boolean = false; 
     50                        try { 
     51                                unprotectedComplete = false; 
     52                                runUnprotected(); 
     53                                noException = true; 
    4454                        } 
    4555                        finally { 
    46                                 runAfters(); 
     56                                if (!noException && !runUnprotectedComplete) { 
     57                                        runUnprotectedComplete(); 
     58                                } 
    4759                        } 
    4860                } 
     
    5163                { 
    5264                        throw new DefinitionError('Subclass must override this method.'); 
     65                } 
     66                 
     67                protected function runUnprotectedComplete():void 
     68                { 
     69                        unprotectedComplete = true; 
     70                        runAfters(); 
     71                        runFinished(); 
    5372                } 
    5473                 
     
    85104                } 
    86105                 
     106                protected function runFinished():void 
     107                { 
     108                         
     109                } 
     110                 
    87111                private function invokeMethod(method:Method):void 
    88112                { 
  • as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/inter/runners/CompositeRunner.as

    r293 r328  
    3131                private var fName:String; 
    3232                 
     33                private var fIndex:uint; 
     34                private var fNotifier:RunNotifier; 
     35                 
    3336                public function CompositeRunner(name:String) 
    3437                { 
     
    3942                public override function run(notifier:RunNotifier):void 
    4043                { 
    41                         for each (var runner:Runner in fRunners) { 
    42                                 runner.run(notifier); 
     44                        start(); 
     45                        if (fRunners.length == 0) { 
     46                                finish(); 
     47                                return; 
     48                        } 
     49                        fIndex = 0; 
     50                        fNotifier = notifier; 
     51                        runChildRunner(); 
     52                } 
     53                 
     54                protected function runChildRunner():void 
     55                { 
     56                        for (;;) { 
     57                                var runner:Runner = fRunners[fIndex]; 
     58                                runner.run(fNotifier); 
     59                                if (++fIndex <= (fRunners.length - 1)) { 
     60                                        if (!runner.hasFinised) { 
     61                                                runner.addCallback(runChildRunner); 
     62                                                break; 
     63                                        } 
     64                                } 
     65                                else { 
     66                                        finish(); 
     67                                        break; 
     68                                } 
    4369                        } 
    4470                } 
  • as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/inter/runners/ErrorReportingRunner.as

    r293 r328  
    3939                public override function run(notifier:RunNotifier):void 
    4040                { 
     41                        start(); 
    4142                        notifier.testAborted(_description, cause); 
     43                        finish(); 
    4244                } 
    4345        } 
  • as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/inter/runners/OldTestClassRunner.as

    r293 r328  
    5656                public override function run(notifier:RunNotifier):void 
    5757                { 
     58                        start(); 
    5859                        var result:TestResult = new TestResult(); 
    5960                        result.addListener(createAdaptingListener(notifier)); 
    6061                        test.run(result); 
     62                        finish(); 
    6163                } 
    6264                 
  • as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/inter/runners/TestClassMethodsRunner.as

    r293 r328  
    3434                private var fTestClass:Class; 
    3535                 
     36                private var fIndex:uint; 
     37                private var fNotifier:RunNotifier; 
     38                 
    3639                public function TestClassMethodsRunner(klass:Class) 
    3740                { 
     
    4245                public override function run(notifier:RunNotifier):void 
    4346                { 
     47                        start(); 
    4448                        if (testMethods.length == 0) { 
    4549                                notifier.testAborted(description, new Error("No runnable methods")); 
     50                                finish(); 
     51                                return; 
    4652                        } 
    47                         for each (var method:Method in testMethods) { 
    48                                 invokeTestMethod(method, notifier); 
     53                        fIndex = 0; 
     54                        fNotifier = notifier; 
     55                        runTestMethod(); 
     56                } 
     57                 
     58                protected function runTestMethod():void 
     59                { 
     60                        for (;;) { 
     61                                var method:Method = testMethods[fIndex]; 
     62                                var runner:Runner = createTestMethodRunner(method, fNotifier); 
     63                                if (runner != null) { 
     64                                        runner.run(null); 
     65                                } 
     66                                if (++fIndex <= (testMethods.length - 1)) { 
     67                                        if (runner != null && !runner.hasFinised) { 
     68                                                runner.addCallback(runTestMethod); 
     69                                                break; 
     70                                        } 
     71                                } 
     72                                else { 
     73                                        finish(); 
     74                                        break; 
     75                                } 
    4976                        } 
    5077                } 
     
    6996                } 
    7097                 
    71                 protected function invokeTestMethod(method:Method, notifier:RunNotifier):void 
     98                protected function createTestMethodRunner(method:Method, notifier:RunNotifier):TestMethodRunner 
    7299                { 
    73100                        var test:Object; 
     
    77104                        catch (e:Error) { 
    78105                                notifier.testAborted(methodDescription(method), e); 
    79                                 return
     106                                return null
    80107                        } 
    81                         createMethodRunner(test, method, notifier).run(); 
     108                        return createMethodRunner(test, method, notifier); 
    82109                } 
    83110                 
  • as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/inter/runners/TestClassRunner.as

    r293 r328  
    5454                public override function run(notifier:RunNotifier):void 
    5555                { 
     56                        start(); 
    5657                        var runner:BeforeAndAfterRunner = new BeforeClassAndAfterClassRunner( 
    5758                                testClass, enclosedRunner, notifier, description); 
    58                         runner.runProtected(); 
     59                        runner.run(null); 
     60                        if (!runner.hasFinised) { 
     61                                runner.addCallback(finish); 
     62                        } 
     63                        else { 
     64                                finish(); 
     65                        } 
    5966                } 
    6067                 
     
    93100        private var runner:Runner; 
    94101        private var notifier:RunNotifier; 
    95         private var description:Description; 
     102        private var fDescription:Description; 
    96103         
    97104        public function BeforeClassAndAfterClassRunner(klass:Class,  
     
    101108                this.runner = runner; 
    102109                this.notifier = notifier; 
    103                 this.description = description; 
     110                this.fDescription = description; 
     111        } 
     112         
     113        public override function run(n:RunNotifier):void 
     114        { 
     115                start(); 
     116                runProtected(); 
    104117        } 
    105118         
     
    107120        { 
    108121                runner.run(notifier); 
     122                if (!runner.hasFinised) { 
     123                        runner.addCallback(runUnprotectedComplete); 
     124                } 
     125                else { 
     126                        runUnprotectedComplete(); 
     127                } 
     128        } 
     129         
     130        protected override function runFinished():void 
     131        { 
     132                finish(); 
    109133        } 
    110134         
    111135        protected override function addFailure(targetException:Object):void 
    112136        { 
    113                 notifier.fireTestFailure(new Failure(description, targetException)); 
     137                notifier.fireTestFailure(new Failure(fDescription, targetException)); 
    114138        } 
    115139} 
  • as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/inter/runners/TestMethodRunner.as

    r293 r328  
    3232                private var notifier:RunNotifier; 
    3333                private var testIntrospector:TestIntrospector; 
    34                 private var description:Description; 
     34                private var fDescription:Description; 
    3535                 
    3636                public function TestMethodRunner(test:Object, method:Method, notifier:RunNotifier, description:Description) 
     
    4141                        this.notifier = notifier; 
    4242                        testIntrospector = new TestIntrospector(test.constructor); 
    43                         this.description = description; 
     43                        this.fDescription = description; 
    4444                } 
    4545                 
    46                 public function run():void 
     46                public override function run(n:RunNotifier):void 
    4747                { 
     48                        start(); 
    4849                        if (testIntrospector.isIgnored(method)) { 
    49                                 notifier.fireTestIgnored(description); 
     50                                notifier.fireTestIgnored(fDescription); 
     51                                finish(); 
    5052                                return; 
    5153                        } 
    52                         notifier.fireTestStarted(description); 
    53                         try { 
    54                                 runMethod(); 
    55                         } 
    56                         finally { 
    57                                 notifier.fireTestFinished(description); 
    58                         } 
     54                        notifier.fireTestStarted(fDescription); 
     55                        runMethod(); 
    5956                } 
    6057                 
     
    8077                                } 
    8178                        } 
     79                        finally { 
     80                                runUnprotectedComplete(); 
     81                        } 
     82                } 
     83                 
     84                protected override function runFinished():void 
     85                { 
     86                        notifier.fireTestFinished(fDescription); 
     87                        finish(); 
    8288                } 
    8389                 
     
    8995                protected override function addFailure(e:Object):void 
    9096                { 
    91                         notifier.fireTestFailure(new Failure(description, e)); 
     97                        notifier.fireTestFailure(new Failure(fDescription, e)); 
    9298                } 
    9399                 
  • as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/runner/AS3UnitCore.as

    r293 r328  
    108108                        var result:Result = new Result(); 
    109109                        var listener:RunListener = result.createListener(); 
     110                        var needRemoveListener:Boolean = true; 
    110111                        var description:Description = runner.description; 
    111112                        addFirstListener(listener); 
     
    113114                                notifier.fireTestRunStarted(runner.description); 
    114115                                runner.run(notifier); 
    115                 notifier.fireTestRunFinished(result); 
     116                                if (!runner.hasFinised) { 
     117                                        runner.addCallback(function():void 
     118                                        { 
     119                                                notifier.fireTestRunFinished(result); 
     120                                                removeListener(listener); 
     121                                        }); 
     122                                        needRemoveListener = false; 
     123                                } 
     124                                else { 
     125                                        notifier.fireTestRunFinished(result); 
     126                                } 
    116127                        } 
    117128                        finally { 
    118                                 removeListener(listener); 
     129                                if (needRemoveListener) { 
     130                                        removeListener(listener); 
     131                                } 
    119132                        } 
    120133                        return result; 
  • as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/runner/Runner.as

    r293 r328  
    3131        public class Runner 
    3232        { 
     33                private var finished:Boolean = false; 
     34                private var callbacks:Array = []; 
     35                 
    3336                /** 
    3437                 * @return a <code>Description</code> showing the tests to be run by the reciver. 
     
    5760                        return description.testCount; 
    5861                } 
     62                 
     63                /** 
     64                 * @return true if Runner.run has finished. 
     65                 */ 
     66                public function get hasFinised():Boolean 
     67                { 
     68                        return finished; 
     69                } 
     70                 
     71                /** 
     72                 * Add callback for run complete. 
     73                 *  
     74                 * @param       callback 
     75                 */ 
     76                public function addCallback(callback:Function):void 
     77                { 
     78                        callbacks.push(callback); 
     79                        if (finished) { 
     80                                callback(); 
     81                        } 
     82                } 
     83                 
     84                /** 
     85                 * Remove callback. 
     86                 *  
     87                 * @param       callback 
     88                 */ 
     89                public function removeCallback(callback:Function):void 
     90                { 
     91                        var index:int = callbacks.indexOf(callback); 
     92                        if (index != -1) { 
     93                                callbacks.splice(index, 1); 
     94                        } 
     95                } 
     96                 
     97                /** 
     98                 * Begin run process. 
     99                 */ 
     100                protected function start():void 
     101                { 
     102                        finished = false; 
     103                } 
     104                 
     105                /** 
     106                 * End run process. 
     107                 */ 
     108                protected function finish():void 
     109                { 
     110                        finished = true; 
     111                        for each (var callback:Function in callbacks) { 
     112                                callback(); 
     113                        } 
     114                } 
    59115        } 
    60116} 
  • as3/AS3Unit/branches/AS3UnitForAsync/tests/org/libspark/as3unit/tests/TestMethodTest.as

    r293 r328  
    4747                } 
    4848                 
    49                 test function ingoreRunner():void 
     49                test function ignoreRunner():void 
    5050                { 
    5151                        var runner:AS3UnitCore = new AS3UnitCore(); 
  • as3/AS3Unit/branches/AS3UnitForAsync/tests/org/libspark/as3unit/tests/UserStopTest.as

    r293 r328  
    6161                         
    6262                        new TestMethodRunner(this, method, notifier,  
    63                                 Description.createTestDescription(OneTest, 'foo')).run(); 
     63                                Description.createTestDescription(OneTest, 'foo')).run(null); 
    6464                } 
    6565