asunit4 4.2.1.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +5 -0
- data/MIT-LICENSE.txt +22 -0
- data/README.textile +6 -0
- data/air/AIR2Runner.mxml +22 -0
- data/air/AIR2RunnerDescriptor.xml +38 -0
- data/asunit4.gemspec +20 -0
- data/asunit4.rb +16 -0
- data/bin/AsUnit-4.1.pre.swc +0 -0
- data/bin/AsUnitRunner.swf +0 -0
- data/build.xml +46 -0
- data/lib/Reflection.swc +0 -0
- data/rakefile.rb +169 -0
- data/script/generate +21 -0
- data/src/asunit/asserts/assertEquals.as +5 -0
- data/src/asunit/asserts/assertEqualsArrays.as +5 -0
- data/src/asunit/asserts/assertEqualsArraysIgnoringOrder.as +5 -0
- data/src/asunit/asserts/assertEqualsFloat.as +5 -0
- data/src/asunit/asserts/assertFalse.as +5 -0
- data/src/asunit/asserts/assertNotNull.as +5 -0
- data/src/asunit/asserts/assertNotSame.as +5 -0
- data/src/asunit/asserts/assertNull.as +5 -0
- data/src/asunit/asserts/assertSame.as +5 -0
- data/src/asunit/asserts/assertThrows.as +5 -0
- data/src/asunit/asserts/assertTrue.as +5 -0
- data/src/asunit/asserts/fail.as +5 -0
- data/src/asunit/core/AsUnitCore.as +177 -0
- data/src/asunit/core/FlashBuilderCore.as +22 -0
- data/src/asunit/core/FlashDevelopCore.as +21 -0
- data/src/asunit/core/TextCore.as +54 -0
- data/src/asunit/errors/AbstractError.as +10 -0
- data/src/asunit/errors/AssertionFailedError.as +10 -0
- data/src/asunit/errors/ClassNotFoundError.as +11 -0
- data/src/asunit/errors/InstanceNotFoundError.as +10 -0
- data/src/asunit/errors/UnimplementedFeatureError.as +10 -0
- data/src/asunit/errors/UsageError.as +11 -0
- data/src/asunit/events/TimeoutCommandEvent.as +27 -0
- data/src/asunit/framework/Assert.as +408 -0
- data/src/asunit/framework/Async.as +138 -0
- data/src/asunit/framework/CallbackBridge.as +175 -0
- data/src/asunit/framework/Command.as +6 -0
- data/src/asunit/framework/ErrorEvent.as +20 -0
- data/src/asunit/framework/IAsync.as +21 -0
- data/src/asunit/framework/IResult.as +36 -0
- data/src/asunit/framework/IRunListener.as +11 -0
- data/src/asunit/framework/IRunner.as +15 -0
- data/src/asunit/framework/IRunnerFactory.as +9 -0
- data/src/asunit/framework/ITestFailure.as +32 -0
- data/src/asunit/framework/ITestListener.as +15 -0
- data/src/asunit/framework/ITestResult.as +21 -0
- data/src/asunit/framework/ITestSuccess.as +22 -0
- data/src/asunit/framework/ITestWarning.as +14 -0
- data/src/asunit/framework/InjectionDelegate.as +96 -0
- data/src/asunit/framework/LegacyTestIterator.as +40 -0
- data/src/asunit/framework/MessageBridge.as +24 -0
- data/src/asunit/framework/Method.as +80 -0
- data/src/asunit/framework/Result.as +181 -0
- data/src/asunit/framework/RunnerFactory.as +179 -0
- data/src/asunit/framework/SuiteIterator.as +71 -0
- data/src/asunit/framework/TestCase.as +106 -0
- data/src/asunit/framework/TestFailure.as +65 -0
- data/src/asunit/framework/TestIterator.as +282 -0
- data/src/asunit/framework/TestObserver.as +12 -0
- data/src/asunit/framework/TestSuccess.as +38 -0
- data/src/asunit/framework/TestWarning.as +40 -0
- data/src/asunit/framework/TimeoutCommand.as +103 -0
- data/src/asunit/printers/FlashBuilderPrinter.as +134 -0
- data/src/asunit/printers/FlashDevelopPrinter.as +81 -0
- data/src/asunit/printers/TextPrinter.as +324 -0
- data/src/asunit/runners/LegacyRunner.as +13 -0
- data/src/asunit/runners/SuiteRunner.as +125 -0
- data/src/asunit/runners/TestRunner.as +403 -0
- data/src/asunit/util/ArrayIterator.as +30 -0
- data/src/asunit/util/Iterator.as +10 -0
- data/test/AllTests.as +73 -0
- data/test/AsUnitRunner.as +15 -0
- data/test/Flex3Runner.mxml +24 -0
- data/test/Flex4Runner.mxml +27 -0
- data/test/asunit/core/AsUnitCoreTest.as +97 -0
- data/test/asunit/framework/AssertEqualsArraysIgnoringOrderTest.as +88 -0
- data/test/asunit/framework/AssertEqualsArraysTest.as +102 -0
- data/test/asunit/framework/AssertTest.as +184 -0
- data/test/asunit/framework/AssertThrowsTest.as +42 -0
- data/test/asunit/framework/AsyncMethodTest.as +69 -0
- data/test/asunit/framework/AsyncTest.as +104 -0
- data/test/asunit/framework/CallbackBridgeTest.as +73 -0
- data/test/asunit/framework/InjectionDelegateTest.as +79 -0
- data/test/asunit/framework/MockData.xml +8 -0
- data/test/asunit/framework/NestedSuiteIteratorTest.as +59 -0
- data/test/asunit/framework/ProceedOnEventTest.as +109 -0
- data/test/asunit/framework/ResultTest.as +92 -0
- data/test/asunit/framework/RunnerFactoryTest.as +54 -0
- data/test/asunit/framework/SuiteIteratorTest.as +67 -0
- data/test/asunit/framework/TestCaseMock.as +24 -0
- data/test/asunit/framework/TestIteratorIgnoredMethodTest.as +62 -0
- data/test/asunit/framework/TestIteratorMethodByNameTest.as +50 -0
- data/test/asunit/framework/TestIteratorMultiMethodTest.as +186 -0
- data/test/asunit/framework/TestIteratorOrderedTestMethodTest.as +57 -0
- data/test/asunit/framework/TestIteratorSingleMethodTest.as +56 -0
- data/test/asunit/framework/VisualTestCaseTest.as +43 -0
- data/test/asunit/framework/assertAssertionFailed.as +19 -0
- data/test/asunit/printers/TextPrinterTest.as +122 -0
- data/test/asunit/runners/LegacyRunnerTest.as +40 -0
- data/test/asunit/runners/SuiteRunnerTest.as +40 -0
- data/test/asunit/runners/TestRunnerAsyncMethodTest.as +107 -0
- data/test/asunit/runners/TestRunnerErrorMethodTest.as +56 -0
- data/test/asunit/runners/TestRunnerExpectsErrorTest.as +98 -0
- data/test/asunit/runners/TestRunnerIgnoredMethodTest.as +42 -0
- data/test/asunit/runners/TestRunnerTest.as +171 -0
- data/test/asunit/support/AnnotatedSubClass.as +18 -0
- data/test/asunit/support/AnnotatedSuperClass.as +15 -0
- data/test/asunit/support/CustomParameters.as +13 -0
- data/test/asunit/support/CustomTestRunner.as +22 -0
- data/test/asunit/support/DoubleFailSuite.as +8 -0
- data/test/asunit/support/DoubleNestedSuite.as +14 -0
- data/test/asunit/support/ErrorInMethod.as +11 -0
- data/test/asunit/support/FailAssertEquals.as +29 -0
- data/test/asunit/support/FailAssertTrue.as +28 -0
- data/test/asunit/support/FakeObserver.as +42 -0
- data/test/asunit/support/FakeRunner.as +32 -0
- data/test/asunit/support/IgnoredMethod.as +26 -0
- data/test/asunit/support/InjectTimeoutOnAsync.as +14 -0
- data/test/asunit/support/InjectionFailure.as +18 -0
- data/test/asunit/support/InjectionVerification.as +69 -0
- data/test/asunit/support/LegacyTestCase.as +38 -0
- data/test/asunit/support/MultiMethod.as +77 -0
- data/test/asunit/support/OrderedTestMethod.as +36 -0
- data/test/asunit/support/RunWithButNoType.as +14 -0
- data/test/asunit/support/RunWithSuiteButNoType.as +11 -0
- data/test/asunit/support/SingleErrorSuite.as +7 -0
- data/test/asunit/support/SingleSuccessSuite.as +7 -0
- data/test/asunit/support/SucceedAssertTrue.as +31 -0
- data/test/asunit/support/SuiteOfTwoSuites.as +8 -0
- data/test/asunit/support/SuiteWithCustomRunner.as +12 -0
- data/test/asunit/support/SuiteWithOneCustomChildSuite.as +10 -0
- data/test/asunit/support/TestForFakeRunner.as +14 -0
- data/test/asunit/util/ArrayIteratorTest.as +65 -0
- data/vendor/as3reflection/README +7 -0
- data/vendor/as3reflection/p2/reflect/Reflection.as +417 -0
- data/vendor/as3reflection/p2/reflect/ReflectionAccessor.as +14 -0
- data/vendor/as3reflection/p2/reflect/ReflectionBase.as +52 -0
- data/vendor/as3reflection/p2/reflect/ReflectionMember.as +16 -0
- data/vendor/as3reflection/p2/reflect/ReflectionMetaData.as +69 -0
- data/vendor/as3reflection/p2/reflect/ReflectionMethod.as +36 -0
- data/vendor/as3reflection/p2/reflect/ReflectionMethodParameter.as +19 -0
- data/vendor/as3reflection/p2/reflect/ReflectionVariable.as +15 -0
- data/vendor/as3reflection/p2/reflect/findFirst.as +14 -0
- data/vendor/generators/suite/USAGE +0 -0
- data/vendor/generators/suite/suite_generator.rb +17 -0
- data/vendor/generators/suite/templates/TestSuite.as +17 -0
- metadata +216 -0
@@ -0,0 +1,403 @@
|
|
1
|
+
package asunit.runners {
|
2
|
+
|
3
|
+
import asunit.events.TimeoutCommandEvent;
|
4
|
+
import asunit.framework.Assert;
|
5
|
+
import asunit.framework.Async;
|
6
|
+
import asunit.framework.CallbackBridge;
|
7
|
+
import asunit.framework.IAsync;
|
8
|
+
import asunit.framework.IResult;
|
9
|
+
import asunit.framework.IRunner;
|
10
|
+
import asunit.framework.IRunnerFactory;
|
11
|
+
import asunit.framework.Method;
|
12
|
+
import asunit.framework.TestFailure;
|
13
|
+
import asunit.framework.TestIterator;
|
14
|
+
import asunit.framework.TestSuccess;
|
15
|
+
import asunit.framework.TestWarning;
|
16
|
+
import asunit.util.ArrayIterator;
|
17
|
+
import asunit.util.Iterator;
|
18
|
+
|
19
|
+
import flash.display.DisplayObjectContainer;
|
20
|
+
import flash.errors.IllegalOperationError;
|
21
|
+
import flash.events.Event;
|
22
|
+
import flash.events.EventDispatcher;
|
23
|
+
import flash.events.IEventDispatcher;
|
24
|
+
import flash.events.TimerEvent;
|
25
|
+
import flash.utils.Timer;
|
26
|
+
import flash.utils.clearTimeout;
|
27
|
+
import flash.utils.getDefinitionByName;
|
28
|
+
import flash.utils.getTimer;
|
29
|
+
import flash.utils.setTimeout;
|
30
|
+
|
31
|
+
import p2.reflect.Reflection;
|
32
|
+
import p2.reflect.ReflectionMember;
|
33
|
+
import p2.reflect.ReflectionMetaData;
|
34
|
+
import p2.reflect.ReflectionVariable;
|
35
|
+
|
36
|
+
public class TestRunner extends EventDispatcher implements IRunner {
|
37
|
+
public static var ASYNC_NAME:String = 'asunit.framework::Async';
|
38
|
+
public static var IASYNC_NAME:String = 'asunit.framework::IAsync';
|
39
|
+
public static var DISPLAY_OBJECT_CONTAINER:String = 'flash.display::DisplayObjectContainer';
|
40
|
+
|
41
|
+
/**
|
42
|
+
* This is how the Runner connects to a printer.
|
43
|
+
* The AsUnitCore will inject the requested bridge
|
44
|
+
* based on the concrete data type.
|
45
|
+
*
|
46
|
+
* There should be a similar Injection point on
|
47
|
+
* whatever printers are interested in what this
|
48
|
+
* concrete runner will dispatch.
|
49
|
+
*/
|
50
|
+
[Inject]
|
51
|
+
public var bridge:CallbackBridge;
|
52
|
+
|
53
|
+
// partially exposed for unit testing
|
54
|
+
internal var currentTest:Object;
|
55
|
+
internal var async:IAsync;
|
56
|
+
|
57
|
+
protected var asyncMembers:Iterator;
|
58
|
+
protected var currentMethod:Method;
|
59
|
+
protected var currentTestReflection:Reflection;
|
60
|
+
protected var injectableMembers:Iterator;
|
61
|
+
protected var methodIsExecuting:Boolean = false;
|
62
|
+
protected var methodPassed:Boolean = true;
|
63
|
+
protected var methodTimeoutID:Number;
|
64
|
+
protected var methodsToRun:TestIterator;
|
65
|
+
protected var startTime:Number;
|
66
|
+
protected var testMethodNameReceived:Boolean;
|
67
|
+
protected var timer:Timer;
|
68
|
+
protected var visualContext:DisplayObjectContainer;
|
69
|
+
protected var visualInstances:Array;
|
70
|
+
|
71
|
+
private var _factory:IRunnerFactory;
|
72
|
+
|
73
|
+
public function TestRunner() {
|
74
|
+
async = new Async();
|
75
|
+
bridge = new CallbackBridge();
|
76
|
+
timer = new Timer(0, 1);
|
77
|
+
timer.addEventListener(TimerEvent.TIMER, runNextMethod);
|
78
|
+
visualInstances = [];
|
79
|
+
}
|
80
|
+
|
81
|
+
public function run(testOrSuite:Class, methodName:String=null, visualContext:DisplayObjectContainer=null):void {
|
82
|
+
runMethodByName(testOrSuite, methodName, visualContext);
|
83
|
+
}
|
84
|
+
|
85
|
+
public function shouldRunTest(testClass:Class):Boolean {
|
86
|
+
return bridge.shouldRunTest(testClass);
|
87
|
+
}
|
88
|
+
|
89
|
+
// This class doesn't really use the runner factory,
|
90
|
+
// since it represents a leaf node in the test
|
91
|
+
// hierarchy...
|
92
|
+
public function set factory(factory:IRunnerFactory):void {
|
93
|
+
_factory = factory;
|
94
|
+
}
|
95
|
+
|
96
|
+
public function get factory():IRunnerFactory {
|
97
|
+
return _factory;
|
98
|
+
}
|
99
|
+
|
100
|
+
public function runMethodByName(test:Class, methodName:String=null, visualContext:DisplayObjectContainer=null):void {
|
101
|
+
currentTestReflection = Reflection.create(test);
|
102
|
+
this.visualContext = visualContext;
|
103
|
+
currentMethod = null;
|
104
|
+
testMethodNameReceived = (methodName != null);
|
105
|
+
|
106
|
+
try {
|
107
|
+
currentTest = new test();
|
108
|
+
}
|
109
|
+
catch(e:VerifyError) {
|
110
|
+
warn("Unable to instantiate provided test case with: " + currentTestReflection.name);
|
111
|
+
return;
|
112
|
+
}
|
113
|
+
|
114
|
+
initializeInjectableMembers();
|
115
|
+
|
116
|
+
async.addEventListener(TimeoutCommandEvent.CALLED, onAsyncMethodCalled);
|
117
|
+
async.addEventListener(TimeoutCommandEvent.TIMED_OUT, onAsyncMethodTimedOut);
|
118
|
+
|
119
|
+
startTime = getTimer();
|
120
|
+
bridge.onTestStarted(currentTest);
|
121
|
+
|
122
|
+
methodsToRun = createTestIterator(currentTest, methodName);
|
123
|
+
|
124
|
+
if(methodsToRun.length == 0) {
|
125
|
+
warn(">> We were unable to find any test methods in " + currentTestReflection.name + ". Did you set the --keep-as3-metadata flag?");
|
126
|
+
}
|
127
|
+
runNextMethod();
|
128
|
+
}
|
129
|
+
|
130
|
+
protected function createTestIterator(test:*, testMethodName:String):TestIterator {
|
131
|
+
return new TestIterator(test, testMethodName);
|
132
|
+
}
|
133
|
+
|
134
|
+
protected function initializeInjectableMembers():void {
|
135
|
+
injectableMembers = new ArrayIterator(currentTestReflection.getMembersByMetaData('Inject'));
|
136
|
+
}
|
137
|
+
|
138
|
+
protected function runNextMethod(e:TimerEvent = null):void {
|
139
|
+
if(!testMethodNameReceived && methodsToRun.readyToTearDown) {
|
140
|
+
removeInjectedMembers();
|
141
|
+
removeInjectedVisualInstances();
|
142
|
+
}
|
143
|
+
|
144
|
+
if (testCompleted) {
|
145
|
+
onTestCompleted();
|
146
|
+
return;
|
147
|
+
}
|
148
|
+
|
149
|
+
if(methodsToRun.readyToSetUp) {
|
150
|
+
prepareForSetUp();
|
151
|
+
}
|
152
|
+
|
153
|
+
runMethod(methodsToRun.next());
|
154
|
+
}
|
155
|
+
|
156
|
+
protected function runMethod(method:Method):void {
|
157
|
+
if (!method) return;
|
158
|
+
currentMethod = method;
|
159
|
+
methodPassed = true; // innocent until proven guilty by recordFailure()
|
160
|
+
|
161
|
+
if (currentMethod.ignore) {
|
162
|
+
bridge.onTestIgnored(currentMethod);
|
163
|
+
onMethodCompleted();
|
164
|
+
return;
|
165
|
+
}
|
166
|
+
|
167
|
+
// This is used to prevent async callbacks from triggering onMethodCompleted too early.
|
168
|
+
methodIsExecuting = true;
|
169
|
+
|
170
|
+
if (currentMethod.expects) {
|
171
|
+
try {
|
172
|
+
var errorClass:Class = getDefinitionByName(currentMethod.expects) as Class;
|
173
|
+
Assert.assertThrows(errorClass, currentMethod.value);
|
174
|
+
}
|
175
|
+
catch(definitionError:ReferenceError) {
|
176
|
+
// NOTE: [luke] Added ReferenceError catch here b/c I had a bad class name in my expects.
|
177
|
+
// Does this look right?
|
178
|
+
recordFailure(new Error('Could not find Reference for: ' + currentMethod.expects));
|
179
|
+
}
|
180
|
+
catch (error:Error) {
|
181
|
+
recordFailure(error);
|
182
|
+
}
|
183
|
+
}
|
184
|
+
else {
|
185
|
+
try {
|
186
|
+
currentMethod.execute();
|
187
|
+
}
|
188
|
+
catch (error:Error) {
|
189
|
+
recordFailure(error);
|
190
|
+
}
|
191
|
+
}
|
192
|
+
|
193
|
+
methodIsExecuting = false;
|
194
|
+
|
195
|
+
if (async.hasPending) return;
|
196
|
+
|
197
|
+
onMethodCompleted();
|
198
|
+
}
|
199
|
+
|
200
|
+
protected function onMethodCompleted():void {
|
201
|
+
async.cancelPending();
|
202
|
+
|
203
|
+
if (currentMethod.isTest && methodPassed && !currentMethod.ignore) {
|
204
|
+
bridge.onTestSuccess(new TestSuccess(currentTest, currentMethod.name));
|
205
|
+
}
|
206
|
+
|
207
|
+
// Calling synchronously is faster but keeps adding to the call stack.
|
208
|
+
//runNextMethod();
|
209
|
+
|
210
|
+
// green thread for runNextMethod()
|
211
|
+
// This runs much slower in Flash Player 10.1.
|
212
|
+
timer.reset();
|
213
|
+
timer.start();
|
214
|
+
}
|
215
|
+
|
216
|
+
protected function onAsyncMethodCalled(event:TimeoutCommandEvent):void {
|
217
|
+
try {
|
218
|
+
event.command.execute();
|
219
|
+
}
|
220
|
+
catch (error:Error) {
|
221
|
+
recordFailure(error);
|
222
|
+
}
|
223
|
+
onAsyncMethodCompleted(event);
|
224
|
+
}
|
225
|
+
|
226
|
+
protected function onAsyncMethodTimedOut(event:TimeoutCommandEvent):void {
|
227
|
+
var error:IllegalOperationError = new IllegalOperationError("Timeout (" + event.command.duration + "ms) exceeded on an asynchronous operation.");
|
228
|
+
recordFailure(error);
|
229
|
+
onAsyncMethodCompleted(event);
|
230
|
+
}
|
231
|
+
|
232
|
+
protected function recordFailure(error:Error):void {
|
233
|
+
methodPassed = false;
|
234
|
+
bridge.onTestFailure(new TestFailure(currentTest, currentMethod.name, error));
|
235
|
+
}
|
236
|
+
|
237
|
+
protected function onAsyncMethodCompleted(event:Event = null):void {
|
238
|
+
if (!methodIsExecuting && !async.hasPending) {
|
239
|
+
onMethodCompleted();
|
240
|
+
}
|
241
|
+
}
|
242
|
+
|
243
|
+
protected function onTestCompleted():void {
|
244
|
+
async.removeEventListener(TimeoutCommandEvent.CALLED, onAsyncMethodCalled);
|
245
|
+
async.removeEventListener(TimeoutCommandEvent.TIMED_OUT, onAsyncMethodTimedOut);
|
246
|
+
async.cancelPending();
|
247
|
+
|
248
|
+
bridge.onTestCompleted(currentTest);
|
249
|
+
|
250
|
+
dispatchEvent(new Event(Event.COMPLETE));
|
251
|
+
}
|
252
|
+
|
253
|
+
protected function get testCompleted():Boolean {
|
254
|
+
return (!methodsToRun.hasNext() && !async.hasPending);
|
255
|
+
}
|
256
|
+
|
257
|
+
protected function removeInjectedMembers():void {
|
258
|
+
var member:ReflectionVariable;
|
259
|
+
while(injectableMembers.hasNext()) {
|
260
|
+
removeInjectedMember(injectableMembers.next());
|
261
|
+
}
|
262
|
+
injectableMembers.reset();
|
263
|
+
}
|
264
|
+
|
265
|
+
protected function removeInjectedVisualInstances():void {
|
266
|
+
var visuals:Iterator = new ArrayIterator(visualInstances);
|
267
|
+
while(visuals.hasNext()) {
|
268
|
+
visualContext.removeChild(visuals.next());
|
269
|
+
}
|
270
|
+
visualInstances = [];
|
271
|
+
}
|
272
|
+
|
273
|
+
protected function removeInjectedMember(member:ReflectionVariable):void {
|
274
|
+
if(!member) return;
|
275
|
+
currentTest[member.name] = null;
|
276
|
+
}
|
277
|
+
|
278
|
+
protected function prepareForSetUp():void {
|
279
|
+
injectMembers();
|
280
|
+
}
|
281
|
+
|
282
|
+
protected function injectMembers():void {
|
283
|
+
var member:ReflectionVariable;
|
284
|
+
while(injectableMembers.hasNext()) {
|
285
|
+
injectMember(injectableMembers.next());
|
286
|
+
}
|
287
|
+
injectableMembers.reset();
|
288
|
+
}
|
289
|
+
|
290
|
+
protected function injectMember(member:ReflectionVariable):void {
|
291
|
+
if(!member) return;
|
292
|
+
var definition:Class;
|
293
|
+
try {
|
294
|
+
definition = getDefinitionByName(member.type) as Class;
|
295
|
+
}
|
296
|
+
catch(referenceError:ReferenceError) {
|
297
|
+
warn("Unable to [Inject] with " + member.type + ". Maybe this was an inner class? That makes it unavailable to external code, try putting it in it's own file.");
|
298
|
+
return;
|
299
|
+
}
|
300
|
+
var reflection:Reflection = Reflection.create(definition);
|
301
|
+
try {
|
302
|
+
var instance:* = createInstanceFromReflection(reflection);
|
303
|
+
configureInjectedInstance(member, instance);
|
304
|
+
currentTest[member.name] = instance;
|
305
|
+
}
|
306
|
+
catch(e:VerifyError) {
|
307
|
+
throw new VerifyError("Failed to instantiate " + member.type + " in order to inject public var " + member.name);
|
308
|
+
}
|
309
|
+
}
|
310
|
+
|
311
|
+
protected function configureInjectedInstance(member:ReflectionVariable, instance:*):void {
|
312
|
+
var injectTag:ReflectionMetaData = member.getMetaDataByName('Inject');
|
313
|
+
var args:Array = injectTag.args;
|
314
|
+
var arg:Object;
|
315
|
+
var len:int = args.length;
|
316
|
+
for(var i:int; i < len; i++) {
|
317
|
+
arg = args[i];
|
318
|
+
try {
|
319
|
+
instance[arg.key] = coerceArgumentType(member, arg.value);
|
320
|
+
}
|
321
|
+
catch(e:ReferenceError) {
|
322
|
+
var reflect:Reflection = Reflection.create(instance);
|
323
|
+
warn("Unable to inject attribute " + arg.key + " on " + reflect.name);
|
324
|
+
}
|
325
|
+
}
|
326
|
+
}
|
327
|
+
|
328
|
+
protected function coerceArgumentType(member:ReflectionVariable, value:String):* {
|
329
|
+
switch(value) {
|
330
|
+
case "false" :
|
331
|
+
return false;
|
332
|
+
case "true" :
|
333
|
+
return true;
|
334
|
+
}
|
335
|
+
|
336
|
+
return value;
|
337
|
+
}
|
338
|
+
|
339
|
+
protected function createInstanceFromReflection(reflection:Reflection):* {
|
340
|
+
// Return the shared async instance if they're expecting the interface
|
341
|
+
// or concrete instance, but NOT if their Inject is merely a subclass...
|
342
|
+
if(reflection.name == ASYNC_NAME || reflection.name == IASYNC_NAME) {
|
343
|
+
return async;
|
344
|
+
}
|
345
|
+
|
346
|
+
var clazz:Class = getClassReferenceFromReflection(reflection);
|
347
|
+
var constructorReflection:Reflection = Reflection.create(clazz);
|
348
|
+
try {
|
349
|
+
var instance:* = new constructorReflection.classReference();
|
350
|
+
}
|
351
|
+
catch(e:VerifyError) {
|
352
|
+
warn("Unable to instantiate: " + reflection.name + " for injection");
|
353
|
+
}
|
354
|
+
|
355
|
+
if(constructorReflection.isA(DISPLAY_OBJECT_CONTAINER)) {
|
356
|
+
// Add injected DisplayObjectContainers to a collection
|
357
|
+
// for removal, and add them to the visualContext if
|
358
|
+
// one was provided to the run() method.
|
359
|
+
if(visualContext) {
|
360
|
+
visualInstances.push(instance);
|
361
|
+
visualContext.addChild(instance);
|
362
|
+
}
|
363
|
+
else {
|
364
|
+
warn("TestRunner is injecting a DisplayObjectContainer on your Test but wasn't given a visualContext when run was called. This means your visual entity will not be attached to the Display List.");
|
365
|
+
}
|
366
|
+
}
|
367
|
+
|
368
|
+
return instance;
|
369
|
+
}
|
370
|
+
|
371
|
+
protected function warn(message:String, method:Method=null):void {
|
372
|
+
bridge.onWarning(new TestWarning(message, method));
|
373
|
+
}
|
374
|
+
|
375
|
+
protected function getClassReferenceFromReflection(reflection:Reflection):Class {
|
376
|
+
// This will attempt to deal with I-prefixed interfaces - like IAsync.
|
377
|
+
if(reflection.isInterface) {
|
378
|
+
return attemptToGetClassReferenceFromReflection(reflection);
|
379
|
+
}
|
380
|
+
return reflection.classReference;
|
381
|
+
}
|
382
|
+
|
383
|
+
protected function attemptToGetClassReferenceFromReflection(reflection:Reflection):Class {
|
384
|
+
var fullName:String = reflection.name;
|
385
|
+
var parts:Array = fullName.split("::");
|
386
|
+
var interfaceName:String = parts.pop();
|
387
|
+
var expr:RegExp = /I([AZ].+)/;
|
388
|
+
var match:Object = expr.exec(interfaceName);
|
389
|
+
if(match) {
|
390
|
+
parts.push(match[1]);
|
391
|
+
var implementationName:String = parts.join("::");
|
392
|
+
return Class(getDefinitionByName(implementationName));
|
393
|
+
}
|
394
|
+
throw new VerifyError("Unable to find class instance for interface " + fullName);
|
395
|
+
}
|
396
|
+
|
397
|
+
// TODO: Implement this method:
|
398
|
+
protected function argumentFreeConstructor(reflection:Reflection):Boolean {
|
399
|
+
return true;
|
400
|
+
}
|
401
|
+
}
|
402
|
+
}
|
403
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
package asunit.util {
|
2
|
+
|
3
|
+
import asunit.util.Iterator;
|
4
|
+
|
5
|
+
[ExcludeClass]
|
6
|
+
public class ArrayIterator implements Iterator {
|
7
|
+
private var items:Array;
|
8
|
+
private var index:Number = 0;
|
9
|
+
|
10
|
+
public function ArrayIterator(items:Array=null) {
|
11
|
+
this.items = items || [];
|
12
|
+
}
|
13
|
+
|
14
|
+
public function hasNext():Boolean {
|
15
|
+
return items[index] != null;
|
16
|
+
}
|
17
|
+
|
18
|
+
public function next():* {
|
19
|
+
return items[index++];
|
20
|
+
}
|
21
|
+
|
22
|
+
public function get length():uint {
|
23
|
+
return items.length;
|
24
|
+
}
|
25
|
+
|
26
|
+
public function reset():void {
|
27
|
+
index = 0;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
data/test/AllTests.as
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
package {
|
2
|
+
/**
|
3
|
+
* This file has been automatically created using
|
4
|
+
* #!/usr/bin/ruby script/generate suite
|
5
|
+
* If you modify it and run this script, your
|
6
|
+
* modifications will be lost!
|
7
|
+
*/
|
8
|
+
|
9
|
+
import asunit.core.AsUnitCoreTest;
|
10
|
+
import asunit.framework.AssertEqualsArraysIgnoringOrderTest;
|
11
|
+
import asunit.framework.AssertEqualsArraysTest;
|
12
|
+
import asunit.framework.AssertTest;
|
13
|
+
import asunit.framework.AssertThrowsTest;
|
14
|
+
import asunit.framework.AsyncMethodTest;
|
15
|
+
import asunit.framework.AsyncTest;
|
16
|
+
import asunit.framework.CallbackBridgeTest;
|
17
|
+
import asunit.framework.InjectionDelegateTest;
|
18
|
+
import asunit.framework.NestedSuiteIteratorTest;
|
19
|
+
import asunit.framework.ProceedOnEventTest;
|
20
|
+
import asunit.framework.ResultTest;
|
21
|
+
import asunit.framework.RunnerFactoryTest;
|
22
|
+
import asunit.framework.SuiteIteratorTest;
|
23
|
+
import asunit.framework.TestIteratorIgnoredMethodTest;
|
24
|
+
import asunit.framework.TestIteratorMethodByNameTest;
|
25
|
+
import asunit.framework.TestIteratorMultiMethodTest;
|
26
|
+
import asunit.framework.TestIteratorOrderedTestMethodTest;
|
27
|
+
import asunit.framework.TestIteratorSingleMethodTest;
|
28
|
+
import asunit.framework.VisualTestCaseTest;
|
29
|
+
import asunit.printers.TextPrinterTest;
|
30
|
+
import asunit.runners.LegacyRunnerTest;
|
31
|
+
import asunit.runners.SuiteRunnerTest;
|
32
|
+
import asunit.runners.TestRunnerAsyncMethodTest;
|
33
|
+
import asunit.runners.TestRunnerErrorMethodTest;
|
34
|
+
import asunit.runners.TestRunnerExpectsErrorTest;
|
35
|
+
import asunit.runners.TestRunnerIgnoredMethodTest;
|
36
|
+
import asunit.runners.TestRunnerTest;
|
37
|
+
import asunit.util.ArrayIteratorTest;
|
38
|
+
|
39
|
+
[Suite]
|
40
|
+
public class AllTests {
|
41
|
+
|
42
|
+
public var asunit_core_AsUnitCoreTest:asunit.core.AsUnitCoreTest;
|
43
|
+
public var asunit_framework_AssertEqualsArraysIgnoringOrderTest:asunit.framework.AssertEqualsArraysIgnoringOrderTest;
|
44
|
+
public var asunit_framework_AssertEqualsArraysTest:asunit.framework.AssertEqualsArraysTest;
|
45
|
+
public var asunit_framework_AssertTest:asunit.framework.AssertTest;
|
46
|
+
public var asunit_framework_AssertThrowsTest:asunit.framework.AssertThrowsTest;
|
47
|
+
public var asunit_framework_AsyncMethodTest:asunit.framework.AsyncMethodTest;
|
48
|
+
public var asunit_framework_AsyncTest:asunit.framework.AsyncTest;
|
49
|
+
public var asunit_framework_CallbackBridgeTest:asunit.framework.CallbackBridgeTest;
|
50
|
+
public var asunit_framework_InjectionDelegateTest:asunit.framework.InjectionDelegateTest;
|
51
|
+
public var asunit_framework_NestedSuiteIteratorTest:asunit.framework.NestedSuiteIteratorTest;
|
52
|
+
public var asunit_framework_ProceedOnEventTest:asunit.framework.ProceedOnEventTest;
|
53
|
+
public var asunit_framework_ResultTest:asunit.framework.ResultTest;
|
54
|
+
public var asunit_framework_RunnerFactoryTest:asunit.framework.RunnerFactoryTest;
|
55
|
+
public var asunit_framework_SuiteIteratorTest:asunit.framework.SuiteIteratorTest;
|
56
|
+
public var asunit_framework_TestIteratorIgnoredMethodTest:asunit.framework.TestIteratorIgnoredMethodTest;
|
57
|
+
public var asunit_framework_TestIteratorMethodByNameTest:asunit.framework.TestIteratorMethodByNameTest;
|
58
|
+
public var asunit_framework_TestIteratorMultiMethodTest:asunit.framework.TestIteratorMultiMethodTest;
|
59
|
+
public var asunit_framework_TestIteratorOrderedTestMethodTest:asunit.framework.TestIteratorOrderedTestMethodTest;
|
60
|
+
public var asunit_framework_TestIteratorSingleMethodTest:asunit.framework.TestIteratorSingleMethodTest;
|
61
|
+
public var asunit_framework_VisualTestCaseTest:asunit.framework.VisualTestCaseTest;
|
62
|
+
public var asunit_printers_TextPrinterTest:asunit.printers.TextPrinterTest;
|
63
|
+
public var asunit_runners_LegacyRunnerTest:asunit.runners.LegacyRunnerTest;
|
64
|
+
public var asunit_runners_SuiteRunnerTest:asunit.runners.SuiteRunnerTest;
|
65
|
+
public var asunit_runners_TestRunnerAsyncMethodTest:asunit.runners.TestRunnerAsyncMethodTest;
|
66
|
+
public var asunit_runners_TestRunnerErrorMethodTest:asunit.runners.TestRunnerErrorMethodTest;
|
67
|
+
public var asunit_runners_TestRunnerExpectsErrorTest:asunit.runners.TestRunnerExpectsErrorTest;
|
68
|
+
public var asunit_runners_TestRunnerIgnoredMethodTest:asunit.runners.TestRunnerIgnoredMethodTest;
|
69
|
+
public var asunit_runners_TestRunnerTest:asunit.runners.TestRunnerTest;
|
70
|
+
public var asunit_util_ArrayIteratorTest:asunit.util.ArrayIteratorTest;
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
package {
|
2
|
+
|
3
|
+
import asunit.core.TextCore;
|
4
|
+
import flash.display.MovieClip;
|
5
|
+
|
6
|
+
public class AsUnitRunner extends MovieClip {
|
7
|
+
|
8
|
+
private var core:TextCore;
|
9
|
+
|
10
|
+
public function AsUnitRunner() {
|
11
|
+
core = new TextCore();
|
12
|
+
core.start(AllTests, null, this);
|
13
|
+
}
|
14
|
+
}
|
15
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<mx:Application
|
3
|
+
xmlns:mx="http://www.adobe.com/2006/mxml"
|
4
|
+
layout="absolute"
|
5
|
+
minWidth="640"
|
6
|
+
minHeight="480"
|
7
|
+
backgroundColor="#333333"
|
8
|
+
backgroundImage=""
|
9
|
+
creationComplete="creationCompleteHandler(event)"
|
10
|
+
>
|
11
|
+
<mx:Script>
|
12
|
+
<![CDATA[
|
13
|
+
import asunit.core.TextCore;
|
14
|
+
|
15
|
+
private var core:TextCore;
|
16
|
+
|
17
|
+
private function creationCompleteHandler(event:Event):void {
|
18
|
+
core = new TextCore();
|
19
|
+
core.start(AllTests, null, visualContext);
|
20
|
+
}
|
21
|
+
]]>
|
22
|
+
</mx:Script>
|
23
|
+
<mx:UIComponent id="visualContext" width="100%" height="100%" />
|
24
|
+
</mx:Application>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
|
3
|
+
xmlns:s="library://ns.adobe.com/flex/spark"
|
4
|
+
xmlns:mx="library://ns.adobe.com/flex/mx"
|
5
|
+
minWidth="955"
|
6
|
+
minHeight="600"
|
7
|
+
creationComplete="creationCompleteHandler(event)"
|
8
|
+
>
|
9
|
+
<fx:Script>
|
10
|
+
<![CDATA[
|
11
|
+
import asunit.core.TextCore;
|
12
|
+
import mx.core.UIComponent;
|
13
|
+
|
14
|
+
private var core:TextCore;
|
15
|
+
|
16
|
+
private function creationCompleteHandler(event:Event):void {
|
17
|
+
// Flex 4 complains when we use UICompenent from MXML... Boo.
|
18
|
+
var visualContext:UIComponent = new UIComponent();
|
19
|
+
addElement(visualContext);
|
20
|
+
|
21
|
+
core = new TextCore();
|
22
|
+
core.start(AllTests, null, visualContext);
|
23
|
+
}
|
24
|
+
]]>
|
25
|
+
</fx:Script>
|
26
|
+
</s:Application>
|
27
|
+
|
@@ -0,0 +1,97 @@
|
|
1
|
+
package asunit.core {
|
2
|
+
|
3
|
+
import asunit.asserts.*;
|
4
|
+
import asunit.framework.CallbackBridge;
|
5
|
+
import asunit.framework.IAsync;
|
6
|
+
import asunit.framework.IResult;
|
7
|
+
import asunit.framework.Result;
|
8
|
+
import asunit.printers.TextPrinter;
|
9
|
+
import asunit.support.CustomTestRunner;
|
10
|
+
import asunit.support.SuiteWithCustomRunner;
|
11
|
+
import asunit.support.SuiteWithOneCustomChildSuite;
|
12
|
+
import asunit.support.SucceedAssertTrue;
|
13
|
+
|
14
|
+
import flash.display.Sprite;
|
15
|
+
import flash.events.Event;
|
16
|
+
|
17
|
+
public class AsUnitCoreTest {
|
18
|
+
|
19
|
+
[Inject]
|
20
|
+
public var async:IAsync;
|
21
|
+
|
22
|
+
[Inject]
|
23
|
+
public var core:AsUnitCore;
|
24
|
+
|
25
|
+
[Inject]
|
26
|
+
public var context:Sprite;
|
27
|
+
|
28
|
+
[After]
|
29
|
+
public function cleanUpStatics():void {
|
30
|
+
CustomTestRunner.runCalledCount = 0;
|
31
|
+
}
|
32
|
+
|
33
|
+
[Test]
|
34
|
+
public function shouldBeInstantiated():void {
|
35
|
+
assertTrue("core is AsUnitCore", core is AsUnitCore);
|
36
|
+
}
|
37
|
+
|
38
|
+
[Test]
|
39
|
+
public function startShouldWork():void {
|
40
|
+
core.start(SucceedAssertTrue);
|
41
|
+
}
|
42
|
+
|
43
|
+
[Test]
|
44
|
+
public function setVisualContextShouldWork():void {
|
45
|
+
core.visualContext = context;
|
46
|
+
assertEquals(context, core.visualContext);
|
47
|
+
}
|
48
|
+
|
49
|
+
[Test]
|
50
|
+
public function textPrinterShouldWork():void {
|
51
|
+
var printer:TextPrinter = new TextPrinter();
|
52
|
+
printer.traceOnComplete = false;
|
53
|
+
core.addObserver(printer);
|
54
|
+
|
55
|
+
// Wait for the complete event:
|
56
|
+
var handler:Function = function(event:Event):void {
|
57
|
+
var output:String = printer.toString();
|
58
|
+
assertTrue("should include test summary", output.indexOf('OK (1 test)') > -1);
|
59
|
+
assertTrue("should include provided test name", output.indexOf('asunit.support::SucceedAssertTrue') > -1);
|
60
|
+
}
|
61
|
+
|
62
|
+
core.addEventListener(Event.COMPLETE, async.add(handler));
|
63
|
+
core.start(SucceedAssertTrue);
|
64
|
+
}
|
65
|
+
|
66
|
+
private function verifyRunWithOnASuite(Suite:Class, testCaseCount:int, testMethodCount:int):void {
|
67
|
+
|
68
|
+
var handler:Function = function(event:Event):void {
|
69
|
+
var message:String = "CustomRunner.run was NOT called with correct count";
|
70
|
+
// This is the number of Tests that will used the custom Runner:
|
71
|
+
assertEquals(message, testCaseCount, CustomTestRunner.runCalledCount);
|
72
|
+
// This is the number of test methods:
|
73
|
+
assertEquals("Total Test Count", testMethodCount, core.bridge.runCount);
|
74
|
+
}
|
75
|
+
|
76
|
+
core.addEventListener(Event.COMPLETE, async.add(handler));
|
77
|
+
core.start(Suite);
|
78
|
+
}
|
79
|
+
|
80
|
+
[Test]
|
81
|
+
public function shouldAssignRunWithUsingOuterSuite():void {
|
82
|
+
// This will work b/c the RunWith is on the outer Suite:
|
83
|
+
var testCaseCount:int = 2;
|
84
|
+
var testMethodCount:int = 4;
|
85
|
+
verifyRunWithOnASuite(SuiteWithCustomRunner, testCaseCount, testMethodCount);
|
86
|
+
}
|
87
|
+
|
88
|
+
[Ignore(description="This doesn't work because we discard the hierarchy of Suites in the SuiteIterator")]
|
89
|
+
[Test]
|
90
|
+
public function shouldAssignRunWithUsingChildSuite():void {
|
91
|
+
// This will work b/c the RunWith is on the outer Suite:
|
92
|
+
var testCaseCount:int = 2;
|
93
|
+
var testMethodCount:int = 4;
|
94
|
+
verifyRunWithOnASuite(SuiteWithOneCustomChildSuite, testCaseCount, testMethodCount);
|
95
|
+
}
|
96
|
+
}
|
97
|
+
}
|