asunit4 4.2.1.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. data/Gemfile +5 -0
  2. data/MIT-LICENSE.txt +22 -0
  3. data/README.textile +6 -0
  4. data/air/AIR2Runner.mxml +22 -0
  5. data/air/AIR2RunnerDescriptor.xml +38 -0
  6. data/asunit4.gemspec +20 -0
  7. data/asunit4.rb +16 -0
  8. data/bin/AsUnit-4.1.pre.swc +0 -0
  9. data/bin/AsUnitRunner.swf +0 -0
  10. data/build.xml +46 -0
  11. data/lib/Reflection.swc +0 -0
  12. data/rakefile.rb +169 -0
  13. data/script/generate +21 -0
  14. data/src/asunit/asserts/assertEquals.as +5 -0
  15. data/src/asunit/asserts/assertEqualsArrays.as +5 -0
  16. data/src/asunit/asserts/assertEqualsArraysIgnoringOrder.as +5 -0
  17. data/src/asunit/asserts/assertEqualsFloat.as +5 -0
  18. data/src/asunit/asserts/assertFalse.as +5 -0
  19. data/src/asunit/asserts/assertNotNull.as +5 -0
  20. data/src/asunit/asserts/assertNotSame.as +5 -0
  21. data/src/asunit/asserts/assertNull.as +5 -0
  22. data/src/asunit/asserts/assertSame.as +5 -0
  23. data/src/asunit/asserts/assertThrows.as +5 -0
  24. data/src/asunit/asserts/assertTrue.as +5 -0
  25. data/src/asunit/asserts/fail.as +5 -0
  26. data/src/asunit/core/AsUnitCore.as +177 -0
  27. data/src/asunit/core/FlashBuilderCore.as +22 -0
  28. data/src/asunit/core/FlashDevelopCore.as +21 -0
  29. data/src/asunit/core/TextCore.as +54 -0
  30. data/src/asunit/errors/AbstractError.as +10 -0
  31. data/src/asunit/errors/AssertionFailedError.as +10 -0
  32. data/src/asunit/errors/ClassNotFoundError.as +11 -0
  33. data/src/asunit/errors/InstanceNotFoundError.as +10 -0
  34. data/src/asunit/errors/UnimplementedFeatureError.as +10 -0
  35. data/src/asunit/errors/UsageError.as +11 -0
  36. data/src/asunit/events/TimeoutCommandEvent.as +27 -0
  37. data/src/asunit/framework/Assert.as +408 -0
  38. data/src/asunit/framework/Async.as +138 -0
  39. data/src/asunit/framework/CallbackBridge.as +175 -0
  40. data/src/asunit/framework/Command.as +6 -0
  41. data/src/asunit/framework/ErrorEvent.as +20 -0
  42. data/src/asunit/framework/IAsync.as +21 -0
  43. data/src/asunit/framework/IResult.as +36 -0
  44. data/src/asunit/framework/IRunListener.as +11 -0
  45. data/src/asunit/framework/IRunner.as +15 -0
  46. data/src/asunit/framework/IRunnerFactory.as +9 -0
  47. data/src/asunit/framework/ITestFailure.as +32 -0
  48. data/src/asunit/framework/ITestListener.as +15 -0
  49. data/src/asunit/framework/ITestResult.as +21 -0
  50. data/src/asunit/framework/ITestSuccess.as +22 -0
  51. data/src/asunit/framework/ITestWarning.as +14 -0
  52. data/src/asunit/framework/InjectionDelegate.as +96 -0
  53. data/src/asunit/framework/LegacyTestIterator.as +40 -0
  54. data/src/asunit/framework/MessageBridge.as +24 -0
  55. data/src/asunit/framework/Method.as +80 -0
  56. data/src/asunit/framework/Result.as +181 -0
  57. data/src/asunit/framework/RunnerFactory.as +179 -0
  58. data/src/asunit/framework/SuiteIterator.as +71 -0
  59. data/src/asunit/framework/TestCase.as +106 -0
  60. data/src/asunit/framework/TestFailure.as +65 -0
  61. data/src/asunit/framework/TestIterator.as +282 -0
  62. data/src/asunit/framework/TestObserver.as +12 -0
  63. data/src/asunit/framework/TestSuccess.as +38 -0
  64. data/src/asunit/framework/TestWarning.as +40 -0
  65. data/src/asunit/framework/TimeoutCommand.as +103 -0
  66. data/src/asunit/printers/FlashBuilderPrinter.as +134 -0
  67. data/src/asunit/printers/FlashDevelopPrinter.as +81 -0
  68. data/src/asunit/printers/TextPrinter.as +324 -0
  69. data/src/asunit/runners/LegacyRunner.as +13 -0
  70. data/src/asunit/runners/SuiteRunner.as +125 -0
  71. data/src/asunit/runners/TestRunner.as +403 -0
  72. data/src/asunit/util/ArrayIterator.as +30 -0
  73. data/src/asunit/util/Iterator.as +10 -0
  74. data/test/AllTests.as +73 -0
  75. data/test/AsUnitRunner.as +15 -0
  76. data/test/Flex3Runner.mxml +24 -0
  77. data/test/Flex4Runner.mxml +27 -0
  78. data/test/asunit/core/AsUnitCoreTest.as +97 -0
  79. data/test/asunit/framework/AssertEqualsArraysIgnoringOrderTest.as +88 -0
  80. data/test/asunit/framework/AssertEqualsArraysTest.as +102 -0
  81. data/test/asunit/framework/AssertTest.as +184 -0
  82. data/test/asunit/framework/AssertThrowsTest.as +42 -0
  83. data/test/asunit/framework/AsyncMethodTest.as +69 -0
  84. data/test/asunit/framework/AsyncTest.as +104 -0
  85. data/test/asunit/framework/CallbackBridgeTest.as +73 -0
  86. data/test/asunit/framework/InjectionDelegateTest.as +79 -0
  87. data/test/asunit/framework/MockData.xml +8 -0
  88. data/test/asunit/framework/NestedSuiteIteratorTest.as +59 -0
  89. data/test/asunit/framework/ProceedOnEventTest.as +109 -0
  90. data/test/asunit/framework/ResultTest.as +92 -0
  91. data/test/asunit/framework/RunnerFactoryTest.as +54 -0
  92. data/test/asunit/framework/SuiteIteratorTest.as +67 -0
  93. data/test/asunit/framework/TestCaseMock.as +24 -0
  94. data/test/asunit/framework/TestIteratorIgnoredMethodTest.as +62 -0
  95. data/test/asunit/framework/TestIteratorMethodByNameTest.as +50 -0
  96. data/test/asunit/framework/TestIteratorMultiMethodTest.as +186 -0
  97. data/test/asunit/framework/TestIteratorOrderedTestMethodTest.as +57 -0
  98. data/test/asunit/framework/TestIteratorSingleMethodTest.as +56 -0
  99. data/test/asunit/framework/VisualTestCaseTest.as +43 -0
  100. data/test/asunit/framework/assertAssertionFailed.as +19 -0
  101. data/test/asunit/printers/TextPrinterTest.as +122 -0
  102. data/test/asunit/runners/LegacyRunnerTest.as +40 -0
  103. data/test/asunit/runners/SuiteRunnerTest.as +40 -0
  104. data/test/asunit/runners/TestRunnerAsyncMethodTest.as +107 -0
  105. data/test/asunit/runners/TestRunnerErrorMethodTest.as +56 -0
  106. data/test/asunit/runners/TestRunnerExpectsErrorTest.as +98 -0
  107. data/test/asunit/runners/TestRunnerIgnoredMethodTest.as +42 -0
  108. data/test/asunit/runners/TestRunnerTest.as +171 -0
  109. data/test/asunit/support/AnnotatedSubClass.as +18 -0
  110. data/test/asunit/support/AnnotatedSuperClass.as +15 -0
  111. data/test/asunit/support/CustomParameters.as +13 -0
  112. data/test/asunit/support/CustomTestRunner.as +22 -0
  113. data/test/asunit/support/DoubleFailSuite.as +8 -0
  114. data/test/asunit/support/DoubleNestedSuite.as +14 -0
  115. data/test/asunit/support/ErrorInMethod.as +11 -0
  116. data/test/asunit/support/FailAssertEquals.as +29 -0
  117. data/test/asunit/support/FailAssertTrue.as +28 -0
  118. data/test/asunit/support/FakeObserver.as +42 -0
  119. data/test/asunit/support/FakeRunner.as +32 -0
  120. data/test/asunit/support/IgnoredMethod.as +26 -0
  121. data/test/asunit/support/InjectTimeoutOnAsync.as +14 -0
  122. data/test/asunit/support/InjectionFailure.as +18 -0
  123. data/test/asunit/support/InjectionVerification.as +69 -0
  124. data/test/asunit/support/LegacyTestCase.as +38 -0
  125. data/test/asunit/support/MultiMethod.as +77 -0
  126. data/test/asunit/support/OrderedTestMethod.as +36 -0
  127. data/test/asunit/support/RunWithButNoType.as +14 -0
  128. data/test/asunit/support/RunWithSuiteButNoType.as +11 -0
  129. data/test/asunit/support/SingleErrorSuite.as +7 -0
  130. data/test/asunit/support/SingleSuccessSuite.as +7 -0
  131. data/test/asunit/support/SucceedAssertTrue.as +31 -0
  132. data/test/asunit/support/SuiteOfTwoSuites.as +8 -0
  133. data/test/asunit/support/SuiteWithCustomRunner.as +12 -0
  134. data/test/asunit/support/SuiteWithOneCustomChildSuite.as +10 -0
  135. data/test/asunit/support/TestForFakeRunner.as +14 -0
  136. data/test/asunit/util/ArrayIteratorTest.as +65 -0
  137. data/vendor/as3reflection/README +7 -0
  138. data/vendor/as3reflection/p2/reflect/Reflection.as +417 -0
  139. data/vendor/as3reflection/p2/reflect/ReflectionAccessor.as +14 -0
  140. data/vendor/as3reflection/p2/reflect/ReflectionBase.as +52 -0
  141. data/vendor/as3reflection/p2/reflect/ReflectionMember.as +16 -0
  142. data/vendor/as3reflection/p2/reflect/ReflectionMetaData.as +69 -0
  143. data/vendor/as3reflection/p2/reflect/ReflectionMethod.as +36 -0
  144. data/vendor/as3reflection/p2/reflect/ReflectionMethodParameter.as +19 -0
  145. data/vendor/as3reflection/p2/reflect/ReflectionVariable.as +15 -0
  146. data/vendor/as3reflection/p2/reflect/findFirst.as +14 -0
  147. data/vendor/generators/suite/USAGE +0 -0
  148. data/vendor/generators/suite/suite_generator.rb +17 -0
  149. data/vendor/generators/suite/templates/TestSuite.as +17 -0
  150. metadata +216 -0
