asproject 0.1.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/CHANGELOG.txt +0 -0
  2. data/History.txt +0 -0
  3. data/MIT-LICENSE.txt +20 -0
  4. data/Manifest.txt +16 -0
  5. data/README.txt +3 -0
  6. data/TODO.txt +10 -0
  7. data/bin/asclass +16 -0
  8. data/bin/asproject +16 -0
  9. data/lib/asclass.rb +254 -0
  10. data/lib/asclass_arguments.rb +147 -0
  11. data/lib/asproject.rb +248 -0
  12. data/lib/asproject/version.rb +9 -0
  13. data/lib/asproject_arguments.rb +175 -0
  14. data/lib/asproject_base.rb +43 -0
  15. data/lib/asproject_utils.rb +57 -0
  16. data/lib/eclipse_project.rb +32 -0
  17. data/lib/path_finder.rb +286 -0
  18. data/lib/platform.rb +107 -0
  19. data/lib/project.rb +82 -0
  20. data/lib/template_resolver.rb +144 -0
  21. data/lib/test_suite_generator.rb +128 -0
  22. data/rakefile.rb +85 -0
  23. data/setup.rb +1585 -0
  24. data/templates/asclass/as2/Class.as +11 -0
  25. data/templates/asclass/as2/Component.as +8 -0
  26. data/templates/asclass/as2/Interface.as +3 -0
  27. data/templates/asclass/as2/TestCase.as +30 -0
  28. data/templates/asclass/as2/TestSuite.as +15 -0
  29. data/templates/asclass/as3/Class.as +9 -0
  30. data/templates/asclass/as3/Component.as +9 -0
  31. data/templates/asclass/as3/Component.mxml +1 -0
  32. data/templates/asclass/as3/Interface.as +6 -0
  33. data/templates/asclass/as3/TestCase.as +30 -0
  34. data/templates/asclass/as3/TestSuite.as +18 -0
  35. data/templates/asproject/as2/project/rakefile.rb +18 -0
  36. data/templates/asproject/as2/project/src/AsProject.as +13 -0
  37. data/templates/asproject/as2/project/test/AsProjectRunner.as +12 -0
  38. data/templates/asproject/as3/project/rakefile.rb +18 -0
  39. data/templates/asproject/as3/project/src/AsProject.as +9 -0
  40. data/templates/asproject/as3/project/src/AsProjectRunner.as +11 -0
  41. data/templates/asproject/asunit2/project/lib/asunit/AsUnitUi.swf +0 -0
  42. data/templates/asproject/asunit2/project/lib/asunit/Sys.as +70 -0
  43. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanel.as +182 -0
  44. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanelTest.as +84 -0
  45. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanelTextArea.as +111 -0
  46. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanelTextAreaTest.as +26 -0
  47. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanelTitleBar.as +81 -0
  48. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/ResizeHandle.as +35 -0
  49. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/ScrollArrow.as +34 -0
  50. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/ScrollHandle.as +43 -0
  51. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/ScrollListener.as +10 -0
  52. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/TextScroller.as +169 -0
  53. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/shapes/Rectangle.as +29 -0
  54. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/shapes/Triangle.as +27 -0
  55. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/AsUnit.as +19 -0
  56. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/Assert.as +408 -0
  57. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/Assertion.as +27 -0
  58. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/Reflection.as +68 -0
  59. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/Test.as +3 -0
  60. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestCase.as +191 -0
  61. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestCaseXml.as +31 -0
  62. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestFailure.as +15 -0
  63. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestResult.as +15 -0
  64. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestRunner.as +41 -0
  65. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestSetup.as +19 -0
  66. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestSuite.as +22 -0
  67. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/ui/Main.as +325 -0
  68. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/ui/RemoteVersion.as +24 -0
  69. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/ui/SuccessMeter.as +32 -0
  70. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/Comparable.as +7 -0
  71. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/EventListener.as +29 -0
  72. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/EventSource.as +89 -0
  73. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalConnClient.as +42 -0
  74. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalConnGateway.as +47 -0
  75. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalConnServer.as +61 -0
  76. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as +58 -0
  77. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/Observable.as +11 -0
  78. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/TextFile.as +30 -0
  79. data/templates/asproject/asunit25/project/lib/asunit/AsUnitTestRunner.as +13 -0
  80. data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/AssertionFailedError.as +7 -0
  81. data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/AssertionPassedError.as +7 -0
  82. data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/ClassNotFoundError.as +7 -0
  83. data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/IllegalOperationError.as +7 -0
  84. data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/InstanceNotFoundError.as +7 -0
  85. data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/InvocationTargetError.as +7 -0
  86. data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/UnimplementedFeatureError.as +7 -0
  87. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/Assert.as +376 -0
  88. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/AssertMock.as +15 -0
  89. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/AssertTest.as +59 -0
  90. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/ITestListener.as +13 -0
  91. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/Test.as +11 -0
  92. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestCase.as +277 -0
  93. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestCaseMock.as +23 -0
  94. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestCaseTest.as +29 -0
  95. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestCaseXml.as +38 -0
  96. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestFailure.as +47 -0
  97. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestResult.as +168 -0
  98. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestSuite.as +102 -0
  99. data/templates/asproject/asunit25/project/lib/asunit/asunit/runner/BaseTestRunner.as +101 -0
  100. data/templates/asproject/asunit25/project/lib/asunit/asunit/runner/IResultPrinter.as +8 -0
  101. data/templates/asproject/asunit25/project/lib/asunit/asunit/textui/ResultPrinter.as +254 -0
  102. data/templates/asproject/asunit25/project/lib/asunit/asunit/textui/SuccessBar.as +41 -0
  103. data/templates/asproject/asunit25/project/lib/asunit/asunit/textui/TestRunner.as +17 -0
  104. data/templates/asproject/asunit25/project/lib/asunit/asunit/util/ArrayIterator.as +24 -0
  105. data/templates/asproject/asunit25/project/lib/asunit/asunit/util/ArrayIteratorTest.as +52 -0
  106. data/templates/asproject/asunit25/project/lib/asunit/asunit/util/Iterator.as +5 -0
  107. data/templates/asproject/asunit3/project/lib/asunit/AsUnitTestRunner.as +10 -0
  108. data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/AbstractMemberCalledError.as +10 -0
  109. data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/AssertionFailedError.as +10 -0
  110. data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/ClassNotFoundError.as +10 -0
  111. data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/InstanceNotFoundError.as +10 -0
  112. data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/UnimplementedFeatureError.as +10 -0
  113. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/Assert.as +271 -0
  114. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/AsynchronousTestCase.as +52 -0
  115. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/AsynchronousTestCaseExample.as +71 -0
  116. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/Test.as +15 -0
  117. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestCase.as +351 -0
  118. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestCaseExample.as +73 -0
  119. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestFailure.as +47 -0
  120. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestListener.as +22 -0
  121. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestResult.as +158 -0
  122. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestSuite.as +115 -0
  123. data/templates/asproject/asunit3/project/lib/asunit/asunit/runner/BaseTestRunner.as +15 -0
  124. data/templates/asproject/asunit3/project/lib/asunit/asunit/runner/TestSuiteLoader.as +9 -0
  125. data/templates/asproject/asunit3/project/lib/asunit/asunit/runner/Version.as +11 -0
  126. data/templates/asproject/asunit3/project/lib/asunit/asunit/textui/FlexRunner.as +19 -0
  127. data/templates/asproject/asunit3/project/lib/asunit/asunit/textui/FlexTestRunner.as +55 -0
  128. data/templates/asproject/asunit3/project/lib/asunit/asunit/textui/ResultPrinter.as +245 -0
  129. data/templates/asproject/asunit3/project/lib/asunit/asunit/textui/TestRunner.as +121 -0
  130. data/templates/asproject/asunit3/project/lib/asunit/asunit/util/ArrayIterator.as +26 -0
  131. data/templates/asproject/asunit3/project/lib/asunit/asunit/util/Iterator.as +9 -0
  132. data/templates/asproject/asunit3/project/lib/asunit/asunit/util/Properties.as +30 -0
  133. data/templates/asproject/asunit3/project/lib/asunit/mx/managers/LayoutManager.as +945 -0
  134. data/templates/asproject/config/project/config/asclass_config.rb +58 -0
  135. data/templates/asproject/fb2as/project/.actionScriptProperties +21 -0
  136. data/templates/asproject/fb2as/project/.project +29 -0
  137. data/templates/asproject/fdt/project/.as2_classpath +6 -0
  138. data/templates/asproject/fdt/project/.project +19 -0
  139. data/templates/ide/mate/Create Class.tmCommand +37 -0
  140. data/templates/ide/mate/Rebuild Test Suites.tmCommand +33 -0
  141. data/templates/ide/mate/Run Rake Task.tmCommand +127 -0
  142. metadata +266 -0
