digitalmars.D.learn - unittest can't have extern (C) or import?
- Leandro Lucarella (19/19) Jan 27 2008 Hi! I'm trying to do some unittest on a C bindings. First, I found I can...
- Jarrett Billingsley (18/30) Jan 27 2008 A unittest block is a function body. Anything that's illegal in a funct...
Hi! I'm trying to do some unittest on a C bindings. First, I found I can't use import inside a unittest block (why?). Should I polute the module with symbols I only want for the unittest? :S Second, and whorst, I can't specify extern (C) in the unittest. I need to use some functions with C linking, but I can't create them inside the unittest. Using extern (C): or extern (C) {} gives me a parse error and extern (C) void f() {} parses OK but the extern (C) is ignored and compiler complains about trying to use a pointer to a D linked function where it expects a C linked function. Is this a bug? A feature? TIA. PS: Using gdc 0.25 (GCC 4.1.3) debian package. -- Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/ ---------------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------------- "The Guinness Book of Records" holds the record for being the most stolen book in public libraries
Jan 27 2008
"Leandro Lucarella" <llucax gmail.com> wrote in message news:20080127154946.GA27400 homero.springfield.home...Hi! I'm trying to do some unittest on a C bindings. First, I found I can't use import inside a unittest block (why?). Should I polute the module with symbols I only want for the unittest? :S Second, and whorst, I can't specify extern (C) in the unittest. I need to use some functions with C linking, but I can't create them inside the unittest. Using extern (C): or extern (C) {} gives me a parse error and extern (C) void f() {} parses OK but the extern (C) is ignored and compiler complains about trying to use a pointer to a D linked function where it expects a C linked function. Is this a bug? A feature? TIA. PS: Using gdc 0.25 (GCC 4.1.3) debian package.A unittest block is a function body. Anything that's illegal in a function body is also illegal in a unittest block. I would kind of like imports to be legal in functions but that's another story. Basically there's no built-in solution to this. Tango does something like: debug(UnitTest) { import my.stuff; extern(C) void some_func(); unittest { some_func(); my.stuff.fweep(); } } And when running unittests they'll also define a UnitTest debug symbol. Not built-in but it works.
Jan 27 2008