public
Description: The Nu programming language.
Homepage: http://programming.nu
Clone URL: git://github.com/timburks/nu.git
Search Repo:
New assert_true and assert_false macros in nu/test.nu.
timburks (author)
Fri Jun 20 22:54:19 -0700 2008
commit  b896cafecbac9f2da8d00344502dfbbd148198ed
tree    ffa447b5746a5d437d7f7c28ba7adcc100a08876
parent  a2cbb2d4293018d7fd2c5f97509dfcadb368b9d6
...
16
17
18
19
 
20
21
22
23
24
25
 
26
27
28
...
32
33
34
35
 
36
37
38
39
40
 
41
42
43
44
45
 
46
47
 
48
49
 
50
51
52
53
 
54
55
56
...
62
63
64
65
 
66
67
68
...
70
71
72
73
 
74
75
76
...
83
84
85
86
 
87
88
89
...
95
96
97
98
 
99
100
101
102
 
 
103
104
105
...
137
138
139
140
 
141
142
143
...
145
146
147
148
 
149
150
151
...
155
156
157
158
 
159
160
161
...
166
167
168
 
 
 
 
 
 
 
169
 
 
 
 
 
 
 
170
...
16
17
18
 
19
20
21
22
23
24
 
25
26
27
28
...
32
33
34
 
35
36
37
38
39
 
40
41
42
43
44
 
45
46
 
47
48
 
49
50
51
52
 
53
54
55
56
...
62
63
64
 
65
66
67
68
...
70
71
72
 
73
74
75
76
...
83
84
85
 
86
87
88
89
...
95
96
97
 
98
99
100
 
 
101
102
103
104
105
...
137
138
139
 
140
141
142
143
...
145
146
147
 
148
149
150
151
...
155
156
157
 
158
159
160
161
...
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
0
@@ -16,13 +16,13 @@
0
 ;; limitations under the License.
0
 
0
 ;; @class NuTestCase
0
-;; @abstract Base class for Nu test cases.
0
+;; @abstract Base class for Nu test cases.
0
 ;; @discussion NuTestCase is an abstract base class for Nu test cases.
0
 ;; To create new tests, create a class derived from this class
0
 ;; and give your test methods names beginning with "test".
0
 ;; As with Ruby's Test::Unit, you can also define methods
0
 ;; named "setup" and "teardown" to be run before and after
0
-;; each test method.
0
+;; each test method.
0
 ;;
0
 ;; Here's an example test:
0
 ;;
0
@@ -32,25 +32,25 @@
0
 ;;     (assert_equal 4 (+ 2 2))))
0
 ;; </code></div>
0
 ;;
0
-;; To run your tests, use the "nutest" standalone program.
0
+;; To run your tests, use the "nutest" standalone program.
0
 ;; The following invocation runs all of the Nu unit tests
0
 ;; from a console (Terminal.app):
0
 ;;
0
 ;; <code>% nutest test/test_*.nu</code>
