チェンジセット 328
- コミット日時:
- 2008/04/20 23:44:09 (4 年前)
- ファイル:
-
- as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/inter/runners/BeforeAndAfterRunner.as (更新) (5 diffs)
- as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/inter/runners/CompositeRunner.as (更新) (2 diffs)
- as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/inter/runners/ErrorReportingRunner.as (更新) (1 diff)
- as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/inter/runners/OldTestClassRunner.as (更新) (1 diff)
- as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/inter/runners/TestClassMethodsRunner.as (更新) (4 diffs)
- as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/inter/runners/TestClassRunner.as (更新) (4 diffs)
- as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/inter/runners/TestMethodRunner.as (更新) (4 diffs)
- as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/runner/AS3UnitCore.as (更新) (2 diffs)
- as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/runner/Runner.as (更新) (2 diffs)
- as3/AS3Unit/branches/AS3UnitForAsync/tests/org/libspark/as3unit/tests/TestMethodTest.as (更新) (1 diff)
- as3/AS3Unit/branches/AS3UnitForAsync/tests/org/libspark/as3unit/tests/UserStopTest.as (更新) (1 diff)
凡例:
- 変更無し
- 追加
- 削除
- 更新
- コピー
- 移動
as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/inter/runners/BeforeAndAfterRunner.as
r293 r328 17 17 package org.libspark.as3unit.inter.runners 18 18 { 19 public class BeforeAndAfterRunner 19 import org.libspark.as3unit.runner.Runner; 20 21 public class BeforeAndAfterRunner extends Runner 20 22 { 21 23 private var beforeAnnotation:Namespace; … … 23 25 private var testIntrospector:TestIntrospector; 24 26 private var test:Object; 27 private var unprotectedComplete:Boolean; 25 28 26 29 public function BeforeAndAfterRunner(testClass:Class, … … 39 42 try { 40 43 runBefores(); 41 runUnprotected();42 44 } 43 45 catch (e:FailedBefore) { 46 runUnprotectedComplete(); 47 return; 48 } 49 var noException:Boolean = false; 50 try { 51 unprotectedComplete = false; 52 runUnprotected(); 53 noException = true; 44 54 } 45 55 finally { 46 runAfters(); 56 if (!noException && !runUnprotectedComplete) { 57 runUnprotectedComplete(); 58 } 47 59 } 48 60 } … … 51 63 { 52 64 throw new DefinitionError('Subclass must override this method.'); 65 } 66 67 protected function runUnprotectedComplete():void 68 { 69 unprotectedComplete = true; 70 runAfters(); 71 runFinished(); 53 72 } 54 73 … … 85 104 } 86 105 106 protected function runFinished():void 107 { 108 109 } 110 87 111 private function invokeMethod(method:Method):void 88 112 { as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/inter/runners/CompositeRunner.as
r293 r328 31 31 private var fName:String; 32 32 33 private var fIndex:uint; 34 private var fNotifier:RunNotifier; 35 33 36 public function CompositeRunner(name:String) 34 37 { … … 39 42 public override function run(notifier:RunNotifier):void 40 43 { 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 } 43 69 } 44 70 } as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/inter/runners/ErrorReportingRunner.as
r293 r328 39 39 public override function run(notifier:RunNotifier):void 40 40 { 41 start(); 41 42 notifier.testAborted(_description, cause); 43 finish(); 42 44 } 43 45 } as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/inter/runners/OldTestClassRunner.as
r293 r328 56 56 public override function run(notifier:RunNotifier):void 57 57 { 58 start(); 58 59 var result:TestResult = new TestResult(); 59 60 result.addListener(createAdaptingListener(notifier)); 60 61 test.run(result); 62 finish(); 61 63 } 62 64 as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/inter/runners/TestClassMethodsRunner.as
r293 r328 34 34 private var fTestClass:Class; 35 35 36 private var fIndex:uint; 37 private var fNotifier:RunNotifier; 38 36 39 public function TestClassMethodsRunner(klass:Class) 37 40 { … … 42 45 public override function run(notifier:RunNotifier):void 43 46 { 47 start(); 44 48 if (testMethods.length == 0) { 45 49 notifier.testAborted(description, new Error("No runnable methods")); 50 finish(); 51 return; 46 52 } 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 } 49 76 } 50 77 } … … 69 96 } 70 97 71 protected function invokeTestMethod(method:Method, notifier:RunNotifier):void98 protected function createTestMethodRunner(method:Method, notifier:RunNotifier):TestMethodRunner 72 99 { 73 100 var test:Object; … … 77 104 catch (e:Error) { 78 105 notifier.testAborted(methodDescription(method), e); 79 return ;106 return null; 80 107 } 81 createMethodRunner(test, method, notifier).run();108 return createMethodRunner(test, method, notifier); 82 109 } 83 110 as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/inter/runners/TestClassRunner.as
r293 r328 54 54 public override function run(notifier:RunNotifier):void 55 55 { 56 start(); 56 57 var runner:BeforeAndAfterRunner = new BeforeClassAndAfterClassRunner( 57 58 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 } 59 66 } 60 67 … … 93 100 private var runner:Runner; 94 101 private var notifier:RunNotifier; 95 private var description:Description;102 private var fDescription:Description; 96 103 97 104 public function BeforeClassAndAfterClassRunner(klass:Class, … … 101 108 this.runner = runner; 102 109 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(); 104 117 } 105 118 … … 107 120 { 108 121 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(); 109 133 } 110 134 111 135 protected override function addFailure(targetException:Object):void 112 136 { 113 notifier.fireTestFailure(new Failure( description, targetException));137 notifier.fireTestFailure(new Failure(fDescription, targetException)); 114 138 } 115 139 } as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/inter/runners/TestMethodRunner.as
r293 r328 32 32 private var notifier:RunNotifier; 33 33 private var testIntrospector:TestIntrospector; 34 private var description:Description;34 private var fDescription:Description; 35 35 36 36 public function TestMethodRunner(test:Object, method:Method, notifier:RunNotifier, description:Description) … … 41 41 this.notifier = notifier; 42 42 testIntrospector = new TestIntrospector(test.constructor); 43 this. description = description;43 this.fDescription = description; 44 44 } 45 45 46 public function run():void46 public override function run(n:RunNotifier):void 47 47 { 48 start(); 48 49 if (testIntrospector.isIgnored(method)) { 49 notifier.fireTestIgnored(description); 50 notifier.fireTestIgnored(fDescription); 51 finish(); 50 52 return; 51 53 } 52 notifier.fireTestStarted(description); 53 try { 54 runMethod(); 55 } 56 finally { 57 notifier.fireTestFinished(description); 58 } 54 notifier.fireTestStarted(fDescription); 55 runMethod(); 59 56 } 60 57 … … 80 77 } 81 78 } 79 finally { 80 runUnprotectedComplete(); 81 } 82 } 83 84 protected override function runFinished():void 85 { 86 notifier.fireTestFinished(fDescription); 87 finish(); 82 88 } 83 89 … … 89 95 protected override function addFailure(e:Object):void 90 96 { 91 notifier.fireTestFailure(new Failure( description, e));97 notifier.fireTestFailure(new Failure(fDescription, e)); 92 98 } 93 99 as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/runner/AS3UnitCore.as
r293 r328 108 108 var result:Result = new Result(); 109 109 var listener:RunListener = result.createListener(); 110 var needRemoveListener:Boolean = true; 110 111 var description:Description = runner.description; 111 112 addFirstListener(listener); … … 113 114 notifier.fireTestRunStarted(runner.description); 114 115 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 } 116 127 } 117 128 finally { 118 removeListener(listener); 129 if (needRemoveListener) { 130 removeListener(listener); 131 } 119 132 } 120 133 return result; as3/AS3Unit/branches/AS3UnitForAsync/src/org/libspark/as3unit/runner/Runner.as
r293 r328 31 31 public class Runner 32 32 { 33 private var finished:Boolean = false; 34 private var callbacks:Array = []; 35 33 36 /** 34 37 * @return a <code>Description</code> showing the tests to be run by the reciver. … … 57 60 return description.testCount; 58 61 } 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 } 59 115 } 60 116 } as3/AS3Unit/branches/AS3UnitForAsync/tests/org/libspark/as3unit/tests/TestMethodTest.as
r293 r328 47 47 } 48 48 49 test function i ngoreRunner():void49 test function ignoreRunner():void 50 50 { 51 51 var runner:AS3UnitCore = new AS3UnitCore(); as3/AS3Unit/branches/AS3UnitForAsync/tests/org/libspark/as3unit/tests/UserStopTest.as
r293 r328 61 61 62 62 new TestMethodRunner(this, method, notifier, 63 Description.createTestDescription(OneTest, 'foo')).run( );63 Description.createTestDescription(OneTest, 'foo')).run(null); 64 64 } 65 65