@@ -0,0 +1,24 @@
1
+ package asunit.framework {
2
+
3
+ /**
4
+ * MessageBridge is a marker interface that is used
5
+ * by AsUnit core in order to support custom messaging
6
+ * schemes between TestObservers and IRunners.
7
+ *
8
+ * The idea is that you [Inject] one or more entities
9
+ * into your concrete IRunner and related TestObservers.
10
+ *
11
+ * The contract is between the concrete MessageBridge,
12
+ * and the other actors that [Inject] it into.
13
+ *
14
+ * This implementation gives AsUnit the ability to support
15
+ * a variety of messaging protocols including native
16
+ * Flash EventDispatchers, callbacks, and even progressive
17
+ * systems like AS3Signals. The decision as to which
18
+ * messaging system to use is made by the person creating
19
+ * the concrete Runner and Observer.
20
+ */
21
+ public interface MessageBridge {
22
+ }
23
+ }
24
+
@@ -0,0 +1,80 @@
1
+ package asunit.framework {
2
+
3
+ import p2.reflect.Reflection;
4
+ import p2.reflect.ReflectionMethod;
5
+ import p2.reflect.ReflectionMetaData;
6
+
7
+ public class Method {
8
+
9
+ private var _scopeName:String;
10
+
11
+ public var expects:String;
12
+ public var ignore:Boolean;
13
+ public var ignoreDescription:String;
14
+ public var metadata:ReflectionMetaData;
15
+ public var name:String;
16
+ public var order:int = 0;
17
+ public var scope:Object;
18
+ public var timeout:int = -1;
19
+ public var value:Function;
20
+
21
+ public function Method(scope:Object, reflection:ReflectionMethod) {
22
+ this.scope = scope;
23
+ this.name = reflection.name;
24
+ this.value = scope[reflection.name];
25
+
26
+ metadata = reflection.getMetaDataByName('Test');
27
+
28
+ if(metadata != null) {
29
+ var ignoreReflection:ReflectionMetaData = reflection.getMetaDataByName('Ignore');
30
+ if(ignoreReflection) {
31
+ ignore = true;
32
+ ignoreDescription = ignoreReflection.getValueFor('description');
33
+ }
34
+
35
+ handleTimeoutMetaData();
36
+ applyMetaData('expects');
37
+ applyMetaData('order');
38
+ }
39
+ }
40
+
41
+ public function get scopeName():String {
42
+ return _scopeName ||= Reflection.create(scope).name
43
+ }
44
+
45
+ private function handleTimeoutMetaData():void {
46
+ var value:* = metadata.getValueFor('timeout');
47
+ if(value != null) {
48
+ var message:String = "It seems you're using [Test(timeout=n)] for " + name + ", but this has been deprecated.\n";
49
+ message += "If you'd like to set a different timeout value, please send it to your Async instance methods like: async.add(null, timeoutInMilliseconds)";
50
+ trace("[DEPRECATION WARNING] " + message);
51
+ }
52
+ }
53
+
54
+ // The null response for timeout was updating the
55
+ // int field to zero when it needs to be -1...
56
+ private function applyMetaData(name:String):void {
57
+ var value:* = metadata.getValueFor(name);
58
+ if(value != null) {
59
+ this[name] = value;
60
+ }
61
+ }
62
+
63
+ public function execute():void {
64
+ value.call(scope);
65
+ }
66
+
67
+ public function get isTest():Boolean {
68
+ return (metadata != null || isLegacyTest);
69
+ }
70
+
71
+ public function get isLegacyTest():Boolean {
72
+ return (metadata == null && name.match(/^test/));
73
+ }
74
+
75
+ public function toString():String {
76
+ return name;
77
+ }
78
+ }
79
+ }
80
+
@@ -0,0 +1,181 @@
1
+ package asunit.framework {
2
+
3
+ import asunit.errors.UsageError;
4
+ import asunit.framework.ITestFailure;
5
+
6
+ import flash.events.EventDispatcher;
7
+ import flash.utils.Dictionary;
8
+
9
+ /**
10
+ * A <code>Result</code> collects the results of executing
11
+ * a test case. It is an instance of the Collecting Parameter pattern.
12
+ * The test framework distinguishes between <i>failures</i> and <i>errors</i>.
13
+ * A failure is anticipated and checked for with assertions. Errors are
14
+ * unanticipated problems like an <code>ArrayIndexOutOfBoundsException</code>.
15
+ *
16
+ * @see Test
17
+ */
18
+ public class Result extends EventDispatcher implements IResult {
19
+
20
+ protected var _runCount:uint = 0;
21
+ protected var _runTime:Number;
22
+ protected var _errors:Array;
23
+ protected var _failures:Array;
24
+ protected var _ignoredTests:Array;
25
+ protected var _successes:Array;
26
+ protected var _warnings:Array;
27
+
28
+ protected var listeners:Array;
29
+ protected var runComplete:Boolean;
30
+ protected var knownTests:Dictionary;
31
+
32
+ public function Result() {
33
+ _errors = [];
34
+ _failures = [];
35
+ _ignoredTests = [];
36
+ _successes = [];
37
+ _warnings = [];
38
+ listeners = [];
39
+ knownTests = new Dictionary();
40
+ }
41
+
42
+ public function get errors():Array { return _errors; }
43
+
44
+ /**
45
+ * Gets the number of detected errors.
46
+ */
47
+ public function get errorCount():uint { return _errors.length; }
48
+
49
+ /**
50
+ *
51
+ */
52
+ public function get failures():Array { return _failures; }
53
+
54
+ /**
55
+ * Gets the number of detected failures.
56
+ */
57
+ public function get failureCount():uint { return _failures.length; }
58
+
59
+ public function get successes():Array { return _successes; }
60
+
61
+ public function get successCount():uint { return _successes.length; }
62
+
63
+ public function get warnings():Array { return _warnings; }
64
+
65
+ public function get ignoredTests():Array { return _ignoredTests; }
66
+
67
+ public function get ignoredTestCount():uint { return _ignoredTests.length; }
68
+
69
+ public function get runCount():uint {
70
+ return errorCount + failureCount + successCount;
71
+ }
72
+
73
+ public function get runTime():Number { return _runTime; }
74
+ public function set runTime(value:Number):void { _runTime = value; }
75
+
76
+ public function shouldRunTest(testClass:Class):Boolean {
77
+ if(!knownTests[testClass]) {
78
+ knownTests[testClass] = testClass;
79
+ return true;
80
+ }
81
+ return false;
82
+ }
83
+
84
+ public function addObserver(observer:TestObserver):void {
85
+ if(!(observer is IRunListener)) {
86
+ throw new UsageError("Result.addObserver called with an instance that wasn't an IRunListener. This should work soon, but doesn't yet...");
87
+ }
88
+ addListener(IRunListener(observer));
89
+ }
90
+
91
+ public function addListener(listener:IRunListener):void {
92
+ if (listeners.indexOf(listener) >= 0) return;
93
+ listeners.push(listener);
94
+ }
95
+
96
+ public function removeListener(listener:IRunListener):void {
97
+ listeners.splice(listeners.indexOf(listener), 1);
98
+ }
99
+
100
+ public function onRunStarted():void {
101
+ for each (var listener:IRunListener in listeners) {
102
+ listener.onRunStarted();
103
+ }
104
+ }
105
+
106
+ public function onRunCompleted(result:IResult):void {
107
+ runComplete = true;
108
+ for each (var listener:IRunListener in listeners) {
109
+ listener.onRunCompleted(this);
110
+ }
111
+ }
112
+
113
+ public function onTestStarted(test:Object):void {
114
+ for each (var listener:IRunListener in listeners) {
115
+ listener.onTestStarted(test);
116
+ }
117
+ }
118
+
119
+ public function onTestCompleted(test:Object):void {
120
+ for each (var listener:IRunListener in listeners) {
121
+ listener.onTestCompleted(test);
122
+ }
123
+ }
124
+
125
+ /**
126
+ * Adds a failure to the list of failures. The passed in exception
127
+ * caused the failure.
128
+ */
129
+ public function onTestFailure(failure:ITestFailure):void {
130
+ if (failure.isFailure)
131
+ _failures.push(failure);
132
+ else
133
+ _errors.push(failure);
134
+
135
+ for each (var listener:IRunListener in listeners) {
136
+ listener.onTestFailure(failure);
137
+ }
138
+ }
139
+
140
+ public function onTestSuccess(success:ITestSuccess):void {
141
+ _successes.push(success);
142
+
143
+ for each (var listener:IRunListener in listeners) {
144
+ listener.onTestSuccess(success);
145
+ }
146
+ }
147
+
148
+ public function onTestIgnored(method:Method):void {
149
+ _ignoredTests.push(method);
150
+
151
+ for each (var listener:IRunListener in listeners) {
152
+ listener.onTestIgnored(method);
153
+ }
154
+ }
155
+
156
+ public function onWarning(warning:ITestWarning):void {
157
+ _warnings.push(warning);
158
+
159
+ for each (var listener:IRunListener in listeners) {
160
+ listener.onWarning(warning);
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Returns whether or not we have yet encountered a failure or error.
166
+ * Will be accurate when checked at any time during test run.
167
+ */
168
+ public function get failureEncountered():Boolean {
169
+ return (failureCount > 0 || errorCount > 0);
170
+ }
171
+
172
+ /**
173
+ * Returns whether or not the entire test was successful.
174
+ * Will only return true after +onRunCompleted+ called.
175
+ */
176
+ public function get wasSuccessful():Boolean {
177
+ return (runComplete && !failureEncountered);
178
+ }
179
+
180
+ }
181
+ }
@@ -0,0 +1,179 @@
1
+ package asunit.framework {
2
+
3
+ import asunit.errors.UsageError;
4
+ import asunit.runners.LegacyRunner;
5
+ import asunit.runners.TestRunner;
6
+ import asunit.runners.SuiteRunner;
7
+
8
+ import flash.utils.getDefinitionByName;
9
+
10
+ import p2.reflect.Reflection;
11
+ import p2.reflect.ReflectionMetaData;
12
+ import asunit.framework.InjectionDelegate;
13
+
14
+ public class RunnerFactory implements IRunnerFactory {
15
+
16
+ public static var DEFAULT_SUITE_RUNNER:Class = SuiteRunner;
17
+ public static var DEFAULT_TEST_RUNNER:Class = TestRunner;
18
+
19
+ /**
20
+ * The DefaultTestRunner will be updated whenever
21
+ * a TestSuite is encountered that has a [RunWith]
22
+ * declaration.
23
+ *
24
+ * All subsequent create calls for a Test that
25
+ * don't have a RunWith will use the IRunner that
26
+ * was defined on the Suite.
27
+ *
28
+ */
29
+ public var DefaultTestRunner:Class;
30
+
31
+ /**
32
+ * The DefaultSuiteRunner is what
33
+ * we use for all TestSuites
34
+ */
35
+ public var DefaultSuiteRunner:Class;
36
+
37
+ public function RunnerFactory() {
38
+ DefaultSuiteRunner = DEFAULT_SUITE_RUNNER;
39
+ DefaultTestRunner = DEFAULT_TEST_RUNNER;
40
+ injector = new InjectionDelegate();
41
+ }
42
+
43
+ private var _injector:InjectionDelegate;
44
+
45
+ public function get injector():InjectionDelegate
46
+ {
47
+ return _injector;
48
+ }
49
+
50
+ public function set injector(value:InjectionDelegate):void
51
+ {
52
+ _injector = value;
53
+ }
54
+
55
+ /**
56
+ * runnerFor is the primary inerface to the RunnerFactory
57
+ */
58
+ public function runnerFor(testOrSuite:Class):IRunner {
59
+ //trace(">> runnerFor: " + testOrSuite + " with current default of: " + DefaultTestRunner);
60
+ validate(testOrSuite);
61
+ return getRunnerForTestOrSuite(testOrSuite);
62
+ }
63
+
64
+ protected function validate(testOrSuite:Class):void {
65
+ if(testOrSuite == null) {
66
+ throw new UsageError("RunnerFactory.runnerFor must be provided with a known test or suite class");
67
+ }
68
+ }
69
+
70
+ protected function getRunnerForTestOrSuite(testOrSuite:Class):IRunner {
71
+ var reflection:Reflection = Reflection.create(testOrSuite);
72
+ if(RunnerFactory.isSuite(reflection)) {
73
+ return getRunnerForSuite(reflection);
74
+ }
75
+ else if(RunnerFactory.isLegacyTest(reflection)) {
76
+ return getLegacyRunnerForTest(reflection);
77
+ }
78
+ else if(RunnerFactory.isTest(reflection)) {
79
+ return getRunnerForTest(reflection);
80
+ }
81
+
82
+ throw new UsageError("RunnerFactory was asked for a Runner, but was not able to identify: " + reflection.name + " as a LegacyTest, Test or Suite.");
83
+ return null;
84
+ }
85
+
86
+ protected function getRunnerForSuite(reflection:Reflection):IRunner {
87
+ // First update the DefaultTestRunner with the provided RunWith
88
+ // if necessary...
89
+ var Constructor:Class = getRunWithConstructor(reflection);
90
+ if(Constructor) {
91
+ DefaultTestRunner = Constructor;
92
+ }
93
+ // Always return the default Suite Runner:
94
+ var runner:IRunner = new DefaultSuiteRunner();
95
+ configureRunner(runner);
96
+ return runner;
97
+ }
98
+
99
+ protected function getLegacyRunnerForTest(reflection:Reflection):IRunner {
100
+ var runner:IRunner = new LegacyRunner();
101
+ configureRunner(runner);
102
+ return runner;
103
+ }
104
+
105
+ protected function getRunnerForTest(reflection:Reflection):IRunner {
106
+ // Use the provided RunWith class, or the DefaultTestRunner (this may
107
+ // have been overridden by a parent Suite
108
+ var Constructor:Class = getRunWithConstructor(reflection) || DefaultTestRunner;
109
+ //FIXME: This will choke if given a class with constructor arguments!
110
+ var runner:IRunner = new Constructor();
111
+ configureRunner(runner);
112
+ return runner;
113
+ }
114
+
115
+ protected function getRunWithConstructor(reflection:Reflection):Class {
116
+ var runWith:ReflectionMetaData = getRunWithDeclaration(reflection);
117
+
118
+ if(runWith) {
119
+ if(runWith.args.length == 0) {
120
+ throw new UsageError("Encountered [RunWith] declaration that's missing the class argument. Try [RunWith(my.class.Name)] instead.");
121
+ }
122
+ try {
123
+ var className:String = runWith.args[0];
124
+ return getDefinitionByName(className) as Class;
125
+ }
126
+ catch(e:ReferenceError) {
127
+ var message:String = "Encountered [RunWith] declaration but cannot instantiate the provided runner. " + className + ". ";
128
+ message += "Is there an actual reference to this class somewhere in your project?";
129
+ throw new UsageError(message);
130
+ }
131
+ }
132
+
133
+ return null;
134
+ }
135
+
136
+ protected function getRunWithDeclaration(reflection:Reflection):ReflectionMetaData {
137
+ var result:ReflectionMetaData = reflection.getMetaDataByName('RunWith');
138
+ if(result) {
139
+ return result;
140
+ }
141
+
142
+ var baseClass:*;
143
+ var baseClassReflection:Reflection;
144
+ var len:int = reflection.extendedClasses.length;
145
+ for(var i:int; i < len; i++) {
146
+ baseClass = getDefinitionByName(reflection.extendedClasses[i]);
147
+ baseClassReflection = Reflection.create(baseClass);
148
+ result = baseClassReflection.getMetaDataByName('RunWith');
149
+ if(result) {
150
+ return result;
151
+ }
152
+ }
153
+ return null;
154
+ }
155
+
156
+ /**
157
+ * @private
158
+ */
159
+ protected function configureRunner(runner:IRunner):void
160
+ {
161
+ runner.factory = this;
162
+ injector.updateInjectionPoints(runner, InjectionDelegate.THROW_ERROR_ON_MISSING_INJECTION_POINT);
163
+ }
164
+
165
+ public static function isSuite(reflection:Reflection):Boolean {
166
+ return (reflection.getMetaDataByName('Suite') != null);
167
+ }
168
+
169
+ public static function isLegacyTest(reflection:Reflection):Boolean {
170
+ return reflection.isA('asunit.framework.TestCase');
171
+ }
172
+
173
+ public static function isTest(reflection:Reflection):Boolean {
174
+ var testMethods:Array = reflection.getMethodsByMetaData('Test');
175
+ var runWith:ReflectionMetaData = reflection.getMetaDataByName('RunWith');
176
+ return (runWith != null || testMethods.length > 0);
177
+ }
178
+ }
179
+ }
@@ -0,0 +1,71 @@
1
+ package asunit.framework {
2
+
3
+ import asunit.util.Iterator;
4
+
5
+ import flash.utils.getDefinitionByName;
6
+
7
+ import p2.reflect.Reflection;
8
+ import p2.reflect.ReflectionVariable;
9
+ import p2.reflect.ReflectionMetaData;
10
+
11
+ public class SuiteIterator implements Iterator {
12
+
13
+ protected var index:int;
14
+ protected var list:Array;
15
+
16
+ public function SuiteIterator(Suite:Class, bridge:CallbackBridge=null) {
17
+ list = getTestClasses(Suite, bridge);
18
+ }
19
+
20
+ private function getTestClasses(Suite:Class, bridge:CallbackBridge=null):Array {
21
+ if(bridge == null) bridge = new CallbackBridge();
22
+
23
+ var reflection:Reflection = Reflection.create(Suite);
24
+
25
+ if(!isSuite(reflection) && isTest(reflection)) {
26
+ return [Suite];
27
+ }
28
+
29
+ var variable:ReflectionVariable;
30
+ var TestConstructor:Class;
31
+ var response:Array = [];
32
+ for each(variable in reflection.variables) {
33
+ TestConstructor = Class(getDefinitionByName(variable.type));
34
+ if(isSuite(Reflection.create(TestConstructor))) {
35
+ response = response.concat( getTestClasses(TestConstructor, bridge) );
36
+ }
37
+ else if(bridge.shouldRunTest(TestConstructor)) {
38
+ response.push(TestConstructor);
39
+ }
40
+ }
41
+ response.sort();
42
+ return response;
43
+ }
44
+
45
+ public function get length():uint {
46
+ return list.length;
47
+ }
48
+
49
+ private function isSuite(reflection:Reflection):Boolean {
50
+ return RunnerFactory.isSuite(reflection);
51
+ }
52
+
53
+ private function isTest(reflection:Reflection):Boolean {
54
+ return RunnerFactory.isTest(reflection);
55
+ }
56
+
57
+ public function hasNext():Boolean {
58
+ return list[index] != null;
59
+ }
60
+
61
+ // Returns a Class reference:
62
+ public function next():* {
63
+ return list[index++];
64
+ }
65
+
66
+ public function reset():void {
67
+ index = 0;
68
+ }
69
+ }
70
+ }
71
+
@@ -0,0 +1,106 @@
1
+ package asunit.framework {
2
+
3
+ import asunit.framework.Assert;
4
+ import asunit.framework.IAsync;
5
+
6
+ import flash.display.DisplayObject;
7
+ import flash.display.DisplayObjectContainer;
8
+ import flash.display.Sprite;
9
+
10
+ [RunWith("asunit.runners.LegacyRunner")]
11
+ public class TestCase {
12
+
13
+ public function TestCase(testMethod:String=null) {
14
+ }
15
+
16
+ [Inject]
17
+ public var asyncDelegate:IAsync;
18
+
19
+ [Inject]
20
+ public var context:Sprite;
21
+
22
+ [Before]
23
+ public function callSetUp():void {
24
+ setUp();
25
+ }
26
+
27
+ protected function setUp():void {
28
+ }
29
+
30
+ [After]
31
+ public function callTearDown():void {
32
+ tearDown();
33
+ }
34
+
35
+ protected function tearDown():void {
36
+ }
37
+
38
+ protected function addAsync(handler:Function, timeout:int=-1):Function {
39
+ return asyncDelegate.add(handler, timeout);
40
+ }
41
+
42
+ protected function getContext():DisplayObjectContainer {
43
+ return context;
44
+ }
45
+
46
+ protected function addChild(child:DisplayObject):DisplayObject {
47
+ context.addChild(child);
48
+ return child;
49
+ }
50
+
51
+ protected function removeChild(child:DisplayObject):DisplayObject {
52
+ if(child && child.parent === context) {
53
+ context.removeChild(child);
54
+ }
55
+ return child;
56
+ }
57
+
58
+ protected function assertTrue(...args:Array):void {
59
+ Assert.assertTrue.apply(null, args);
60
+ }
61
+
62
+ public function assertFalse(...args:Array):void {
63
+ Assert.assertFalse.apply(null, args);
64
+ }
65
+
66
+ protected function fail(message:String):void {
67
+ Assert.fail(message);
68
+ }
69
+
70
+ protected function assertThrows(errorType:Class, block:Function):void {
71
+ Assert.assertThrows(errorType, block);
72
+ }
73
+
74
+ protected function assertEquals(...args:Array):void {
75
+ Assert.assertEquals.apply(null, args);
76
+ }
77
+
78
+ protected function assertNotNull(...args:Array):void {
79
+ Assert.assertNotNull.apply(null, args);
80
+ }
81
+
82
+ protected function assertNull(...args:Array):void {
83
+ Assert.assertNull.apply(null, args);
84
+ }
85
+
86
+ protected function assertSame(...args:Array):void {
87
+ Assert.assertSame.apply(null, args);
88
+ }
89
+
90
+ protected function assertNotSame(...args:Array):void {
91
+ Assert.assertNotSame.apply(null, args);
92
+ }
93
+
94
+ protected function assertEqualsFloat(...args:Array):void {
95
+ Assert.assertEquals.apply(null, args);
96
+ }
97
+
98
+ protected function assertEqualsArrays(...args:Array):void {
99
+ Assert.assertEqualsArrays.apply(null, args);
100
+ }
101
+
102
+ protected function assertEqualsArraysIgnoringOrder(...args:Array):void {
103
+ Assert.assertEqualsArraysIgnoringOrder.apply(null, args);
104
+ }
105
+ }
106
+ }
@@ -0,0 +1,65 @@
1
+ package asunit.framework {
2
+ import asunit.errors.AssertionFailedError;
3
+ import flash.utils.getQualifiedClassName;
4
+ import asunit.framework.ITestFailure;
5
+
6
+ /**
7
+ * A <code>TestFailure</code> collects a failed test together with
8
+ * the caught exception.
9
+ * @see Result
10
+ */
11
+ public class TestFailure implements ITestFailure {
12
+ protected var _failedTest:Object;
13
+ protected var _failedMethod:String;
14
+ protected var _thrownException:Error;
15
+
16
+ /**
17
+ * Constructs a TestFailure with the given test and exception.
18
+ */
19
+ public function TestFailure(failedTest:Object, methodName:String, thrownException:Error) {
20
+ _failedTest = failedTest;
21
+ _failedMethod = methodName;
22
+ _thrownException = thrownException;
23
+ }
24
+
25
+ public function get failedFeature():String {
26
+ return getQualifiedClassName(_failedTest) + '.' + _failedMethod;
27
+ }
28
+
29
+ public function get failedMethod():String {
30
+ return _failedMethod;
31
+ }
32
+
33
+ public function set failedMethod(value:String):void {
34
+ _failedMethod = value;
35
+ }
36
+
37
+ /**
38
+ * Gets the failed test case.
39
+ */
40
+ public function get failedTest():Object {
41
+ return _failedTest;
42
+ }
43
+ /**
44
+ * Gets the thrown exception.
45
+ */
46
+ public function get thrownException():Error {
47
+ return _thrownException;
48
+ }
49
+ /**
50
+ * Returns a short description of the failure.
51
+ */
52
+ public function toString():String {
53
+ return '[TestFailure ' + failedMethod + ']';
54
+ }
55
+
56
+ public function get exceptionMessage():String {
57
+ return thrownException.message;
58
+ }
59
+
60
+ public function get isFailure():Boolean {
61
+ return thrownException is AssertionFailedError;
62
+ }
63
+
64
+ }
65
+ }