unittesting generic functions

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Thu Aug 14 12:08:27 PDT 2014


On Thu, Aug 14, 2014 at 06:26:05PM +0000, bearophile via Digitalmars-d wrote:
> Andrei Alexandrescu:
> >Destroy https://issues.dlang.org/show_bug.cgi?id=13291?
> 
> I'd like a way to test nested functions:
> 
> 
> void foo() {
>     int bar() { return 0; }
> 
>     unittest {
>         assert(bar() == 1);
>     }
> }
> 
> void main() {}
[...]

When should such unittests be run, and how should the following code
behave?

	void foo(int x) {
		int bar() {
			return x+1;
		}
		unittest {
			// When is this unittest run? What's the value
			// of x when the unittest runs?
			assert(bar() == 1);
		}
	}


T

-- 
"Uhh, I'm still not here." -- KD, while "away" on ICQ.


More information about the Digitalmars-d mailing list