So, I'm trying to run some tests and I had code that looks similar to this:

unittest
{
auto range = readStream(File("test_data/multiple.xml").byLine);
        int count = 0;
        while (!range.empty)
        {
                count++;
                range.popFront();
        }
        assert(count == 3);
}

However, if I have a second block above/below it doing the same thing, the last assert will fail because in the second block it appears the ranges have been joined together. E.g.:

unittest
{
auto range = readStream(File("test_data/multiple.xml").byLine);
        int count = 0;
        while (!range.empty)
        {
                count++;
                range.popFront();
        }
        assert(count == 3); // Passes
}

unittest
{
auto range = readStream(File("test_data/another.xml").byLine);
        int count = 0;
        while (!range.empty)
        {
                count++;
                range.popFront();
        }
        assert(count == 2); // Fails
}

To me, it looks like range is not being overwritten. The code for readStream looks similar to this:

auto readStream(Range)(auto ref Range r) if (isInputRange!(Unqual!Range))
{
        struct StreamRange(Range)
        {
                alias R = Unqual!Range;
                R _input;

                this(R input)
                {
                        this._input = input;
                }

                bool empty()
                {
                        return this._input.empty;
                }

                string front()
                {
                        // Do stuff...
                }

                void popFront()
                {
                }
        }

        return StreamRange!(Range)(r);
}

I feel like I'm missing something obscure and it's driving me a bit batty. Any clue as to why this is happening? I'd like to not have to worry about creating new variable names between tests. To me, it seems like each unittest block is independent of each other and I haven't come across anything that contradicts that. However, I didn't find anything that confirms it either.

Thanks.

Reply via email to