I kept this topic open on my phone and was reminded to reply several times over the last month, but of course, always while using my phone and not being in a position to type a proper reply.
I had only been updating the core part of Yunit (Yunit.ahk) and had not bothered with version control.
Yunit is described as "super simple", but for how I use it, it is over-engineered. I tried the GUI at first and quickly found that it wasn't useful to me; I prefer to have the tests print to the editor's output pane and immediately exit. Using the Yunit class directly was inconvenient, so I've been using shortcut functions since early on. My test scripts generally consist of:
- tests followed by a list of classes.
- Tests defined as methods of classes. The methods are generally self-contained; I generally do not use __new/__delete, Begin/End, or ExpectedException.
- A series of related assertions with assert expression, throws ()=> expression (which passes only if the expression throws an exception) and equals expression, value.
The helper functions were defined like this:
Code: Select all
tests(t*) => Yunit.Use(YunitStdOut).Test(t*)
assert(p*) => Yunit.Assert(p*)
equals(a, b) => assert(a == b, (a is Number ? a : '"' a '"') ' != ' (b is Number ? b : '"' b '"'))
throws(f, p*) {
try f()
catch
return
assert(false, p*)
}
Although I actually use a replacement for YunitStdOut which changes the format slightly.
After thinking about what Yunit actually does that I use, I worked out that the following was sufficient to replace it for my existing tests:
Code: Select all
tests(classes*) {
for testclass in classes {
env := testclass()
for name in ObjOwnProps(testclass.Prototype) {
if SubStr(name, 1, 2) != '__' {
try
env.%name%()
catch as e
print "FAIL: " type(env) "." name errline(e)
else
print "PASS: " type(env) "." name
}
}
}
errline(e) => "`n" StrReplace(e.File, A_InitialWorkingDir "\") " (" e.Line ") : " e.Message
print(s) => FileAppend(s "`n", "*")
}
assert(condition, message:="FAIL", n:=-1) {
if !condition
throw Error(message, n)
}
equals(a, b) => assert(a == b, (a is Number ? a : '"' a '"') ' != ' (b is Number ? b : '"' b '"'), -2)
throws(f, m:="FAIL (didn't throw)") {
try f()
catch
return
assert(false, m, -2)
}