Bug 14082 – RedBlackTree unittest fails with custom predicate less
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-01-30T13:42:00Z
Last change time
2015-02-18T03:41:42Z
Assigned to
schveiguy
Creator
drug2004
Comments
Comment #0 by drug2004 — 2015-01-30T13:42:36Z
import std.container: RedBlackTree;
class Test(T, alias less = "a<b")
{
alias Container = RedBlackTree!(T, less);
}
unittest
{
alias Foo = Test!(int);
}
void main() {}
run using rdmd -unittest filename.d
this code causes unittest failure:
std/container/rbtree.d
Lines 846-850:
static if(less == "a < b")
auto vals = [1, 2, 3, 4, 5];
else
auto vals = [5, 4, 3, 2, 1];
assert(equal(r, vals));
because less is set to "a<b" instead of "a < b" by default, i.e. spaces have meaning here. What is the best way to fix that?
Comment #1 by schveiguy — 2015-01-30T14:17:27Z
The real answer is that phobos unit tests should not run when you run your private unit tests. That is really a language change that needs to happen.
The band-aid answer is that the unit tests should ONLY run if we know exactly the instantiating parameters are. When I wrote those, I didn't consider that I should worry about the less parameter.
Comment #2 by drug2004 — 2015-01-30T14:37:17Z
I agree. Also I'm curious why RedBlackTree instance in Phobos unittest get less from my private unittest?
Comment #3 by schveiguy — 2015-01-30T14:49:49Z
(In reply to drug007 from comment #2)
> I agree. Also I'm curious why RedBlackTree instance in Phobos unittest get
> less from my private unittest?
RedBlackTree unit tests are done inside the class, so every instantiation of RBT creates its own set of unit tests. It's actually quite useful, I found about 3 compiler bugs because of it.
But the drawback is that EVERY instantiation of RBT creates its own unit tests. And it's nearly impossible to make a unit test that works for every instantation.
So I have code that limits when unit tests run, based on the *type* of the data stored. But I never thought of limiting it based on the lambda. I just have to add a few static ifs, and you will be all set.