I wanted to give an update on the === issue. I made the changes so that the parameters on either side of === are named left and right, and the error message for assert(1 === 2) is "1 did not equal 2". I've used it for testing an enhancement and it seems to work fine.
However, I made one other change that I'd like to get feedback on. I changed expect to expectE, for expect exception, and made plain old expect mean expecting a regularly returned result. For example,
expect(List(1, 2)) {
List(1, 2, 3)
}
Would throw an AssertionError with the detail message: "Expected List(1, 2), but got List(1, 2, 3)". Basically, you put the value you're expecting in the parens after "expect", then put some code in the curly braces. The end result of that code is compared with the expected value.
When I tried this, I thought the code looked a bit more readable than the === approach. Here are some assertions:
assert(DiscoverySuite.nestedSuiteNames("a.b.c", Set(), false) === Nil)
assert(DiscoverySuite.nestedSuiteNames("a.b.c", Set("a.b.c.Hi"), true) === List("a.b.c.Hi"))
assert(DiscoverySuite.nestedSuiteNames("a.b.c", Set("a.b.c.d.Hi"), true) === List("a.b.c.d.Hi"))
assert(DiscoverySuite.nestedSuiteNames("a.b.c", Set("a.b.c.Hi"), false) === List("a.b.c.Hi"))
assert(DiscoverySuite.nestedSuiteNames("a.b.c", Set("a.b.c"), false) === Nil)
assert(DiscoverySuite.nestedSuiteNames("a.b.c", Set("a.b.c.d.Hi"), false) === Nil)
Here are the same assertions written with the expected value first:
assert(Nil === DiscoverySuite.nestedSuiteNames("a.b.c", Set(), false))
assert(List("a.b.c.Hi") === DiscoverySuite.nestedSuiteNames("a.b.c", Set("a.b.c.Hi"), true))
assert(List("a.b.c.d.Hi" === DiscoverySuite.nestedSuiteNames("a.b.c", Set("a.b.c.d.Hi"), true))
assert(List("a.b.c.Hi") === DiscoverySuite.nestedSuiteNames("a.b.c", Set("a.b.c.Hi"), false))
assert(Nil === DiscoverySuite.nestedSuiteNames("a.b.c", Set("a.b.c"), false))
assert(Nil === DiscoverySuite.nestedSuiteNames("a.b.c", Set("a.b.c.d.Hi"), false))
Here are the same assertions in the expect form:
expect(Nil) {
DiscoverySuite.nestedSuiteNames("a.b.c", Set(), false)
}
expect(List("a.b.c.Hi")) {
DiscoverySuite.nestedSuiteNames("a.b.c", Set("a.b.c.Hi"), true)
}
expect(List("a.b.c.d.Hi")) {
DiscoverySuite.nestedSuiteNames("a.b.c", Set("a.b.c.d.Hi"), true)
}
expect(List("a.b.c.Hi")) {
DiscoverySuite.nestedSuiteNames("a.b.c", Set("a.b.c.Hi"), false)
}
expect(Nil) {
DiscoverySuite.nestedSuiteNames("a.b.c", Set("a.b.c"), false)
}
expect(Nil) {
DiscoverySuite.nestedSuiteNames("a.b.c", Set("a.b.c.d.Hi"), false)
}
Here's an example of some expectE's:
expectE(classOf[RuntimeException]) {
buggyReporter.testStarting(report)
}
catchReporter.testStarting(report)
expect E(classOf[RuntimeException]) {
buggyReporter.runStarting(1)
}
catchReporter.runStarting(1)
expectE(classOf[Ru ntimeException]) {
buggyReporter.testStarting(report)
}
catchReporter.testStarting(report)
I am curious what your thoughts are. What do you think you'd rather write? What would you rather read?