@@ -0,0 +1,47 @@
1
+ //import flash.util.StringBuilder;
2
+ import asunit.errors.AssertionFailedError;
3
+ import asunit.framework.Test;
4
+
5
+ /**
6
+ * A <code>TestFailure</code> collects a failed test together with
7
+ * the caught exception.
8
+ * @see TestResult
9
+ */
10
+ class asunit.framework.TestFailure {
11
+ private var fFailedTest:String;
12
+ private var fThrownException:Error;
13
+
14
+ /**
15
+ * Constructs a TestFailure with the given test and exception.
16
+ */
17
+ public function TestFailure(failedTest:Test, thrownException:Error) {
18
+ fFailedTest = failedTest.toString();
19
+ fThrownException = thrownException;
20
+ }
21
+ /**
22
+ * Gets the failed test.
23
+ */
24
+ public function failedTest():String {
25
+ return fFailedTest;
26
+ }
27
+ /**
28
+ * Gets the thrown exception.
29
+ */
30
+ public function thrownException():Error {
31
+ return fThrownException;
32
+ }
33
+ /**
34
+ * Returns a short description of the failure.
35
+ */
36
+ public function toString():String {
37
+ return "";
38
+ }
39
+
40
+ public function exceptionMessage():String {
41
+ return thrownException().message;
42
+ }
43
+
44
+ public function isFailure():Boolean {
45
+ return thrownException() instanceof AssertionFailedError;
46
+ }
47
+ }
@@ -0,0 +1,168 @@
1
+ import asunit.errors.AssertionFailedError;
2
+ import asunit.errors.InstanceNotFoundError;
3
+ import asunit.framework.Test;
4
+ import asunit.framework.TestCase;
5
+ import asunit.framework.TestFailure;
6
+ import asunit.framework.ITestListener;
7
+
8
+ /**
9
+ * A <code>TestResult</code> collects the results of executing
10
+ * a test case. It is an instance of the Collecting Parameter pattern.
11
+ * The test framework distinguishes between <i>failures</i> and <i>errors</i>.
12
+ * A failure is anticipated and checked for with assertions. Errors are
13
+ * unanticipated problems like an <code>ArrayIndexOutOfBoundsException</code>.
14
+ *
15
+ * @see Test
16
+ */
17
+ class asunit.framework.TestResult {
18
+ private var fFailures:Array;
19
+ private var fErrors:Array;
20
+ private var fListeners:Array;
21
+ private var fRunTests:Number;
22
+ private var fStop:Boolean;
23
+
24
+ public function TestResult() {
25
+ fFailures = new Array();
26
+ fErrors = new Array();
27
+ fListeners = new Array();
28
+ fRunTests = 0;
29
+ fStop = false;
30
+ }
31
+ /**
32
+ * Adds an error to the list of errors. The passed in exception
33
+ * caused the error.
34
+ */
35
+ public function addError(test:Test, t:Error):Void {
36
+ fErrors.push(new TestFailure(test, t));
37
+ var len:Number = fListeners.length;
38
+ var item:ITestListener;
39
+ for(var i:Number = 0; i < len; i++) {
40
+ item = ITestListener(fListeners[i]);
41
+ item.addError(test, t);
42
+ }
43
+ }
44
+ /**
45
+ * Adds a failure to the list of failures. The passed in exception
46
+ * caused the failure.
47
+ */
48
+ public function addFailure(test:Test, t:AssertionFailedError):Void {
49
+ fFailures.push(new TestFailure(test, t));
50
+ var len:Number = fListeners.length;
51
+ var item:ITestListener;
52
+ for(var i:Number = 0; i < len; i++) {
53
+ item = ITestListener(fListeners[i]);
54
+ item.addFailure(test, t);
55
+ }
56
+ }
57
+ /**
58
+ * Registers a ITestListener
59
+ */
60
+ public function addListener(listener:ITestListener):Void {
61
+ fListeners.push(listener);
62
+ }
63
+ /**
64
+ * Unregisters a ITestListener
65
+ */
66
+ public function removeListener(listener:ITestListener):Void {
67
+ var len:Number = fListeners.length;
68
+ for(var i:Number = 0; i < len; i++) {
69
+ if(fListeners[i] == listener) {
70
+ fListeners.splice(i, 1);
71
+ return;
72
+ }
73
+ }
74
+ throw new InstanceNotFoundError("removeListener called without listener in list");
75
+ }
76
+ /**
77
+ * Gets the number of detected errors.
78
+ */
79
+ public function errorCount():Number {
80
+ return fErrors.length;
81
+ }
82
+ /**
83
+ * Returns an Enumeration for the errors
84
+ */
85
+ public function errors():Array {
86
+ return fErrors;
87
+ }
88
+ /**
89
+ * Gets the number of detected failures.
90
+ */
91
+ public function failureCount():Number {
92
+ return fFailures.length;
93
+ }
94
+ /**
95
+ * Returns an Enumeration for the failures
96
+ */
97
+ public function failures():Array {
98
+ return fFailures;
99
+ }
100
+
101
+ /**
102
+ * Runs a TestCase.
103
+ */
104
+ public function run(test:TestCase):Void {
105
+ startTest(test);
106
+ try {
107
+ test.runBare();
108
+ }
109
+ catch(afe:AssertionFailedError) {
110
+ addFailure(test, afe);
111
+ }
112
+ catch(e:Error) {
113
+ addError(test, e);
114
+ }
115
+ finally {
116
+ endTest(test);
117
+ }
118
+ }
119
+ /**
120
+ * Gets the number of run tests.
121
+ */
122
+ public function runCount():Number {
123
+ return fRunTests;
124
+ }
125
+ /**
126
+ * Checks whether the test run should stop
127
+ */
128
+ public function shouldStop():Boolean {
129
+ return fStop;
130
+ }
131
+ /**
132
+ * Informs the result that a test will be started.
133
+ */
134
+ public function startTest(test:Test):Void {
135
+ var count:Number = test.countTestCases();
136
+ fRunTests += count;
137
+
138
+ var len:Number = fListeners.length;
139
+ var item:ITestListener;
140
+ for(var i:Number = 0; i < len; i++) {
141
+ item = ITestListener(fListeners[i]);
142
+ item.startTest(test);
143
+ }
144
+ }
145
+ /**
146
+ * Informs the result that a test was completed.
147
+ */
148
+ public function endTest(test:Test):Void {
149
+ var len:Number = fListeners.length;
150
+ var item:ITestListener;
151
+ for(var i:Number = 0; i < len; i++) {
152
+ item = ITestListener(fListeners[i]);
153
+ item.endTest(test);
154
+ }
155
+ }
156
+ /**
157
+ * Marks that the test run should stop.
158
+ */
159
+ public function stop():Void {
160
+ fStop = true;
161
+ }
162
+ /**
163
+ * Returns whether the entire test was successful or not.
164
+ */
165
+ public function wasSuccessful():Boolean {
166
+ return (failureCount() == 0 && errorCount() == 0);
167
+ }
168
+ }
@@ -0,0 +1,102 @@
1
+ import asunit.framework.TestCase;
2
+ import asunit.framework.Test;
3
+ import asunit.framework.TestResult;
4
+ import asunit.util.Iterator;
5
+ import asunit.util.ArrayIterator;
6
+
7
+ class asunit.framework.TestSuite extends TestCase {
8
+ private var fTests:Array = new Array();
9
+
10
+ public function TestSuite() {
11
+ super();
12
+ fTests = new Array();
13
+ }
14
+
15
+ private function getTestMethods():Array {
16
+ return new Array();
17
+ }
18
+
19
+ public function testsComplete():Boolean {
20
+ var completed:Boolean;
21
+ var len:Number = fTests.length;
22
+ for(var i:Number = 0; i < len; i++) {
23
+ if(!fTests[i].testsComplete()) {
24
+ return false;
25
+ }
26
+ }
27
+ return true;
28
+ }
29
+
30
+ /**
31
+ * Adds a test to the suite.
32
+ */
33
+ public function addTest(test:Test):Void {
34
+ fTests.push(test);
35
+ }
36
+
37
+ /**
38
+ * Counts the number of tests that will be run by this Suite.
39
+ */
40
+ public function countTestCases():Number {
41
+ var count:Number;
42
+ var len:Number = fTests.length;
43
+ for(var i:Number = 0; i < len; i++) {
44
+ count = count + fTests[i].countTestCases();
45
+ }
46
+ return count;
47
+ }
48
+
49
+ /**
50
+ * Runs the tests and collects their result in a TestResult.
51
+ */
52
+ public function run():Void {
53
+ var result:TestResult = getResult();
54
+ runTests(fTests, result);
55
+ }
56
+
57
+ public function runTests(tests:Array, result:TestResult):Void {
58
+ var itr:Iterator = new ArrayIterator(tests);
59
+ var test:TestCase;
60
+ if(itr.hasNext()) {
61
+ test = TestCase(itr.next());
62
+ runTest(itr, test, result);
63
+ }
64
+ }
65
+
66
+ public function runTest(itr:Iterator, test:TestCase, result:TestResult):Void {
67
+ test.setResult(result);
68
+ test.run();
69
+ if(itr.hasNext()) {
70
+ _global.setTimeout(this, "runTest", 10, itr, itr.next(), result);
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Returns the number of tests in this suite
76
+ */
77
+ public function testCount():Number {
78
+ return fTests.length;
79
+ }
80
+
81
+ public function toString():String {
82
+ return getName();
83
+ }
84
+
85
+ public function getIsComplete():Boolean {
86
+ var len:Number = fTests.length;
87
+ for(var i:Number = 0; i < len; i++) {
88
+ if(!fTests[i].getIsComplete()) {
89
+ return false;
90
+ }
91
+ }
92
+ return true;
93
+ }
94
+
95
+ public function setContext(context:MovieClip):Void {
96
+ super.setContext(context);
97
+ var len:Number = fTests.length;
98
+ for(var i:Number = 0; i < len; i++) {
99
+ fTests[i].setContext(context);
100
+ }
101
+ }
102
+ }
@@ -0,0 +1,101 @@
1
+ import asunit.runner.IResultPrinter;
2
+ import asunit.framework.Test;
3
+ import asunit.framework.TestResult;
4
+ import asunit.framework.Assert;
5
+ import asunit.textui.ResultPrinter;
6
+
7
+ class asunit.runner.BaseTestRunner {
8
+ private static var instance:BaseTestRunner;
9
+ private static var clipContext:MovieClip;
10
+ private var printer:IResultPrinter;
11
+ private var intervalId:Number;
12
+
13
+ public function BaseTestRunner(printerReference:Function) {
14
+ if(printerReference == undefined) {
15
+ throw new Error("BaseTestRunner instantiated without a ResultPrinter");
16
+ }
17
+ Stage.scaleMode = "noscale";
18
+ Stage.align = "TL";
19
+ instance = this;
20
+ setClipContext(_root);
21
+ setPrinter(createResultPrinter(printerReference));
22
+ }
23
+
24
+ public static function getFilteredTrace(stack:String):String {
25
+ return stack;
26
+ }
27
+
28
+ public function start(testCase:Function, testMethod:String, showTrace:Boolean):TestResult {
29
+ try {
30
+ var suite:Test = Test(new testCase(testMethod));
31
+ return doRun(suite, showTrace);
32
+ }
33
+ catch(e:Error) {
34
+ trace("ERROR: Failed to create and run test suite with: \n" + e.toString());
35
+ }
36
+ }
37
+
38
+ public function doRun(suite:Test, showTrace:Boolean):TestResult {
39
+ try {
40
+ var result:TestResult = new TestResult();
41
+ result.addListener(getPrinter());
42
+ var startTime:Number = getTimer();
43
+ suite.setResult(result);
44
+ suite.setContext(getClipContext());
45
+ suite.run();
46
+ clearInterval(intervalId);
47
+ intervalId = setInterval(this, "completionHandler", 1, suite, result, startTime);
48
+ return result;
49
+ }
50
+ catch(e:Error) {
51
+ trace(e.toString());
52
+ }
53
+ }
54
+
55
+ private function completionHandler(suite:Test, result:TestResult, startTime:Number):Void {
56
+ if(suite.testsComplete()) {
57
+ clearInterval(intervalId);
58
+ getPrinter().printResult(result, (getTimer() - startTime));
59
+ }
60
+ }
61
+
62
+ public static function trace(msg:String):Void {
63
+ getInstance().getPrinter().trace(msg);
64
+ }
65
+
66
+ public static function getInstance():BaseTestRunner {
67
+ if(instance == undefined) {
68
+ return instance = new BaseTestRunner(ResultPrinter);
69
+ }
70
+ return instance;
71
+ }
72
+
73
+ public function setPrinter(printer:IResultPrinter):Void {
74
+ this.printer = printer;
75
+ }
76
+
77
+ public function getPrinter():IResultPrinter {
78
+ return IResultPrinter(printer);
79
+ }
80
+
81
+ public function setClipContext(context:MovieClip):Void {
82
+ BaseTestRunner.clipContext = context;
83
+ }
84
+ /*
85
+ * This function should return a reference to the
86
+ * MovieClip that all test cases will attach items
87
+ * to. This MovieClip should probably *not* be _root.
88
+ */
89
+ public function getClipContext():MovieClip {
90
+ return BaseTestRunner.clipContext;
91
+ }
92
+
93
+ private static function createResultPrinter(reference:Function):IResultPrinter {
94
+ var printer:IResultPrinter;
95
+ if(printer == undefined) {
96
+ var context:MovieClip = BaseTestRunner.clipContext;
97
+ printer = IResultPrinter(context.attachMovie(reference.linkageId, "asUnitResultPrinter_" + 9000, Assert.nextDepth()));
98
+ }
99
+ return printer;
100
+ }
101
+ }
@@ -0,0 +1,8 @@
1
+ import asunit.framework.ITestListener;
2
+ import asunit.framework.TestResult;
3
+
4
+ interface asunit.runner.IResultPrinter extends ITestListener {
5
+
6
+ public function printResult(result:TestResult, runTime:Number):Void;
7
+ public function trace():Void;
8
+ }
@@ -0,0 +1,254 @@
1
+ import asunit.runner.IResultPrinter;
2
+ import asunit.errors.AssertionFailedError;
3
+ import asunit.framework.Test;
4
+ import asunit.framework.TestResult;
5
+ import asunit.framework.TestFailure;
6
+ import asunit.runner.BaseTestRunner;
7
+ import asunit.textui.SuccessBar;
8
+ import asunit.framework.ITestListener;
9
+
10
+ class asunit.textui.ResultPrinter extends MovieClip implements IResultPrinter, ITestListener {
11
+ public static var linkageId:String = "__Packages.asunit.textui.ResultPrinter";
12
+ public static var classRef:Function = ResultPrinter;
13
+ private static var instance:ResultPrinter;
14
+
15
+ private var fColumn:Number = 0;
16
+ private var showTrace:Boolean;
17
+ private var barHeight:Number = 3;
18
+ private var bgColor:Number = 0x333333;
19
+ private var fontColor:Number = 0xFFFFFF;
20
+ private var spacing:Number = 5;
21
+ private var textArea:TextField;
22
+ private var traceOutput:TextField;
23
+ private var successMeter:MovieClip;
24
+ private var bar:SuccessBar;
25
+
26
+ public function ResultPrinter() {
27
+ init();
28
+ configureAssets();
29
+ println("AsUnit 2.5 by Luke Bayes and Ali Mills");
30
+ // If you can't see clips that you think should be
31
+ // attached... Perhaps it's behind this runner?
32
+ //_alpha = 50;
33
+ }
34
+
35
+ private function init():Void {
36
+ if(instance != undefined) {
37
+ throw new Error("Resultprinter instantiated twice in one session, this will likely cause problems");
38
+ }
39
+ instance = this;
40
+ Stage.addListener(this);
41
+ }
42
+
43
+ private function onLoad():Void {
44
+ onResize();
45
+ }
46
+
47
+ private function configureAssets():Void {
48
+ createTextArea();
49
+ createOutput();
50
+ createSuccessBar();
51
+ }
52
+
53
+ public function trace():Void {
54
+ traceOutput._visible = true;
55
+ traceOutput.text += arguments.toString() + "\n";
56
+ traceOutput.scroll = traceOutput.maxscroll;
57
+ }
58
+
59
+ public function println():Void {
60
+ textArea.text += arguments.toString() + "\n";
61
+ }
62
+
63
+ public function printf():Void {
64
+ textArea.text += arguments.toString();
65
+ }
66
+
67
+ public function startTest(test:Test):Void {
68
+ var count:Number = test.countTestCases();
69
+ for(var i:Number = 0; i < count; i++) {
70
+ printf(".");
71
+ if (fColumn++ >= 80) {
72
+ println();
73
+ fColumn = 0;
74
+ }
75
+ }
76
+ }
77
+
78
+ public function addError(test:Test, e:Error):Void {
79
+ printf("E");
80
+ }
81
+
82
+ public function addFailure(test:Test, e:AssertionFailedError):Void {
83
+ printf("F");
84
+ }
85
+
86
+ public function endTest(test:Test):Void {
87
+ }
88
+
89
+ private function createTextArea():Void {
90
+ textArea = getTextField("textArea", 2);
91
+ }
92
+
93
+ private function createOutput():Void {
94
+ traceOutput = getTextField("output", 4);
95
+ traceOutput._visible = false;
96
+ var format:TextFormat = traceOutput.getTextFormat();
97
+ format.align = "right";
98
+ traceOutput.setNewTextFormat(format);
99
+ }
100
+
101
+ private function getTextField(name:String, depth:Number):TextField {
102
+ this.createTextField(name, depth, 0, 0, 100, 100);
103
+ var textField:TextField = this[name];
104
+ textField.wordWrap = true;
105
+ textField.multiline = true;
106
+ var format:TextFormat = new TextFormat();
107
+ format.font = "Verdana";
108
+ format.color = fontColor;
109
+ format.size = 11;
110
+ format.leftMargin = spacing/2;
111
+ format.rightMargin = spacing/2;
112
+ textField.setNewTextFormat(format);
113
+ return textField;
114
+ }
115
+
116
+ private function createSuccessBar():Void {
117
+ bar = SuccessBar(attachMovie(SuccessBar.linkageId, "bar", 3));
118
+ }
119
+
120
+ private function onResize():Void {
121
+ draw();
122
+ }
123
+
124
+ public function draw():Void {
125
+ var w:Number = Stage.width;
126
+ var h:Number = Stage.height;
127
+ drawBackground(w, h);
128
+ drawTextArea(w, h);
129
+ drawOutput(w, h);
130
+ drawBar(w, h);
131
+ }
132
+
133
+ private function drawBackground(w:Number, h:Number):Void {
134
+ clear();
135
+ beginFill(bgColor);
136
+ lineTo(w, 0);
137
+ lineTo(w, h);
138
+ lineTo(0, h);
139
+ lineTo(0, 0);
140
+ endFill();
141
+ }
142
+
143
+ private function drawTextArea(w:Number, h:Number):Void {
144
+ drawTextField(textArea, w, h);
145
+ }
146
+
147
+ private function drawOutput(w:Number, h:Number):Void {
148
+ drawTextField(traceOutput, w, h);
149
+ }
150
+
151
+ private function drawTextField(ref:TextField, w:Number, h:Number):Void {
152
+ ref._width = w - (spacing*2);
153
+ ref._height = h - (barHeight + (spacing*2));
154
+ ref._x = spacing;
155
+ ref._y = spacing;
156
+ }
157
+
158
+ private function drawBar(w:Number, h:Number):Void {
159
+ bar._x = 0;
160
+ bar._y = h - (barHeight);
161
+ bar.width = w;
162
+ bar.height = barHeight;
163
+ }
164
+
165
+ public function printResult(result:TestResult, runTime:Number):Void {
166
+ printHeader(runTime);
167
+ printErrors(result);
168
+ printFailures(result);
169
+ printFooter(result);
170
+
171
+ bar.setSuccess(result.wasSuccessful());
172
+ if(showTrace) {
173
+ trace(textArea.text);
174
+ }
175
+ }
176
+
177
+ private function printHeader(runTime:Number):Void {
178
+ println();
179
+ println();
180
+ println("Time: " + elapsedTimeAsString(runTime));
181
+ }
182
+
183
+ /**
184
+ * Returns the formatted string of the elapsed time.
185
+ * Duplicated from BaseTestRunner. Fix it.
186
+ */
187
+ private function elapsedTimeAsString(runTime:Number):String {
188
+ return Number(runTime/1000).toString();
189
+ }
190
+
191
+ private function printErrors(result:TestResult):Void {
192
+ printDefects(result.errors(), result.errorCount(), "error");
193
+ }
194
+
195
+ private function printFailures(result:TestResult):Void {
196
+ printDefects(result.failures(), result.failureCount(), "failure");
197
+ }
198
+
199
+ private function printDefects(booBoos:Array, count:Number, type:String):Void {
200
+ if (count == 0) {
201
+ return;
202
+ }
203
+ if (count == 1) {
204
+ println("There was " + count + " " + type + ":");
205
+ }
206
+ else {
207
+ println("There were " + count + " " + type + "s:");
208
+ }
209
+ var item:TestFailure;
210
+ var len:Number = booBoos.length;
211
+ for(var i:Number = 0; i < len; i++) {
212
+ printDefect(TestFailure(booBoos[i]), i);
213
+ }
214
+ }
215
+
216
+ public function printDefect(booBoo:TestFailure, count:Number ):Void { // only public for testing purposes
217
+ printDefectHeader(booBoo, count);
218
+ printDefectTrace(booBoo);
219
+ }
220
+
221
+ private function printDefectTrace(booBoo:TestFailure):Void {
222
+ println(BaseTestRunner.getFilteredTrace(booBoo.thrownException().toString()));
223
+ }
224
+
225
+ private function printDefectHeader(booBoo:TestFailure, count:Number):Void {
226
+ // I feel like making this a println, then adding a line giving the throwable a chance to print something
227
+ // before we get to the stack trace.
228
+ var startIndex:Number = textArea.text.length;
229
+ println(count + ") " + booBoo.failedTest());
230
+ var endIndex:Number = textArea.text.length;
231
+
232
+ var format:TextFormat = textArea.getTextFormat();
233
+ format.bold = true;
234
+
235
+ // GROSS HACK because of bug in flash player - TextField isn't accepting formats...
236
+ // setTimeout(onFormatTimeout, 1, format, startIndex, endIndex);
237
+ }
238
+
239
+ private function printFooter(result:TestResult):Void {
240
+ println();
241
+ if (result.wasSuccessful()) {
242
+ printf("OK");
243
+ println (" (" + result.runCount() + " test" + (result.runCount() == 1 ? "": "s") + ")");
244
+ } else {
245
+ println("FAILURES!!!");
246
+ println("Tests run: " + result.runCount()+
247
+ ", Failures: "+result.failureCount()+
248
+ ", Errors: "+result.errorCount());
249
+ }
250
+ println();
251
+ }
252
+
253
+ public static var serializable:Boolean = Object.registerClass(linkageId, classRef);
254
+ }