D For A Web Developer

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Wed Apr 30 07:35:30 PDT 2014


On Wed, Apr 30, 2014 at 02:25:05PM +0000, Dicebot via Digitalmars-d wrote:
> On Wednesday, 30 April 2014 at 14:18:37 UTC, Ary Borenszweig wrote:
> >When I have a bug in my code I usually add a test for it so it never
> >happens again.
> >
> >Because it's a bug, I might need to debug it. So I add a couple of
> >"writefln" instead of using a debugger (it's faster and I get
> >formatted results easier).
> >
> >Now, if I run all tests I will get output from all the tests, not the
> >one I'm trying to debug. That's really annoying.
> 
> Output from the failing test will always be the last one in console. Pipe to
> tail -> profit. This sounds as pure aesthetics issue.

What I usually do is to be writefln at the start and end of the failing
test, so I know exactly which part of the output belongs to the failure:

	unittest {
		writeln("Starting failing test");

		... // stuff
			writeln("debug value = %s", ...);
		... // stuff

		writeln("End failing test");
	}

Then just pipe it to:

	sed -ne/^Starting\ failing\ test/,/^End\ failing\ test/p

and you're good to go. :-)  (The "End" message is there so that you're
sure the failure is coming from this test, not somewhere else, and also
serves as an indicator of when the problem gets fixed and it moves on to
the next test.)


T

-- 
It's amazing how careful choice of punctuation can leave you hanging:


More information about the Digitalmars-d mailing list