0
-;;
0
+;;
0
 (class NuTestCase is NSObject
0
      (ivar (id) failures (id) assertions (id) errors)
0
      
0
      ;; By overriding this method, we detect each time a class is defined in Nu that inherits from this class.
0
- (cmethod (id) inheritedByClass:(id) testClass is
0
+ (cmethod (id) inheritedByClass:(id) testClass is
0
           (unless $testClasses (set $testClasses (NSMutableSet set)))
0
- ($testClasses addObject:testClass))
0
+ ($testClasses addObject:testClass))
0
      
0
- ;; The setup method is called before each test case is executed.
0
+ ;; The setup method is called before each test case is executed.
0
      ;; The default implementation does nothing.
0
      (imethod (id) setup is nil)
0
      
0
- ;; The teardown method is called after each test case is executed.
0
+ ;; The teardown method is called after each test case is executed.
0
      ;; The default implementation does nothing.
0
      (imethod (id) teardown is nil)
0
      
0
@@ -62,7 +62,7 @@
0
           (set $failures 0)
0
           (set $tests 0)
0
           (if $testClasses
0
- ((($testClasses allObjects) sort) each:
0
+ ((($testClasses allObjects) sort) each:
0
                (do (testClass)
0
                    (((testClass alloc) init) run))))
0
           
0
@@ -70,7 +70,7 @@
0
           (puts "All: completed #{$tests} tests/#{$assertions} assertions/#{$failures} failures/#{$errors} errors")
0
           (puts "")
0
           (if (or $failures $errors)
0
- (then (puts "FAILURE (#{$failures} failures, #{$errors} errors)"))
0
+ (then (puts "FAILURE (#{$failures} failures, #{$errors} errors)"))
0
               (else (puts "SUCCESS (0 failures, 0 errors)")))
0
           (+ $failures $errors))
0
      
0
@@ -83,7 +83,7 @@
0
           (set testcases (((self instanceMethods) sort) select: (do (method) ((pattern findInString:(method name))))))
0
           (puts "")
0
           (puts "#{((self class) name)}: running")
0
- (testcases each:
0
+ (testcases each:
0
                (do (test)
0
                    (set $tests (+ $tests 1))
0
                    (print "--- #{(test name)}")
0
@@ -95,11 +95,11 @@
0
                               (print " FAILED: Unhandled #{(exception name)} exception caught in #{(test name)}: #{(exception reason)}")
0
                               (set @errors (+ @errors 1))))
0
                    (self teardown)
0
- (puts "")))
0
+ (puts "")))
0
           (set $errors (+ $errors @errors))
0
           (set $failures (+ $failures @failures))
0
- (set $assertions (+ $assertions @assertions))
0
- (puts "#{((self class) name)}: completed #{(testcases count)} tests/#{@assertions} assertions/#{@failures} failures/#{@errors} errors")))
0
+ (set $assertions (+ $assertions @assertions))
0
+ (puts "#{((self class) name)}: completed #{(testcases count)} tests/#{@assertions} assertions/#{@failures} failures/#{@errors} errors")))
0
 
0
 (macro assert_equal
0
      (set @assertions (+ @assertions 1))
0
@@ -137,7 +137,7 @@
0
              (set @failures (+ @failures 1)))
0
      nil)
0
 
0
-(macro assert_throws
0
+(macro assert_throws
0
      (set @assertions (+ @assertions 1))
0
      (set __desired (eval (car margs)))
0
      (set __block (cdr margs))
0
@@ -145,7 +145,7 @@
0
      (try
0
          (eval __block)
0
          (catch (exception) (set __exception exception)))
0
- (if __exception
0
+ (if __exception
0
          (then
0
               (unless (eq (__exception name) __desired)
0
                       (puts "failure: expected exception #{__desired} to be thrown, got #{(__exception name)}")
0
@@ -155,7 +155,7 @@
0
               (set @failures (+ @failures 1))))
0
      nil)
0
 
0
-(macro assert_in_delta
0
+(macro assert_in_delta
0
      (set @assertions (+ @assertions 1))
0
      (set __reference (eval (car margs)))
0
      (set __actual (eval (car (cdr (margs)))))
0
@@ -166,5 +166,19 @@
0
          (set @failures (+ @failures 1)))
0
      nil)
0
 
0
+(macro assert_true
0
+ (set @assertions (+ @assertions 1))
0
+ (set __actual (eval (car margs)))
0
+ (unless __actual
0
+ (puts "failure: #{(car margs)} expected true value, got '#{__actual}'")
0
+ (set @failures (+ @failures 1)))
0
+ nil)
0
 
0
+(macro assert_false
0
+ (set @assertions (+ @assertions 1))
0
+ (set __actual (eval (car margs)))
0
+ (if __actual
0
+ (puts "failure: #{(car margs)} expected false value, got '#{__actual}'")
0
+ (set @failures (+ @failures 1)))
0
+ nil)
0
 

Comments

    No one has commented yet.