@@ -91,21 +91,38 @@ gen2 assertGreaterEqual, `>=`
91
91
gen2 assertIsInstance, `is`
92
92
gen2 assertNotIsInstance, `is_not`
93
93
94
- template addSkip(reason) = checkpoint reason ##\
95
- ## XXX: TODO: not really python-like
94
+ func fmtSkip(name, reason: string ): string = name & ": " & reason
96
95
97
96
template skipTest*(reason: string ){.genSelf.} =
98
- bind skip
99
- addSkip reason
97
+ bind skip, fmtSkip
98
+ const msg = fmtSkip(astToStr(self), reason)
99
+ checkpoint msg
100
+ ## XXX: TODO: not really python-like
100
101
skip()
101
102
103
+ proc skipTest(reason, testStmt: NimNode): NimNode =
104
+ if testStmt.kind == nnkCommand:
105
+ result = newNimNode nnkCommand
106
+ result .add testStmt[ 0]
107
+ let name = testStmt[1 ]
108
+ result .add newCall(bindSym" fmtSkip" , name, reason)
109
+ result .add newStmtList(
110
+ newCall(bindSym" skip" )
111
+ )
112
+ else :
113
+ result = newCall(bindSym" skipTest" , reason)
114
+
102
115
template skip* (reason; body) =
103
116
# # EXT.
104
- addSkip reason
117
+ bind skipTest
118
+ skipTest(reason, body)
105
119
106
120
template skip* (reason: string ): untyped =
107
- addSkip reason
108
- proc (_: proc) = discard
121
+ bind skip, fmtSkip
122
+ template temp(p: proc ) =
123
+ test fmtSkip(astToStr(p), reason):
124
+ skip()
125
+ temp
109
126
110
127
proc asis_id[P: proc ](x: P): P = x
111
128
@@ -114,20 +131,37 @@ template skipIf*(condition: bool, reason: string): proc =
114
131
if condition: skip(reason)
115
132
else : asis_id
116
133
117
- template doIf(cond: bool ; body) =
118
- if cond: body
119
- template doIf(cond: static bool ; body) =
120
- when cond: body
134
+ macro makeSkip(cond: bool ; reason: string ; body; staticBanch: static [bool ]) =
135
+ result = newNimNode(if staticBanch: nnkWhenStmt else : nnkIfStmt)
136
+ result .add nnkElifBranch.newTree(
137
+ cond, body
138
+ )
139
+ var elseBody = newStmtList()
140
+ if body.kind == nnkStmtList:
141
+ for s in body:
142
+ elseBody.add skipTest(reason, s)
143
+ elif body.kind == nnkCommand and body[0 ].eqIdent " test" :
144
+ # test "xxx"
145
+ elseBody.add skipTest(reason, body)
146
+ result .add nnkElse.newTree elseBody
147
+
148
+ template doOrSkip(cond: bool ; reason: string ; body) =
149
+ bind makeSkip
150
+ makeSkip cond, reason, body, false
151
+ template doOrSkip(cond: static bool ; reason: string ; body) =
152
+ bind makeSkip
153
+ makeSkip cond, reason, body, true
121
154
122
155
template skipIf* (condition: bool , reason: string ; body) =
123
- bind doIf
124
- addSkip reason
125
- doIf not condition, body
156
+ # # EXT.
157
+ bind doOrSkip
158
+ doOrSkip not condition, reason , body
126
159
127
160
template skipUnless* (condition: bool , reason: string ): proc =
128
161
bind skipIf
129
162
skipIf(not condition, reason)
130
163
131
164
template skipUnless* (condition: bool , reason: string ; body) =
165
+ # # EXT.
132
166
bind skipIf
133
167
skipIf(not condition, reason, body)
0 commit comments